1 // 2 // Copyright (c) ZeroC, Inc. All rights reserved. 3 // 4 5 #ifndef SERVICE_MANAGER_I_H 6 #define SERVICE_MANAGER_I_H 7 8 #include <IceBox/IceBox.h> 9 #include <Ice/LoggerF.h> 10 #include <Ice/CommunicatorF.h> 11 #include <Ice/DynamicLibraryF.h> 12 #include <map> 13 14 namespace IceBox 15 { 16 17 class ServiceManagerI : public ServiceManager, 18 public IceUtil::Monitor<IceUtil::Mutex> 19 #ifdef ICE_CPP11_MAPPING 20 , public std::enable_shared_from_this<ServiceManagerI> 21 #endif 22 { 23 public: 24 25 ServiceManagerI(Ice::CommunicatorPtr, int&, char*[]); 26 virtual ~ServiceManagerI(); 27 28 virtual Ice::SliceChecksumDict getSliceChecksums(const Ice::Current&) const; 29 30 virtual void startService(ICE_IN(std::string), const ::Ice::Current&); 31 virtual void stopService(ICE_IN(std::string), const ::Ice::Current&); 32 33 virtual void addObserver(ICE_IN(ServiceObserverPrxPtr), const Ice::Current&); 34 35 virtual void shutdown(const ::Ice::Current&); 36 37 int run(); 38 39 bool start(); 40 void stop(); 41 42 #ifdef ICE_CPP11_MAPPING 43 void observerCompleted(const std::shared_ptr<ServiceObserverPrx>&, std::exception_ptr); 44 #else 45 void observerCompleted(const Ice::AsyncResultPtr&); 46 #endif 47 48 private: 49 50 enum ServiceStatus 51 { 52 Stopping, 53 Stopped, 54 Starting, 55 Started 56 }; 57 58 struct ServiceInfo 59 { 60 ::std::string name; 61 ServicePtr service; 62 ::IceInternal::DynamicLibraryPtr library; 63 ::Ice::CommunicatorPtr communicator; 64 ::std::string envName; 65 ServiceStatus status; 66 Ice::StringSeq args; 67 }; 68 69 void start(const std::string&, const std::string&, const ::Ice::StringSeq&); 70 void stopAll(); 71 72 void servicesStarted(const std::vector<std::string>&, const std::set<ServiceObserverPrxPtr>&); 73 void servicesStopped(const std::vector<std::string>&, const std::set<ServiceObserverPrxPtr>&); 74 75 #ifdef ICE_CPP11_MAPPING 76 std::function<void(std::exception_ptr)> makeObserverCompletedCallback(const std::shared_ptr<ServiceObserverPrx>&); 77 void observerRemoved(const std::shared_ptr<ServiceObserverPrx>&, std::exception_ptr); 78 #else 79 void observerRemoved(const ServiceObserverPrx&, const std::exception&); 80 #endif 81 82 Ice::PropertiesPtr createServiceProperties(const std::string&); 83 void destroyServiceCommunicator(const std::string&, const Ice::CommunicatorPtr&); 84 85 bool configureAdmin(const Ice::PropertiesPtr&, const std::string&); 86 void removeAdminFacets(const std::string&); 87 88 ::Ice::CommunicatorPtr _communicator; 89 bool _adminEnabled; 90 std::set<std::string> _adminFacetFilter; 91 ::Ice::CommunicatorPtr _sharedCommunicator; 92 ::Ice::LoggerPtr _logger; 93 ::Ice::StringSeq _argv; // Filtered server argument vector, not including program name 94 std::vector<ServiceInfo> _services; 95 bool _pendingStatusChanges; 96 97 std::set<ServiceObserverPrxPtr> _observers; 98 int _traceServiceObserver; 99 #ifndef ICE_CPP11_MAPPING 100 ::Ice::CallbackPtr _observerCompletedCB; 101 #endif 102 }; 103 ICE_DEFINE_PTR(ServiceManagerIPtr, ServiceManagerI); 104 105 } 106 107 #endif 108