Go to the documentation of this file.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_ACCESS_CONTROL__H
00041 #define __JAUS_CORE_ACCESS_CONTROL__H
00042
00043 #include "jaus/core/discovery/discovery.h"
00044 #include "jaus/core/control/confirmcontrol.h"
00045 #include "jaus/core/control/queryauthority.h"
00046 #include "jaus/core/control/querycontrol.h"
00047 #include "jaus/core/control/querytimeout.h"
00048 #include "jaus/core/control/rejectcontrol.h"
00049 #include "jaus/core/control/releasecontrol.h"
00050 #include "jaus/core/control/reportauthority.h"
00051 #include "jaus/core/control/reportcontrol.h"
00052 #include "jaus/core/control/reporttimeout.h"
00053 #include "jaus/core/control/requestcontrol.h"
00054 #include "jaus/core/control/setauthority.h"
00055
00056 namespace JAUS
00057 {
00072 class JAUS_CORE_DLL AccessControl : public Events::Child
00073 {
00074 public:
00083 class JAUS_CORE_DLL Callback : public Discovery::Callback
00084 {
00085 public:
00086 typedef std::set<Callback* > Set;
00087 Callback() {}
00088 virtual ~Callback() {}
00089
00090 virtual void ProcessLossOfControl(const Address& controlledComponent) {}
00091
00092 virtual void ProcessAcquisitionfControl(const Address& controlledComponent) {}
00093
00094 virtual void ProcessReleaseOfControl(const Address& controllerID) {}
00095 };
00103 class JAUS_CORE_DLL Child : public Events::Child
00104 {
00105 public:
00106 Child(const ID& serviceIdentifier,
00107 const ID& parentServiceIdentifier) : Events::Child(serviceIdentifier,
00108 parentServiceIdentifier) {}
00109 virtual ~Child() {}
00116 virtual bool RequestControl() { return true; }
00123 virtual bool ReleaseControl() { return true; }
00136 virtual void ProcessAcquisitionOfControl(const Address& controlledComponent) {}
00137 };
00138 const static std::string Name;
00139
00140 AccessControl();
00141
00142 ~AccessControl();
00143
00144 bool AcceptCommandMessage(const Message* commandMessage) const;
00145
00146 virtual bool LoadSettings(const std::string& filename);
00147
00148 virtual void Shutdown();
00149
00150 bool RequestComponentControl(const Address& id,
00151 const bool reacquire = true,
00152 const unsigned int waitTimeMs = Service::DefaultWaitMs);
00153
00154 bool ReleaseComponentControl(const Address& id,
00155 const unsigned int waitTimeMs = Service::DefaultWaitMs);
00156
00157 virtual bool GenerateEvent(const Events::Subscription& info) const;
00158
00159 virtual bool IsEventSupported(const Events::Type type,
00160 const double requestedPeriodicRate,
00161 const Message* queryMessage,
00162 double& confirmedPeriodicRate,
00163 std::string& errorMessage) const;
00164
00165 void SetControllable(const bool on = true);
00166
00167 inline bool IsControllable() const { return mControllableFlag; }
00168
00169 virtual bool IsDiscoverable() const { return true; }
00170
00171 virtual void Receive(const Message* message);
00172
00173 virtual Message* CreateMessage(const UShort messageCode) const;
00174
00175 void SetAuthorityCode(const Byte authorityCode);
00176
00177 inline Byte GetAuthorityCode() const { return mAuthorityCode; }
00178
00179 bool HaveControl(const Address& id) const;
00180
00181 bool IsControlled() const;
00182
00183 void SetControllerID(const Address& id);
00184
00185 Address GetControllerID() const;
00186
00187 Byte GetControllerAuthorityCode() const;
00188
00189 Address::List GetControlledComponents() const;
00190
00191 virtual void CheckServiceStatus(const unsigned int timeSinceLastCheckMs);
00192
00193 Byte GetTimeoutPeriod() const;
00194
00195 void SetTimeoutPeriod(const Byte timeSeconds);
00196
00197 Time::Stamp GetControlCheckPeriod() const;
00198
00199 Time GetControllerUpdateTime() const { return mControllerUpdateTime; }
00200
00201 void RegisterCallback(Callback* callback, const bool add = true);
00202
00203 virtual void PrintStatus() const;
00204 protected:
00205 bool mControllableFlag;
00206 Byte mAuthorityCode;
00207 Mutex mControlMutex;
00208 Address::Set mControlledComponents;
00209 Address::Set mToReleaseControl;
00210 std::map<Address, bool> mMaintainFlags;
00211 std::map<Address, bool> mControlFlags;
00212 Address mControllerID;
00213 Byte mControllerAuthorityCode;
00214 Time mControllerUpdateTime;
00215 Time mControllerCheckTime;
00216 Byte mTimeoutPeriod;
00217 double mTimeoutThreshold;
00218 std::map<Address, Byte> mTimeoutPeriods;
00219 std::map<Address, Time> mControlCheckTimes;
00220 std::map<Address, Time> mControlConfirmTimes;
00221 Callback::Set mCallbacks;
00222 Mutex mCallbacksMutex;
00223 private:
00224 void EraseComponentControlInfo(const Address& id);
00225 };
00226 }
00227
00228 #endif
00229