7 #include "FileDescriptor.h"
8 #include "MoteControlInfrastructure.h"
9 #include "MoteAddresses.h"
10 #include "host_server/HostMsg.h"
11 #include "host_server/MsgPlugEvent.h"
12 #include "host_server/MsgHostRequest.h"
13 #include "host_server/MsgHostConfirm.h"
14 #include "host_server/MsgMoteAddresses.h"
15 #include "host_server/MsgMoteConnectionInfoList.h"
16 #include "host_server/MsgMoteConnectionInfo.h"
19 namespace remote
{ namespace mcs
{
21 using namespace protocols::host_server
;
22 using namespace remote::mcs
;
27 typedef std::map
<std::string
, Mote
*> motemapbymac_t
;
28 typedef std::map
<dbkey_t
,Host
*> hostmapbykey_t
;
30 /** This class handles a single mote host connection. It listens for infrastructure changes and
31 * updates the mote database accordingly. It routes mote messages to and from the mote host.
33 class Host
: public FileDescriptor
, public MoteControlInfrastructure
36 /** Send a message to a mote.
37 * \param address Address of the mote
38 * \param request Message payload
40 void request( MCIAddress
& address
, MsgPayload
& request
);
42 /** Constructor - create a new host connection
43 * \param fd File descriptor for this host connection
44 * \param p_id Database key of this host
45 * \param IP address of this host
46 * \param host map to register the new host connection object in
48 Host( int fd
, dbkey_t p_id
, std::string ip
, hostmapbykey_t
& p_hostMap
);
49 /** Clean up this host and destroy it.
50 * \param silent If true, catch and log any exceptions
52 void destroy(bool silent
=false);
56 /** Handle an event that occured on the file descriptor
57 * \param events Event descriptor
59 void handleEvent(short events
); // handle an event on the host socket
60 /** Handle a message received from a mote host.
61 * \param msgHostMote Message that was received.
63 void handleMsgIn(MsgHostConfirm
& msgHostConfirm
);
64 /** Update the local image of the mote infrastructure to reflect
65 * that a set of motes were unplugged.
66 * \param infolist List of motes that were unplugged
68 void handleMotesLostList(MsgMoteConnectionInfoList
& infolist
);
69 /** Update the local image of the mote infrastructure to reflect
70 * that a set of motes were plugged in.
71 * \param infolist List of motes that were plugged in
73 void handleMotesFoundList(MsgMoteConnectionInfoList
& infolist
);
75 /** Register this mote in a map by its MAC address.
76 * \param mac MAC address of the mote.
77 * \param mote Pointer for the mote object.
79 void registerMoteByMac(std::string mac
, Mote
*mote
);
81 /** Delete a mote object by its MAC address.
82 * \param mac MAC address of the mote to delete.
84 void deleteMoteByMac(std::string mac
);
85 /** Check if a mote object exists, and create it if it doesn't.
86 * \param info Connection information of the mote (MAC address and
87 * bus location string.
89 void findOrCreateMote(MsgMoteConnectionInfo
& info
);
91 /** Database key of this host **/
93 /** Index og this host in the host map **/
94 unsigned int hostIndex
;
95 /** Map of the motes attached to this host keyed by mote MAC **/
96 motemapbymac_t motesByMac
;
97 /** Map of additional deployment sepcific mote information keyed by mote MAC **/
98 /** Structure for incoming messages **/
100 /** IP address of this mote host **/
101 std::string ipaddress
;
102 /** Reference to the host map that this host is registered in **/
103 hostmapbykey_t
& hostMap
;