Adding protobuf for SyncState
diff --git a/ice_cxx.py b/ice_cxx.py
deleted file mode 100644
index a876fb8..0000000
--- a/ice_cxx.py
+++ /dev/null
@@ -1,60 +0,0 @@
-# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
-#!/usr/bin/env python
-# encoding: utf-8
-# Alexander Afanasyev, 2013
-
-from waflib.Task import Task
-from waflib.TaskGen import extension
-from waflib import Logs
-from waflib import Node
-
-"""
-A simple tool to integrate zeroc ICE into your build system.
-
- def configure(conf):
- conf.load('compiler_cxx cxx ice_cxx')
-
- def build(bld):
- bld(
- features = 'cxx cxxprogram'
- source = 'main.cpp file1.ice',
- include = '.',
- target = 'executable')
-
-"""
-
-class ice_cxx(Task):
- run_str = '${SLICE2CPP} --header-ext ice.h --source-ext ice.cc --output-dir ${SRC[0].parent.get_bld().abspath()} ${SRC[0].abspath()}'
- color = 'BLUE'
- ext_out = ['.ice.h', '.ice.cc']
-
-@extension('.ice')
-def process_protoc(self, node):
- cpp_node = node.change_ext('.ice.cc')
- hpp_node = node.change_ext('.ice.h')
- self.create_task('ice_cxx', node, [cpp_node, hpp_node])
- self.source.append(cpp_node)
-
- use = getattr(self, 'use', '')
- if not 'ICE' in use:
- self.use = self.to_list(use) + ['ICE']
-
-ICE_PATHS = ['/usr', '/usr/local', '/opt/local', '/sw']
-
-def options(opt):
- opt.add_option('--ice',action='store',dest='ICE_PATH',help='''path to ZeroC installation''')
-
-
-def configure(conf):
- # conf.check_cfg(package="", uselib_store="PROTOBUF", args=['--cflags', '--libs'])
- if conf.options.ICE_PATH:
- conf.find_program('slice2cpp', var='SLICE2CPP', path_list="%s/bin" % conf.options.ICE_PATH, mandatory=True)
- else:
- conf.find_program('slice2cpp', var='SLICE2CPP', path_list=["%s/bin" % path for path in ICE_PATHS], mandatory=True)
-
- ICE_PATH = conf.env.SLICE2CPP[:-14]
-
- conf.env['LIB_ICE'] = ["Ice", "ZeroCIce", "IceUtil"]
- conf.env['INCLUDES_ICE']= '%s/include' % ICE_PATH
- conf.env['LIBPATH_ICE'] = '%s/lib' % ICE_PATH
-
diff --git a/src/sync-log.cc b/src/sync-log.cc
index 99b652c..3e49c69 100644
--- a/src/sync-log.cc
+++ b/src/sync-log.cc
@@ -149,13 +149,13 @@
sqlite3_finalize (stmt);
}
-void
+SyncStateMsgPtr
SyncLog::FindStateDifferences (const std::string &oldHash, const std::string &newHash)
{
- FindStateDifferences (*Hash::FromString (oldHash), *Hash::FromString (newHash));
+ return FindStateDifferences (*Hash::FromString (oldHash), *Hash::FromString (newHash));
}
-void
+SyncStateMsgPtr
SyncLog::FindStateDifferences (const Hash &oldHash, const Hash &newHash)
{
sqlite3_stmt *stmt;
@@ -208,12 +208,29 @@
res += sqlite3_bind_blob (stmt, 1, oldHash.GetHash (), oldHash.GetHashBytes (), SQLITE_STATIC);
res += sqlite3_bind_blob (stmt, 2, newHash.GetHash (), newHash.GetHashBytes (), SQLITE_STATIC);
+ SyncStateMsgPtr msg = make_shared<SyncStateMsg> ();
+
while (sqlite3_step (stmt) == SQLITE_ROW)
{
- std::cout << sqlite3_column_text (stmt, 0) <<
- ": from " << sqlite3_column_int64 (stmt, 1) <<
- " to " << sqlite3_column_int64 (stmt, 2) <<
- std::endl;
+ SyncState *state = msg->add_state ();
+
+ state->set_name (reinterpret_cast<const char*> (sqlite3_column_text (stmt, 0)));
+
+ sqlite3_int64 newSeqNo = sqlite3_column_int64 (stmt, 2);
+ if (newSeqNo > 0)
+ {
+ state->set_type (SyncState::UPDATE);
+ state->set_seq (newSeqNo);
+ }
+ else
+ state->set_type (SyncState::DELETE);
+
+ // std::cout << sqlite3_column_text (stmt, 0) <<
+ // ": from " << sqlite3_column_int64 (stmt, 1) <<
+ // " to " << sqlite3_column_int64 (stmt, 2) <<
+ // std::endl;
}
- sqlite3_finalize (stmt);
+ sqlite3_finalize (stmt);
+
+ return msg;
}
diff --git a/src/sync-log.h b/src/sync-log.h
index a597888..5705e45 100644
--- a/src/sync-log.h
+++ b/src/sync-log.h
@@ -23,6 +23,9 @@
#define SYNC_LOG_H
#include "db-helper.h"
+#include <sync-state.pb.h>
+
+typedef boost::shared_ptr<SyncStateMsg> SyncStateMsgPtr;
class SyncLog : public DbHelper
{
@@ -58,10 +61,10 @@
LookupSyncLog (const Hash &stateHash);
// How difference is exposed will be determined later by the actual protocol
- void
+ SyncStateMsgPtr
FindStateDifferences (const std::string &oldHash, const std::string &newHash);
- void
+ SyncStateMsgPtr
FindStateDifferences (const Hash &oldHash, const Hash &newHash);
};
diff --git a/src/sync-state.proto b/src/sync-state.proto
new file mode 100644
index 0000000..9ef5e33
--- /dev/null
+++ b/src/sync-state.proto
@@ -0,0 +1,24 @@
+// message Name
+// {
+// repeated bytes comp = 1;
+// }
+
+message SyncState
+{
+ // required Name name = 1;
+ required string name = 1;
+
+ enum ActionType
+ {
+ UPDATE = 0;
+ DELETE = 1;
+ }
+ required ActionType type = 2;
+
+ optional uint64 seq = 3;
+}
+
+message SyncStateMsg
+{
+ repeated SyncState state = 1;
+}
diff --git a/waf b/waf
index 69fb819..a6859ac 100755
--- a/waf
+++ b/waf
Binary files differ
diff --git a/wscript b/wscript
index b37b9f4..7ca0fbd 100644
--- a/wscript
+++ b/wscript
@@ -11,8 +11,7 @@
opt.add_option('--test', action='store_true',default=False,dest='_test',help='''build unit tests''')
opt.add_option('--yes',action='store_true',default=False) # for autoconf/automake/make compatibility
- opt.load('compiler_cxx boost ccnx protoc')
- opt.load('ice_cxx', tooldir=["."])
+ opt.load('compiler_cxx boost ccnx protoc ice_cxx')
def configure(conf):
conf.load("compiler_cxx")
@@ -110,6 +109,7 @@
'src/db-helper.cc',
'src/sync-log.cc',
'src/action-log.cc',
+ 'src/sync-state.proto',
],
use = "BOOST CCNX SSL SQLITE3 ICE common",
includes = ['include', 'src'],