Protocols: Move __THROW__ macro to MMSException header file
[remote/remote-mci.git] / mcs / Host.h
blobf8a4f956fa65e0e942050d1848195fea0c491f7d
1 #ifndef _HOST_H_
2 #define _HOST_H_
4 #include "tcputil.h"
5 #include "types.h"
6 #include "Mote.h"
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"
17 #include <stdlib.h>
19 namespace remote { namespace mcs {
21 using namespace protocols::host_server;
22 using namespace remote::mcs;
24 //class Mote;
25 class Host;
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.
32 **/
33 class Host : public FileDescriptor, public MoteControlInfrastructure
35 public:
36 /** Send a message to a mote.
37 * \param address Address of the mote
38 * \param request Message payload
39 **/
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
47 **/
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
51 **/
52 void destroy(bool silent=false);
53 protected:
54 /** Destructor **/
55 virtual ~Host();
56 /** Handle an event that occured on the file descriptor
57 * \param events Event descriptor
58 **/
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.
62 **/
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
67 **/
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
72 **/
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.
78 **/
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.
83 **/
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.
88 **/
89 void findOrCreateMote(MsgMoteConnectionInfo& info);
91 /** Database key of this host **/
92 dbkey_t id;
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 **/
99 Message message_in;
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;
108 #endif