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 struct moteinfo_s
32 typedef std::map
<std::string
, Mote
*> motemapbymac_t
;
33 typedef std::map
<std::string
, moteinfo_t
> moteinfobymac_t
;
34 typedef std::map
<dbkey_t
,Host
*> hostmapbykey_t
;
36 /** This class handles a single mote host connection. It listens for infrastructure changes and
37 * updates the mote database accordingly. It routes mote messages to and from the mote host.
39 class Host
: public FileDescriptor
, public MoteControlInfrastructure
42 /** Send a message to a mote.
43 * \param address Address of the mote
44 * \param request Message payload
46 void request( MCIAddress
& address
, MsgPayload
& request
);
48 /** Constructor - create a new host connection
49 * \param fd File descriptor for this host connection
50 * \param p_id Database key of this host
51 * \param IP address of this host
52 * \param host map to register the new host connection object in
54 Host( int fd
, dbkey_t p_id
, std::string ip
, hostmapbykey_t
& p_hostMap
);
55 /** Clean up this host and destroy it.
56 * \param silent If true, catch and log any exceptions
58 void destroy(bool silent
=false);
62 /** Handle an event that occured on the file descriptor
63 * \param events Event descriptor
65 void handleEvent(short events
); // handle an event on the host socket
66 /** Handle a message received from a mote host.
67 * \param msgHostMote Message that was received.
69 void handleMsgIn(MsgHostConfirm
& msgHostConfirm
);
70 /** Update the local image of the mote infrastructure to reflect
71 * that a set of motes were unplugged.
72 * \param infolist List of motes that were unplugged
74 void handleMotesLostList(MsgMoteConnectionInfoList
& infolist
);
75 /** Update the local image of the mote infrastructure to reflect
76 * that a set of motes were plugged in.
77 * \param infolist List of motes that were plugged in
79 void handleMotesFoundList(MsgMoteConnectionInfoList
& infolist
);
81 /** Register this mote in a map by its MAC address.
82 * \param mac MAC address of the mote.
83 * \param mote Pointer for the mote object.
85 void registerMoteByMac(std::string mac
, Mote
*mote
);
87 /** Delete a mote object by its MAC address.
88 * \param mac MAC address of the mote to delete.
90 void deleteMoteByMac(std::string mac
);
91 /** Register additional mote information by mote MAC address.
92 * \param mac MAC address of the mote
93 * \param moteinfo Additional mote information.
95 void registerMoteInfoByMac(std::string mac
, moteinfo_t moteinfo
);
96 /** Delete additional mote info by mote MAC address.
97 * \param mac MAC address of the mote
99 void deleteMoteInfoByMac(std::string mac
);
100 /** Check if a mote object exists, and create it if it doesn't.
101 * \param info Connection information of the mote (MAC address and
102 * bus location string.
104 void findOrCreateMote(MsgMoteConnectionInfo
& info
);
106 /** Database key of this host **/
108 /** Index og this host in the host map **/
109 unsigned int hostIndex
;
110 /** Map of the motes attached to this host keyed by mote MAC **/
111 motemapbymac_t motesByMac
;
112 /** Map of additional deployment sepcific mote information keyed by mote MAC **/
113 moteinfobymac_t moteInfoByMac
;
114 /** Structure for incoming messages **/
116 /** IP address of this mote host **/
117 std::string ipaddress
;
118 /** Reference to the host map that this host is registered in **/
119 hostmapbykey_t
& hostMap
;