5 #include "MoteControlInfrastructure.h"
6 #include "MsgPayload.h"
8 namespace remote
{ namespace mcs
{
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.
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
42 static result_t
getById( dbkey_t p_mote_id
,
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
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
56 Mote( dbkey_t p_mote_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
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.
73 void destroy(bool silent
= false);
75 /** Sets a session object for the mote.
76 * \param p_session Pointer to the session to set.
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
84 void dropSession(bool notify
= true);
86 /** Send message to the mote.
87 * \param request Messsage to send
89 void request( MsgPayload
& request
);
91 /** Receive message from the mote
92 * \param confirm Message to receive
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 **/
114 /** Database ket of the current deployment site of the mote. **/
118 /** Mote object destructor **/
120 /** ensures no dangling mote pointers
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 **/