KoduDiscover.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_KoduDiscover_h_
00003 #define INCLUDED_KoduDiscover_h_
00004
00005 #include "Events/EventBase.h"
00006 #include "Events/EventListener.h"
00007 #include "Wireless/Wireless.h"
00008 #include <map>
00009 #include <string>
00010
00011 using namespace std;
00012
00013 namespace KoduType {
00014 typedef enum {
00015 INVALID = 0,
00016 KODU,
00017 CYCLE,
00018 OCTOPUS,
00019 TURTLE,
00020 NUM_TYPES
00021 } player_type;
00022
00023 extern string strs[];
00024 }
00025
00026 typedef struct {
00027 int hostAddr;
00028 KoduType::player_type type;
00029 } player_identity;
00030
00031 typedef void (*ident_callback)(player_identity *ident, void *cb_arg);
00032
00033 class KoduDiscover : public EventListener {
00034 public:
00035 KoduDiscover(player_identity& ident, const string& iface);
00036 ~KoduDiscover();
00037
00038 void setNewRobotCallback(ident_callback new_robot, void *cb_arg);
00039
00040 static map<int, player_identity> players;
00041 private:
00042 static player_identity my_identity;
00043 static Socket *discover_sock;
00044 static Socket *broadcast_sock;
00045 static void *callback_arg;
00046 static ident_callback new_robot;
00047 static int discover_rcv(char* buf, int size);
00048 void processEvent(const EventBase& event);
00049 };
00050
00051 #endif