00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 #ifndef __JAUS_CORE_COMPONENT__H 00041 #define __JAUS_CORE_COMPONENT__H 00042 00043 #include "jaus/core/transport/transport.h" 00044 #include "jaus/core/events/events.h" 00045 #include "jaus/core/liveness/liveness.h" 00046 #include "jaus/core/discovery/discovery.h" 00047 #include "jaus/core/control/accesscontrol.h" 00048 #include "jaus/core/management/management.h" 00049 #include "jaus/core/time/timeservice.h" 00050 #include <cxutils/ipc/mappedmemory.h> 00051 00052 namespace JAUS 00053 { 00081 class JAUS_CORE_DLL Component 00082 { 00083 public: 00084 // Constructor. 00085 Component(); 00086 // Destructor. 00087 virtual ~Component(); 00088 // Initializes the component with a given ID. 00089 virtual bool Initialize(const Address& id, 00090 const double serviceUpdateFrequency = 10.0); 00091 // Initializes the component with a given ID. 00092 virtual bool InitializeWithUniqueID(const unsigned int waitTimeMs = 3000, 00093 const double serviceUpdateFrequency = 10.0); 00094 // Check to see if component is initialized. 00095 inline bool IsInitialized() const { return mpTransportService->IsInitialized(); } 00096 // Loads settings for the component and it's services. 00097 bool LoadSettings(const std::string& filename); 00098 // Shutsdown the Component. 00099 void Shutdown(); 00100 // Gets a pointer to the service. 00101 inline Transport* TransportService() { return mpTransportService; } 00102 // Gets a pointer to the service. 00103 Events* EventsService(); 00104 // Gets a pointer to the service. 00105 Liveness* LivenessService(); 00106 // Gets a pointer to the service. 00107 Discovery* DiscoveryService(); 00108 // Gets a pointer to the service. 00109 AccessControl* AccessControlService(); 00110 // Gets a pointer to the service. 00111 Management* ManagementService(); 00112 // Gets a pointer to the service. 00113 TimeService* GetTimeService(); 00114 // Gets a pointer to the service. 00115 inline const Transport* TransportService() const { return mpTransportService; } 00116 // Gets a pointer to the service. 00117 const Events* EventsService() const; 00118 // Gets a pointer to the service. 00119 const Liveness* LivenessService() const; 00120 // Gets a pointer to the service. 00121 const Discovery* DiscoveryService() const; 00122 // Gets a pointer to the service. 00123 const AccessControl* AccessControlService() const; 00124 // Gets a pointer to the service. 00125 const Management* ManagementService() const; 00126 // Gets a pointer to the service. 00127 const TimeService* GetTimeService() const; 00128 // Sends a message. 00129 bool Send(const Message* message, const int broadcastFlags = Service::NoBroadcast) const; 00130 // Sends a message, then waits for a response. 00131 bool Send(const Message* message, 00132 Message* response, 00133 const unsigned int waitTimeMs = Service::DefaultWaitMs) const; 00134 // Toggles a Service on or off. By default, all services are enabled. 00135 bool EnableService(const std::string& name, const bool enable = true); 00136 // Adds a service to the component. Service pointer is owned by Component. 00137 bool AddService(Service* service); 00138 // Gets a pointer to a service. 00139 Service* GetService(const std::string& name); 00140 // Gets a pointer to a service. 00141 const Service* GetService(const std::string& name) const; 00142 // Gets all services. 00143 inline Service::Map GetServices() { return mServices; } 00144 // Gets a list of all services for the Component. 00145 Service::ID::List GetServiceList() const; 00146 // Gets a list of all services for the Component. 00147 Service::ID::Set GetServiceSet() const; 00148 // Gets the component ID. 00149 inline Address GetComponentID() const { return mComponentID; } 00150 // Prints the status information for all services. 00151 virtual void PrintStatus() const; 00152 private: 00153 static void CheckServiceStatusEvent(void* args); 00154 static void CheckCoreServicesStatusEvent(void* args); 00155 Address mComponentID; 00156 volatile bool mInitializedFlag; 00157 Time::Stamp mServiceCheckTimeMs; 00158 Time::Stamp mCoreServicesCheckTimeMs; 00159 Transport* mpTransportService; 00160 Service::Map mServices; 00161 CxUtils::Timer mCheckServiceTimer; 00162 CxUtils::Timer mCheckCoreServicesTimer; 00163 Events* mpEventsService; 00164 Liveness* mpLivenessService; 00165 Discovery* mpDiscoveryService; 00166 AccessControl * mpAccessControlService; 00167 Management* mpManagementService; 00168 TimeService* mpTimeService; 00169 CxUtils::MappedMemory mLockID; 00170 }; 00171 } 00172 00173 #endif 00174 /* End of File */