Now there is a simplest form of IPC using zeroc ice. More stuff is coming.
diff --git a/client/client.cc b/client/client.cc
index 746de70..22a0147 100644
--- a/client/client.cc
+++ b/client/client.cc
@@ -22,9 +22,12 @@
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <config.h>
+#include <Ice/Ice.h>
+#include <chronoshare-client.ice.h>
using namespace std;
using namespace boost;
+using namespace ChronoshareClient;
void
usage ()
@@ -76,6 +79,40 @@
usage ();
}
}
+
+
+ int status = 0;
+ Ice::CommunicatorPtr ic;
+ try
+ {
+ // Create a communicator
+ //
+ ic = Ice::initialize (argc, argv);
+
+ Ice::ObjectPrx base = ic->stringToProxy("NotifyDaemon:default -p 55436");
+ if (!base)
+ {
+ throw "Could not create proxy";
+ }
+
+ NotifyPrx notify = NotifyPrx::checkedCast (base);
+ if (notify)
+ {
+ notify->deleteFile ("bla");
+ }
+ else
+ {
+ cerr << "Cannot connect to the daemon\n";
+ status = 1;
+ }
+ }
+ catch (const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ status = 1;
+ }
- return 0;
+ if (ic)
+ ic->destroy();
+ return status;
}
diff --git a/daemon/daemon.cc b/daemon/daemon.cc
index ba1fecc..fad4017 100644
--- a/daemon/daemon.cc
+++ b/daemon/daemon.cc
@@ -21,60 +21,97 @@
#include "db-helper.h"
#include <iostream>
+#include <Ice/Service.h>
+#include <Ice/Identity.h>
+
+#include "notify-i.h"
using namespace std;
using namespace boost;
+using namespace ChronoshareClient;
typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str;
+class MyService : public Ice::Service
+{
+protected:
+ virtual bool start (int, char*[], int&)
+ {
+ _adapter = communicator ()->createObjectAdapterWithEndpoints ("ChronoShare", "default -p 55436");
+
+ Ice::Identity identity;
+ identity.name="NotifyDaemon";
+ NotifyPtr servant=new NotifyI;
+
+ _adapter->add (servant, identity);
+
+ _adapter->activate();
+ // status = EXIT_SUCCESS;
+ return true;
+ }
+
+private:
+ Ice::ObjectAdapterPtr _adapter;
+};
int
main (int argc, char **argv)
{
+ int status = 0;
+
try
{
DbHelper db ("./");
- HashPtr hash = db.RememberStateInStateLog ();
- // should be empty
- cout << "Hash: [" << *hash << "]" << endl;
+ MyService svc;
+ status = svc.main (argc, argv);
- //
- db.UpdateDeviceSeqno ("Alex", 1);
- hash = db.RememberStateInStateLog ();
- cout << "Hash: [" << *hash << "]" << endl;
+ // HashPtr hash = db.RememberStateInStateLog ();
+ // // should be empty
+ // cout << "Hash: [" << *hash << "]" << endl;
- db.UpdateDeviceSeqno ("Alex", 2);
- hash = db.RememberStateInStateLog ();
- cout << "Hash: [" << *hash << "]" << endl;
+ // //
+ // db.UpdateDeviceSeqno ("Alex", 1);
+ // hash = db.RememberStateInStateLog ();
+ // cout << "Hash: [" << *hash << "]" << endl;
- db.UpdateDeviceSeqno ("Alex", 2);
- hash = db.RememberStateInStateLog ();
- cout << "Hash: [" << *hash << "]" << endl;
+ // db.UpdateDeviceSeqno ("Alex", 2);
+ // hash = db.RememberStateInStateLog ();
+ // cout << "Hash: [" << *hash << "]" << endl;
- db.UpdateDeviceSeqno ("Alex", 1);
- hash = db.RememberStateInStateLog ();
- cout << "Hash: [" << *hash << "]" << endl;
+ // db.UpdateDeviceSeqno ("Alex", 2);
+ // hash = db.RememberStateInStateLog ();
+ // cout << "Hash: [" << *hash << "]" << endl;
- db.FindStateDifferences ("00", "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52");
- db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52", "00");
- db.FindStateDifferences ("869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce",
- "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52");
- db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52",
- "869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce");
+ // db.UpdateDeviceSeqno ("Alex", 1);
+ // hash = db.RememberStateInStateLog ();
+ // cout << "Hash: [" << *hash << "]" << endl;
- db.UpdateDeviceSeqno ("Bob", 1);
- hash = db.RememberStateInStateLog ();
- cout << "Hash: [" << *hash << "]" << endl;
+ // db.FindStateDifferences ("00", "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52");
+ // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52", "00");
+ // db.FindStateDifferences ("869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce",
+ // "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52");
+ // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52",
+ // "869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce");
- db.FindStateDifferences ("00", "48f4d95b503b9a79c2d5939fa67722b13fc01db861fc501d09efd0a38dbafab8");
- db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52",
- "48f4d95b503b9a79c2d5939fa67722b13fc01db861fc501d09efd0a38dbafab8");
+ // db.UpdateDeviceSeqno ("Bob", 1);
+ // hash = db.RememberStateInStateLog ();
+ // cout << "Hash: [" << *hash << "]" << endl;
+
+ // db.FindStateDifferences ("00", "48f4d95b503b9a79c2d5939fa67722b13fc01db861fc501d09efd0a38dbafab8");
+ // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52",
+ // "48f4d95b503b9a79c2d5939fa67722b13fc01db861fc501d09efd0a38dbafab8");
+ }
+ catch (const Ice::Exception& e)
+ {
+ cerr << e << endl;
+ status = 1;
}
catch (const boost::exception &e)
{
cout << "ERRORR: " << *get_error_info<errmsg_info_str> (e) << endl;
+ status = 1;
}
- return 0;
+ return status;
}
diff --git a/daemon/notify-i.cc b/daemon/notify-i.cc
new file mode 100644
index 0000000..48ac56c
--- /dev/null
+++ b/daemon/notify-i.cc
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ */
+
+#include "notify-i.h"
+
+using namespace std;
+
+void
+NotifyI::updateFile (const ::std::string &filename,
+ const ::ChronoshareClient::HashBytes &hash,
+ const ::std::string &atime,
+ const ::std::string &mtime,
+ const ::std::string &ctime,
+ ::Ice::Int mode,
+ const ::Ice::Current&)
+{
+ cout << "updateFile " << filename << endl;
+}
+
+
+void
+NotifyI::deleteFile (const ::std::string &filename,
+ const ::Ice::Current&)
+{
+ cout << "deleteFile " << filename << endl;
+}
+
diff --git a/daemon/notify-i.h b/daemon/notify-i.h
new file mode 100644
index 0000000..7afb0dd
--- /dev/null
+++ b/daemon/notify-i.h
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ */
+
+#ifndef NOTIFY_I_H
+#define NOTIFY_I_H
+
+#include <chronoshare-client.ice.h>
+
+class NotifyI : public ChronoshareClient::Notify
+{
+public:
+ virtual void
+ updateFile (const ::std::string &filename,
+ const ::ChronoshareClient::HashBytes &hash,
+ const ::std::string &atime,
+ const ::std::string &mtime,
+ const ::std::string &ctime,
+ ::Ice::Int mode,
+ const ::Ice::Current& = ::Ice::Current());
+
+ virtual void
+ deleteFile (const ::std::string &filename,
+ const ::Ice::Current& = ::Ice::Current());
+
+};
+
+#endif // NOTIFY_I_H
diff --git a/wscript b/wscript
index 2c0f727..af3befd 100644
--- a/wscript
+++ b/wscript
@@ -85,7 +85,7 @@
target = "common",
features = ["cxx"],
source = bld.path.ant_glob(
- 'src/chronoshare-client.ice'
+ 'src/chronoshare-client.ice'
),
use = 'BOOST',
includes = ['include', 'src'],
@@ -95,7 +95,7 @@
client = bld (
target="cs-client",
features=['cxx', 'cxxprogram'],
- source = ['client/client.cc',
+ source = ['client/client.cc',
],
use = "BOOST CCNX SSL ICE common",
includes = ['include', 'src'],
@@ -105,7 +105,8 @@
target="cs-daemon",
features=['cxx', 'cxxprogram'],
# source = bld.path.ant_glob(['src/**/*.cc']),
- source = ['daemon/daemon.cc',
+ source = ['daemon/daemon.cc',
+ 'daemon/notify-i.cc',
'src/db-helper.cc',
'src/hash-string-converter.cc',
],