[Orxonox-commit 413] r2997 - in branches/ggz: cmake src/orxonox src/orxonox/objects

adrfried at orxonox.net adrfried at orxonox.net
Wed May 20 16:18:02 CEST 2009


Author: adrfried
Date: 2009-05-20 16:18:02 +0200 (Wed, 20 May 2009)
New Revision: 2997

Removed:
   branches/ggz/src/orxonox/objects/FDWatcher.cc
   branches/ggz/src/orxonox/objects/FDWatcher.h
Modified:
   branches/ggz/cmake/BuildConfigGCC.cmake
   branches/ggz/src/orxonox/GGZClient.cc
   branches/ggz/src/orxonox/GGZClient.h
   branches/ggz/src/orxonox/objects/CMakeLists.txt
Log:
some asio functionality

Modified: branches/ggz/cmake/BuildConfigGCC.cmake
===================================================================
--- branches/ggz/cmake/BuildConfigGCC.cmake	2009-05-20 14:13:26 UTC (rev 2996)
+++ branches/ggz/cmake/BuildConfigGCC.cmake	2009-05-20 14:18:02 UTC (rev 2997)
@@ -63,6 +63,7 @@
 ADD_COMPILER_FLAGS("-Wno-sign-compare" GCC_NO_SYSTEM_HEADER_SUPPORT CACHE)
 
 # Increase warning level if requested
+SET(EXTRA_COMPILER_WARNINGS TRUE)
 IF(EXTRA_COMPILER_WARNINGS)
   ADD_COMPILER_FLAGS("-Wall -Wextra -Wno-unused-parameter" CACHE)
 ELSE()

Modified: branches/ggz/src/orxonox/GGZClient.cc
===================================================================
--- branches/ggz/src/orxonox/GGZClient.cc	2009-05-20 14:13:26 UTC (rev 2996)
+++ branches/ggz/src/orxonox/GGZClient.cc	2009-05-20 14:18:02 UTC (rev 2997)
@@ -7,10 +7,15 @@
     GGZClient* GGZClient::singletonRef_s = 0;
 
     GGZClient::GGZClient()
+        : ggzSocket(io), gameSocket(io)
     {
         assert(singletonRef_s == 0);
         singletonRef_s = this;
 
+        boost::asio::ip::tcp::socket::non_blocking_io non_blocking_io(true);
+        ggzSocket.io_control(non_blocking_io);
+        gameSocket.io_control(non_blocking_io);
+
         active = ggzmod_is_ggz_mode();
         if (active) {
             initGGZ();
@@ -33,6 +38,15 @@
         return *singletonRef_s;
     }
 
+    void GGZClient::tick(const float /*dt*/)
+    {
+        boost::system::error_code ec;
+        io.poll(ec);
+        if (ec) {
+            /* TODO: Error */
+        }
+    }
+
     void GGZClient::initGGZ()
     {
         ggzmod = ggzmod_new(GGZMOD_GAME);
@@ -41,11 +55,13 @@
         if (ggzmod_connect(ggzmod) < 0) {
             /* TODO: Error */
         }
-        int ggzSocket = ggzmod_get_fd(ggzmod);
-        if (ggzSocket < 0) {
+        int fd = ggzmod_get_fd(ggzmod);
+        if (fd < 0) {
             /* TODO: Error */
         }
-        sockets.add(ggzSocket, &orxonox::GGZClient::handleGGZ);
+        /* TODO: Error */
+        ggzSocket.assign(boost::asio::ip::tcp::v4(), fd);
+        ggzSocket.async_read_some(boost::asio::null_buffers(), handleGGZ);
     }
 
     void GGZClient::deinitGGZ()
@@ -55,13 +71,13 @@
     }
 
     /* Got data from game server */
-    void handleGame(int fd)
+    void handleGame(const boost::system::error_code& /*e*/)
     {
-        /* TODO: read from fd */
+        /* TODO: read from gameSocket */
     }
 
     /* Got data from GGZ */
-    void GGZClient::handleGGZ(int fd)
+    void GGZClient::handleGGZ(const boost::system::error_code& /*e*/)
     {
         ggzmod_dispatch(getInstance().ggzmod);
     }
@@ -71,7 +87,7 @@
             const void *data)
     {
         ggzmod_set_state(ggzmod, GGZMOD_STATE_PLAYING);
-        int gameSocket = *(int*)data;
-        getInstance().sockets.add(gameSocket, &orxonox::GGZClient::handleGGZ);
+        gameSocket.assign(boost::asio::ip::tcp::v4(), *(int*)data);
+        gameSocket.async_read_some(boost::asio::null_buffers(), handleGame);
     }
 }

Modified: branches/ggz/src/orxonox/GGZClient.h
===================================================================
--- branches/ggz/src/orxonox/GGZClient.h	2009-05-20 14:13:26 UTC (rev 2996)
+++ branches/ggz/src/orxonox/GGZClient.h	2009-05-20 14:18:02 UTC (rev 2997)
@@ -2,31 +2,35 @@
 #define _GGZClient_H__
 
 #include "OrxonoxPrereqs.h"
