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/Manageable.h" 00025 #include "qpid/sys/Mutex.h" 00026 00027 namespace qpid { 00028 namespace management { 00029 00030 class ManagementAgent 00031 { 00032 public: 00033 00034 class Singleton { 00035 public: 00036 Singleton(bool disableManagement = false); 00037 ~Singleton(); 00038 static ManagementAgent* getInstance(); 00039 private: 00040 static sys::Mutex lock; 00041 static bool disabled; 00042 static int refCount; 00043 static ManagementAgent* agent; 00044 }; 00045 00046 ManagementAgent () {} 00047 virtual ~ManagementAgent () {} 00048 00049 virtual int getMaxThreads() = 0; 00050 00051 // Connect to a management broker 00052 // 00053 // brokerHost - Hostname or IP address (dotted-quad) of broker. 00054 // 00055 // brokerPort - TCP port of broker. 00056 // 00057 // intervalSeconds - The interval (in seconds) that this agent shall use 00058 // between broadcast updates to the broker. 00059 // 00060 // useExternalThread - If true, the thread of control used for callbacks 00061 // must be supplied by the user of the object (via the 00062 // pollCallbacks method). 00063 // 00064 // If false, callbacks shall be invoked on the management 00065 // agent's thread. In this case, the callback implementations 00066 // MUST be thread safe. 00067 // 00068 virtual void init (std::string brokerHost = "localhost", 00069 uint16_t brokerPort = 5672, 00070 uint16_t intervalSeconds = 10, 00071 bool useExternalThread = false) = 0; 00072 00073 // Register a schema with the management agent. This is normally called by the 00074 // package initializer generated by the management code generator. 00075 // 00076 virtual void 00077 RegisterClass (std::string packageName, 00078 std::string className, 00079 uint8_t* md5Sum, 00080 management::ManagementObject::writeSchemaCall_t schemaCall) = 0; 00081 00082 // Add a management object to the agent. Once added, this object shall be visible 00083 // in the greater management context. 00084 // 00085 // Please note that ManagementObject instances are not explicitly deleted from 00086 // the management agent. When the core object represented by a management object 00087 // is deleted, the "resourceDestroy" method on the management object must be called. 00088 // It will then be reclaimed in due course by the management agent. 00089 // 00090 // Once a ManagementObject instance is added to the agent, the agent then owns the 00091 // instance. The caller MUST NOT free the resources of the instance at any time. 00092 // When it is no longer needed, invoke its "resourceDestroy" method and discard the 00093 // pointer. This allows the management agent to report the deletion of the object 00094 // in an orderly way. 00095 // 00096 virtual uint64_t addObject (ManagementObject* objectPtr, 00097 uint32_t persistId = 0, 00098 uint32_t persistBank = 4) = 0; 00099 00100 // If "useExternalThread" was set to true in init, this method must 00101 // be called to provide a thread for any pending method calls that have arrived. 00102 // The method calls for ManagementObject instances shall be invoked synchronously 00103 // during the execution of this method. 00104 // 00105 // callLimit may optionally be used to limit the number of callbacks invoked. 00106 // if 0, no limit is imposed. 00107 // 00108 // The return value is the number of callbacks that remain queued after this 00109 // call is complete. It can be used to determine whether or not further calls 00110 // to pollCallbacks are necessary to clear the backlog. If callLimit is zero, 00111 // the return value will also be zero. 00112 // 00113 virtual uint32_t pollCallbacks (uint32_t callLimit = 0) = 0; 00114 00115 // If "useExternalThread" was set to true in the constructor, this method provides 00116 // a standard file descriptor that can be used in a select statement to signal that 00117 // there are method callbacks ready (i.e. that "pollCallbacks" will result in at 00118 // least one method call). When this fd is ready-for-read, pollCallbacks may be 00119 // invoked. Calling pollCallbacks shall reset the ready-to-read state of the fd. 00120 // 00121 virtual int getSignalFd (void) = 0; 00122 00123 }; 00124 00125 }} 00126 00127 #endif