Commits

Nikhil Marathe  committed 5ac4b73

Added basic receiving and switch based dispatch

  • Participants
  • Parent commits a958648

Comments (0)

Files changed (2)

 DDM::~DDM()
 {
     m_running = false;
+    google::protobuf::ShutdownProtobufLibrary();
     curl_global_cleanup();
 }
 
     SocketHandler main;
     port_t p = port;
 
-    McastSocket mcast(main);
+    m_mcastSock = new McastSocket(main, this );
 
-    if( mcast.Bind(p) )
+    if( m_mcastSock->Bind(p) )
     {
         std::cerr << "Could not bind to UDP 2345\n";
         exit( -1 );
         exit( -1 );
     }
 
-    main.Add( &mcast );
+    main.Add( m_mcastSock );
     main.Add( &listen );
 
     while( m_running )
     //    m_handler->Select( 1, 0 );
 }
 
+void DDM::incoming( const proto::Packet& packet )
+{
+    switch ( packet.command() )
+    {
+        case proto::Packet::HELLO:
+            addPeer( packet.from() );
+            break;
+
+        default:
+            break;
+    }
+}
+
 void DDM::addUrl( std::string url )
 {
 }
 #define DDM_H
 
 class SocketHandler;
-class McastSocket;
+namespace proto
+{
+class Packet;
+}
+
 namespace ddm
 {
+class McastSocket;
 class DDM
 {
 public:
 
     void addUrl( std::string url );
     void start(int port);
+    void incoming( const proto::Packet& packet );
 
 private:
     void mainLoop();