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_DISCOVERY__H 00041 #define __JAUS_CORE_DISCOVERY__H 00042 00043 #include "jaus/core/discovery/vehicle.h" 00044 #include "jaus/core/events/events.h" 00045 #include "jaus/core/transport/transport.h" 00046 #include "jaus/core/discovery/queryconfiguration.h" 00047 #include "jaus/core/discovery/queryidentification.h" 00048 #include "jaus/core/discovery/queryservices.h" 00049 #include "jaus/core/discovery/querysubsystemlist.h" 00050 #include "jaus/core/discovery/registerservices.h" 00051 #include "jaus/core/discovery/reportconfiguration.h" 00052 #include "jaus/core/discovery/reportidentification.h" 00053 #include "jaus/core/discovery/reportservices.h" 00054 #include "jaus/core/discovery/reportsubsystemlist.h" 00055 00056 namespace JAUS 00057 { 00075 class JAUS_CORE_DLL Discovery : public Events::Child 00076 { 00077 public: 00078 const static std::string Name; 00079 00080 00081 00082 00083 00084 00085 00086 class JAUS_CORE_DLL Callback : public Transport::Callback 00087 { 00088 public: 00089 typedef std::set<Callback* > Set; 00090 Callback() {} 00091 virtual ~Callback() {} 00092 virtual void ProcessSystemState(const Subsystem::Map& system){}; 00093 }; 00094 typedef std::map<UShort, std::string> List; 00095 Discovery(); 00096 ~Discovery(); 00097 // Loads settings from XML specific to the Service. 00098 virtual bool LoadSettings(const std::string& filename); 00099 // Initializes the service. 00100 virtual void Initialize(); 00101 // Shutsdown the Service. 00102 virtual void Shutdown(); 00103 // Events service is always discoverable. 00104 virtual bool IsDiscoverable() const { return true; } 00105 // Processes messages associated with the Events service. 00106 virtual void Receive(const Message* message); 00107 // Creates messages associated with the events service. 00108 virtual Message* CreateMessage(const UShort messageCode) const; 00109 // When called verifies that no subscriptions have been lost. 00110 virtual void CheckServiceStatus(const unsigned int timeSinceLastCheckMs); 00111 // Method called when an Event has been signaled, generates an Event message. 00112 virtual bool GenerateEvent(const Events::Subscription& info) const; 00113 // Method called to determine if an Event is supported by the service. 00114 virtual bool IsEventSupported(const Events::Type type, 00115 const double requestedPeriodicRate, 00116 const Message* queryMessage, 00117 double& confirmedPeriodicRate, 00118 std::string& errorMessage) const; 00119 // Sets the name of the component. 00120 void SetComponentIdentification(const std::string& identification) { mComponentIdentification = identification; } 00121 // Sets the name of the node. 00122 void SetNodeIdentification(const std::string& identification) { mNodeIdentification = identification; } 00123 // Sets the identification of the subsystem. 00124 void SetSubsystemIdentification(const Subsystem::Type type, 00125 const std::string& identification); 00126 // Sets how often to broadast messages for discovery. 00127 bool SetDiscoveryFrequency(const double frequencyHz); 00128 // Sets whether or not to perform a global query for other subsystems (default is on). 00129 void DiscoverSubsystems(const bool enable = true) { mDiscoverSubsystemsFlag = enable; } 00130 // Gets the subsystem type. 00131 Subsystem::Type GetSubsystemType() const { return mSubsystemType; } 00132 // Gets this subsystem identification. 00133 std::string GetSubsystemIdentification() const { return mSubsystemIdentification; } 00134 // Gets this subsystem identification. 00135 std::string GetNodeIdentification() const { return mNodeIdentification; } 00136 // Gets this subsystem identification. 00137 std::string GetComponentIdentification() const { return mComponentIdentification; } 00138 // Gets a list of subsystems by name and ID. 00139 List GetSubsystemList() const; 00140 // Gets a list of subsystems (that are Vehicles) by name and ID. 00141 List GetVehicleList() const; 00142 // Gets a list of component IDs with a service. 00143 Address::List GetComponentsWithService(const std::string& serviceName) const; 00144 // Gets a pointer to subsystem data that is thread safe. 00145 Subsystem::Ptr GetSubsystem(const UShort id); 00146 // Gets a pointer to subsystem data that is thread safe. 00147 Subsystem::Ptr GetSubsystem(const Address& id) { return GetSubsystem(id.mSubsystem); } 00148 // Gets a pointer to subsystem data that is thread safe. 00149 const Subsystem::Ptr GetSubsystem(const UShort id) const; 00150 // Gets a pointer to subsystem data that is thread safe. 00151 const Subsystem::Ptr GetSubsystem(const Address& id) const { return GetSubsystem(id.mSubsystem); } 00152 // Gets a pointer to subsystem data that is thread safe. 00153 Vehicle::Ptr GetVehicle(const UShort id); 00154 // Gets a pointer to subsystem data that is thread safe. 00155 Vehicle::Ptr GetVehicle(const Address& id) { return GetVehicle(id.mSubsystem); } 00156 // Gets a pointer to subsystem data that is thread safe. 00157 const Vehicle::Ptr GetVehicle(const UShort id) const; 00158 // Gets a pointer to subsystem data that is thread safe. 00159 const Vehicle::Ptr GetVehicle(const Address& id) const { return GetVehicle(id.mSubsystem); } 00160 // Gets copy of all the Subsystem data (YOU MUST DELETE THIS DATA WHEN DONE). 00161 void GetSubsystems(Subsystem::Map& subsystems) const; 00162 // Gets copy of all the Vehicle data (YOU MUST DELETE THIS DATA WHEN DONE). 00163 void GetVehicles(Vehicle::Map& vehicles) const; 00164 // Register to receive updates of subsystems (add or removes callback). 00165 void RegisterCallback(Callback* callback, const bool add = true); 00166 // Prints system configuration information to the console. 00167 void PrintSystemConfiguration() const; 00168 // Prints information about the service. 00169 virtual void PrintStatus() const; 00170 // Triggers discovery callbacks. 00171 void TriggerDiscoveryCallbacks(); 00172 // Sets a list of subsystems that you want Discovery to find (ignoring all others). 00173 void SetSubsystemsToDiscover(const std::set<UShort>& toDiscover); 00174 // Gets the set of subsystems you want to discover (if empty, all are discovered). 00175 std::set<UShort> GetSubsystemsToDiscover() const; 00176 private: 00177 volatile bool mDiscoverSubsystemsFlag; 00178 Mutex mSubsystemDataMutex; 00179 Mutex mCallbacksMutex; 00180 unsigned int mBroadcastDelayMs; 00181 Time::Stamp mBroadcastTimeMs; 00182 Subsystem::Map mSystem; 00183 Callback::Set mCallbacks; 00184 std::string mComponentIdentification; 00185 std::string mNodeIdentification; 00186 std::string mSubsystemIdentification; 00187 Subsystem::Type mSubsystemType; 00188 Address::Set mSubsystemList; 00189 std::set<UShort> mSubsystemsToDiscover; 00190 }; 00191 } 00192 00193 #endif 00194 /* End of File */