]> git.sesse.net Git - cubemap/commitdiff
Move some serialization logic into ServerPool, where it belongs.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 12 Apr 2013 20:31:05 +0000 (22:31 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 12 Apr 2013 20:31:05 +0000 (22:31 +0200)
main.cpp
serverpool.cpp
serverpool.h

index c5640e0c6ecd6c70fadad8c748a1907dfbf565fe..eed486ebe39889dacac191aa7a0d9fc3a6c8a322 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -73,10 +73,9 @@ int make_tempfile(const CubemapStateProto &state)
 CubemapStateProto collect_state(const timeval &serialize_start,
                                 const vector<Acceptor *> acceptors,
                                 const vector<Input *> inputs,
 CubemapStateProto collect_state(const timeval &serialize_start,
                                 const vector<Acceptor *> acceptors,
                                 const vector<Input *> inputs,
-                                ServerPool *servers,
-                                int num_servers)
+                                ServerPool *servers)
 {
 {
-       CubemapStateProto state;
+       CubemapStateProto state = servers->serialize();  // Fills streams() and clients().
        state.set_serialize_start_sec(serialize_start.tv_sec);
        state.set_serialize_start_usec(serialize_start.tv_usec);
        
        state.set_serialize_start_sec(serialize_start.tv_sec);
        state.set_serialize_start_usec(serialize_start.tv_usec);
        
@@ -88,18 +87,6 @@ CubemapStateProto collect_state(const timeval &serialize_start,
                state.add_inputs()->MergeFrom(inputs[i]->serialize());
        }
 
                state.add_inputs()->MergeFrom(inputs[i]->serialize());
        }
 
-       for (int i = 0; i < num_servers; ++i) { 
-               CubemapStateProto local_state = servers->get_server(i)->serialize();
-
-               // The stream state should be identical between the servers, so we only store it once.
-               if (i == 0) {
-                       state.mutable_streams()->MergeFrom(local_state.streams());
-               }
-               for (int j = 0; j < local_state.clients_size(); ++j) {
-                       state.add_clients()->MergeFrom(local_state.clients(j));
-               }
-       }
-
        return state;
 }
 
        return state;
 }
 
@@ -375,7 +362,7 @@ int main(int argc, char **argv)
 
        fprintf(stderr, "Serializing state and re-execing...\n");
        int state_fd = make_tempfile(collect_state(
 
        fprintf(stderr, "Serializing state and re-execing...\n");
        int state_fd = make_tempfile(collect_state(
-               serialize_start, acceptors, inputs, servers, config.num_servers));
+               serialize_start, acceptors, inputs, servers));
        delete servers;
         
        char buf[16];
        delete servers;
         
        char buf[16];
index cf6933ccda181e23f4f7f7d85e353ec11b7d805a..9f1a7280662a68f35fb40cb8230af9cb75384978 100644 (file)
@@ -1,4 +1,5 @@
 #include "serverpool.h"
 #include "serverpool.h"
+#include "state.pb.h"
 
 using namespace std;
 
 
 using namespace std;
 
@@ -13,6 +14,25 @@ ServerPool::~ServerPool()
 {
        delete[] servers;
 }
 {
        delete[] servers;
 }
+       
+CubemapStateProto ServerPool::serialize()
+{
+       CubemapStateProto state;
+
+       for (int i = 0; i < num_servers; ++i) {
+                CubemapStateProto local_state = servers[i].serialize();
+
+               // The stream state should be identical between the servers, so we only store it once.
+               if (i == 0) {
+                       state.mutable_streams()->MergeFrom(local_state.streams());
+               }
+               for (int j = 0; j < local_state.clients_size(); ++j) {
+                       state.add_clients()->MergeFrom(local_state.clients(j));
+               }
+        }
+
+       return state;
+}
 
 void ServerPool::add_client(int sock)
 {
 
 void ServerPool::add_client(int sock)
 {
index 5dee5f778e8a534a720c0683405a8fe6e24b6313..559f76a212c1aab24ceeafb985c95d9e9102a1c7 100644 (file)
@@ -13,9 +13,8 @@ public:
        ServerPool(int num_servers);
        ~ServerPool();
 
        ServerPool(int num_servers);
        ~ServerPool();
 
-       // Accessor. Only to be used in rare situations, really.
-       // The ServerPool retains ownership.
-       Server *get_server(int num) { return &servers[num]; }
+       // Fills streams() and clients().
+       CubemapStateProto serialize();
 
        // Picks a server (round-robin) and allocates the given client to it.
        void add_client(int sock);
 
        // Picks a server (round-robin) and allocates the given client to it.
        void add_client(int sock);