Protocols: Move __THROW__ macro to MMSException header file
[remote/remote-mci.git] / mcs / Mote.h
bloba10e2bf96f926946373ea6c5d75ae667b3611a80
1 #ifndef _MOTE_H_
2 #define _MOTE_H_
4 #include "Session.h"
5 #include "MoteControlInfrastructure.h"
6 #include "MsgPayload.h"
8 namespace remote { namespace mcs {
10 class Host;
11 class Session;
12 class Mote;
14 typedef std::map<dbkey_t,Mote*> motemapbykey_t;
16 /** The mote class acts as a global mote pool. Any client requests for mote
17 control are handled by this class. Also, MoteControlInfrastructure instances must
18 report their available motes to this class. Finally, the mote class
19 maintains high level information about mote-site relations.
20 Mote objects know their indexes in the global mote pool as well as the
21 responsible MoteControlInfrastructure object along with the custom address
22 (MCIAddress) that uniquely identifies the mote within the owning
23 MoteControlInfrastructure object. Motes are globally uniquely identified using their
24 primary key ID from the database. The MoteControlInfrastructure object is responsible
25 for resolving the global ID of any mote before creating a Mote object. The
26 ID is connected to the actual mote rather than the site the mote is
27 attached to. Therefore, the MCIAddress and the MoteControlInfrastructure may
28 become invalid if the mote is hotplugged. Whenever this happens, the
29 MoteControlInfrastructure losing the mote must delete the mote.
30 The MoteControlInfrastructure getting the mote must look up the global ID
31 in the database and create the Mote object anew.
32 **/
33 class Mote
35 public:
36 /** Request client control of the mote with the specified id.
37 * \param p_mote_id Database key of the mote
38 * \param p_session Pointer to the session object requesting control
39 * \param p_mote Pointer-pointer to receive a pointer for the mote object
40 * \returns
41 **/
42 static result_t getById( dbkey_t p_mote_id,
43 Session* p_session,
44 Mote** p_mote );
46 /** Reset all nonstatic information about all motes in the database. **/
47 static void resetDb();
49 /** Look up the mote with specified id in the database, register the
50 * site on the mote.
51 * \param p_mote_id Database key of the mote
52 * \param p_site_id Database key of the site
53 * \param p_infrastructure Control infrastructure object owning the mote
54 * \param p_mciAddress Control infrastructure address of the mote
55 **/
56 Mote( dbkey_t p_mote_id,
57 dbkey_t p_site_id,
58 MoteControlInfrastructure& p_infrastructure,
59 MCIAddress& p_mciAddress );
61 /** Create a new mote in the database with specified site_id.
62 * \param p_site_id Database key of the site
63 * \param p_infrastructure Control infrastructure object owning the mote
64 * \param p_mciAddress Control infrastructure address of the mote
65 * **/
66 Mote( dbkey_t p_site_id,
67 MoteControlInfrastructure& p_infrastructure,
68 MCIAddress& p_mciAddress );
70 /** Delete the mote object
71 * \param silent If true, exceptions are caught and logged silently.
72 * */
73 void destroy(bool silent = false);
75 /** Sets a session object for the mote.
76 * \param p_session Pointer to the session to set.
77 **/
78 bool setSession( Session* p_session );
80 /** Removes the mote from the current session, if any.
81 * \param notify If true, the session should notify its client that the mote is no longer
82 * controlled.
83 **/
84 void dropSession(bool notify = true);
86 /** Send message to the mote.
87 * \param request Messsage to send
88 **/
89 void request( MsgPayload& request );
91 /** Receive message from the mote
92 * \param confirm Message to receive
93 **/
94 void confirm( MsgPayload& confirm );
96 /** Register a custom attribute on the mote in the database.
97 * The attribute type must pre-exist in the database or else
98 * an exception is thrown. If an attribute
99 * with the given type and value does not exist, it is created.
100 * If the mote allready has an attribute of the given type, this
101 * attribute is removed from the mote.
102 * \param type Name of the attribute type
103 * \param value Attribute value to assign
105 void setAttribute(std::string type, std::string value);
107 /** Query existence of attribute. */
108 std::string getAttribute(std::string type);
110 /** Mote Control Infrastructure address. **/
111 MCIAddress& mciAddress;
112 /** Database key of the mote **/
113 dbkey_t mote_id;
114 /** Database ket of the current deployment site of the mote. **/
115 dbkey_t site_id;
117 protected:
118 /** Mote object destructor **/
119 virtual ~Mote();
120 /** ensures no dangling mote pointers
121 * \param mote
123 static void registerMote(Mote* mote); //
124 /** Keyed map of all current Mote objects **/
125 static motemapbykey_t mote;
126 /** The current owner of this mote **/
127 MoteControlInfrastructure& mci;
128 /** The session currently in control of this mote **/
129 Session* session;
134 #endif