00001 #ifndef _qpid_agent_ManagementAgent_ 00002 #define _qpid_agent_ManagementAgent_ 00003 00004 // 00005 // Licensed to the Apache Software Foundation (ASF) under one 00006 // or more contributor license agreements. See the NOTICE file 00007 // distributed with this work for additional information 00008 // regarding copyright ownership. The ASF licenses this file 00009 // to you under the Apache License, Version 2.0 (the 00010 // "License"); you may not use this file except in compliance 00011 // with the License. You may obtain a copy of the License at 00012 // 00013 // http://www.apache.org/licenses/LICENSE-2.0 00014 // 00015 // Unless required by applicable law or agreed to in writing, 00016 // software distributed under the License is distributed on an 00017 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 00018 // KIND, either express or implied. See the License for the 00019 // specific language governing permissions and limitations 00020 // under the License. 00021 // 00022 00023 #include "qpid/management/ManagementObject.h" 00024 #include "qpid/management/ManagementEvent.h" 00025 #include "qpid/management/Manageable.h" 00026 #include "qpid/sys/Mutex.h" 00027 00028 namespace qpid { 00029 namespace management { 00030 00031 class ManagementAgent 00032 { 00033 public: 00034 00035 class Singleton { 00036 public: 00037 Singleton(bool disableManagement = false); 00038 ~Singleton(); 00039 static ManagementAgent* getInstance(); 00040 private: 00041 static sys::Mutex lock; 00042 static bool disabled; 00043 static int refCount; 00044 static ManagementAgent* agent; 00045 }; 00046 00047 typedef enum { 00048 SEV_EMERG = 0, 00049 SEV_ALERT = 1, 00050 SEV_CRIT = 2, 00051 SEV_ERROR = 3, 00052 SEV_WARN = 4, 00053 SEV_NOTE = 5, 00054 SEV_INFO = 6, 00055 SEV_DEBUG = 7, 00056 SEV_DEFAULT = 8 00057 } severity_t; 00058 00059 ManagementAgent() {} 00060 virtual ~ManagementAgent() {} 00061 00062 virtual int getMaxThreads() = 0; 00063 00064 // Connect to a management broker 00065 // 00066 // brokerHost - Hostname or IP address (dotted-quad) of broker. 00067 // 00068 // brokerPort - TCP port of broker. 00069 // 00070 // intervalSeconds - The interval (in seconds) that this agent shall use 00071 // between broadcast updates to the broker. 00072 // 00073 // useExternalThread - If true, the thread of control used for callbacks 00074 // must be supplied by the user of the object (via the 00075 // pollCallbacks method). 00076 // 00077 // If false, callbacks shall be invoked on the management 00078 // agent's thread. In this case, the callback implementations 00079 // MUST be thread safe. 00080 // 00081 // storeFile - File where this process has read and write access. This 00082 // file shall be used to store persistent state. 00083 // 00084 virtual void init (std::string brokerHost = "localhost", 00085 uint16_t brokerPort = 5672, 00086 uint16_t intervalSeconds = 10, 00087 bool useExternalThread = false, 00088 std::string storeFile = "") = 0; 00089 00090 // Register a schema with the management agent. This is normally called by the 00091 // package initializer generated by the management code generator. 00092 // 00093 virtual void 00094 registerClass(std::string& packageName, 00095 std::string& className, 00096 uint8_t* md5Sum, 00097 management::ManagementObject::writeSchemaCall_t schemaCall) = 0; 00098 00099 virtual void 00100 registerEvent(std::string& packageName, 00101 std::string& eventName, 00102 uint8_t* md5Sum, 00103 management::ManagementEvent::writeSchemaCall_t schemaCall) = 0; 00104 00105 // Add a management object to the agent. Once added, this object shall be visible 00106 // in the greater management context. 00107 // 00108 // Please note that ManagementObject instances are not explicitly deleted from 00109 // the management agent. When the core object represented by a management object 00110 // is deleted, the "resourceDestroy" method on the management object must be called. 00111 // It will then be reclaimed in due course by the management agent. 00112 // 00113 // Once a ManagementObject instance is added to the agent, the agent then owns the 00114 // instance. The caller MUST NOT free the resources of the instance at any time. 00115 // When it is no longer needed, invoke its "resourceDestroy" method and discard the 00116 // pointer. This allows the management agent to report the deletion of the object 00117 // in an orderly way. 00118 // 00119 virtual ObjectId addObject(ManagementObject* objectPtr, uint64_t persistId = 0) = 0; 00120 00121 // 00122 // 00123 virtual void raiseEvent(const ManagementEvent& event, 00124 severity_t severity = SEV_DEFAULT) = 0; 00125 00126 // If "useExternalThread" was set to true in init, this method must 00127 // be called to provide a thread for any pending method calls that have arrived. 00128 // The method calls for ManagementObject instances shall be invoked synchronously 00129 // during the execution of this method. 00130 // 00131 // callLimit may optionally be used to limit the number of callbacks invoked. 00132 // if 0, no limit is imposed. 00133 // 00134 // The return value is the number of callbacks that remain queued after this 00135 // call is complete. It can be used to determine whether or not further calls 00136 // to pollCallbacks are necessary to clear the backlog. If callLimit is zero, 00137 // the return value will also be zero. 00138 // 00139 virtual uint32_t pollCallbacks(uint32_t callLimit = 0) = 0; 00140 00141 // If "useExternalThread" was set to true in the constructor, this method provides 00142 // a standard file descriptor that can be used in a select statement to signal that 00143 // there are method callbacks ready (i.e. that "pollCallbacks" will result in at 00144 // least one method call). When this fd is ready-for-read, pollCallbacks may be 00145 // invoked. Calling pollCallbacks shall reset the ready-to-read state of the fd. 00146 // 00147 virtual int getSignalFd() = 0; 00148 }; 00149 00150 }} 00151 00152 #endif