-#include "objects/FDWatcher.h"
+#include "objects/Tickable.h"
 
 #include <ggzmod.h>
+#include <boost/asio.hpp>
 
 namespace orxonox
 {
-    class _OrxonoxExport GGZClient
+    class _OrxonoxExport GGZClient : public Tickable
     {
         public:
             GGZClient();
             ~GGZClient();
 
             static GGZClient& getInstance();
+            virtual void tick(const float dt);
 
         private:
             static GGZClient* singletonRef_s;
 
             bool active;
-            GGZMod *ggzmod;
-            FDWatcher sockets;
+            GGZMod * ggzmod;
+            boost::asio::io_service io;
+            boost::asio::ip::tcp::socket ggzSocket;
+            boost::asio::ip::tcp::socket gameSocket;
 
             void initGGZ();
             void deinitGGZ();
-            static void handleGame(int fd);
-            static void handleGGZ(int fd);
+            void handleGame(const boost::system::error_code& e);
+            void handleGGZ(const boost::system::error_code& e);
             static void handleGGZModServer(GGZMod * ggzmod, GGZModEvent e,
                     const void *data);
     };

Modified: branches/ggz/src/orxonox/objects/CMakeLists.txt
===================================================================
--- branches/ggz/src/orxonox/objects/CMakeLists.txt	2009-05-20 14:13:26 UTC (rev 2996)
+++ branches/ggz/src/orxonox/objects/CMakeLists.txt	2009-05-20 14:18:02 UTC (rev 2997)
@@ -2,7 +2,6 @@
   EventListener.cc
   EventDispatcher.cc
   EventTarget.cc
-  FDWatcher.cc
   GlobalShader.cc
   Level.cc
   Radar.cc

Deleted: branches/ggz/src/orxonox/objects/FDWatcher.cc
===================================================================
--- branches/ggz/src/orxonox/objects/FDWatcher.cc	2009-05-20 14:13:26 UTC (rev 2996)
+++ branches/ggz/src/orxonox/objects/FDWatcher.cc	2009-05-20 14:18:02 UTC (rev 2997)
@@ -1,67 +0,0 @@
-#include "FDWatcher.h"
-
-namespace orxonox
-{
-    FDWatcher::FDWatcher()
-    {
-        pollfds = 0;
-        npollfds = 0;
-    }
-
-    FDWatcher::~FDWatcher()
-    {
-        if (pollfds) {
-            delete [] pollfds;
-        }
-    }
-
-    void FDWatcher::tick(const float dt)
-    {
-        int ret = poll(pollfds, npollfds, 0);
-        if (ret < 0) {
-            // TODO error
-        }
-        for (int i=0; ret>0; i++, ret--) {
-            if (pollfds[i].revents & POLLIN) {
-                (*watches[pollfds[i].fd])(pollfds[i].fd);
-            }
-            if (pollfds[i].revents & !POLLIN) {
-                // TODO error
-            }
-        }
-    }
-
-    void FDWatcher::add(const int fd, intfunction cb)
-    {
-        watches[fd] = cb;
-        npollfds++;
-        rebuild();
-    }
-
-    void FDWatcher::remove(const int fd)
-    {
-        watches.erase(fd);
-        npollfds--;
-        rebuild();
-    }
-
-    void FDWatcher::rebuild()
-    {
-        if (pollfds) {
-            delete [] pollfds;
-        }
-        if (npollfds) {
-            pollfds = new struct pollfd[npollfds];
-        }
-        else {
-            pollfds = 0;
-        }
-        int i=0;
-        for (std::map<int, intfunction>::iterator it=watches.begin();
-                it!=watches.end(); it++, i++)
-        {
-            pollfds[i].fd = it->first;
-            pollfds[i].events = POLLIN;
-        }
-    }
-}

Deleted: branches/ggz/src/orxonox/objects/FDWatcher.h
===================================================================
--- branches/ggz/src/orxonox/objects/FDWatcher.h	2009-05-20 14:13:26 UTC (rev 2996)
+++ branches/ggz/src/orxonox/objects/FDWatcher.h	2009-05-20 14:18:02 UTC (rev 2997)
@@ -1,33 +0,0 @@
-#ifndef _FDWATCHER_H__
-#define _FDWATCHER_H__
-
-#include "objects/Tickable.h"
-
-#include <map>
-#include <poll.h>
-
-namespace orxonox
-{
-    class _OrxonoxExport FDWatcher : public Tickable
-    {
-        typedef void (*intfunction) (int fd);
-
-        public:
-            FDWatcher();
-            ~FDWatcher();
-
-            virtual void tick(const float dt);
-
-            void add(const int fd, intfunction cb);
-            void remove(const int fd);
-
-        private:
-            std::map<int, intfunction> watches;
-            pollfd * pollfds;
-            int npollfds;
-
-            void rebuild();
-    };
-}
-
-#endif /* _FDWATCHER_H__ */




More information about the Orxonox-commit mailing list