blob: ae41418cf490b5836c510e53a496e7b3c252f59b [file] [log] [blame]
Alexander Afanasyev71b43e72012-12-27 01:03:43 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
Alexander Afanasyev8811b352013-01-02 12:51:15 -080018 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Zhenkai Zhu <zhenkai@cs.ucla.edu>
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080020 */
21
Alexander Afanasyeva199f972013-01-02 19:37:26 -080022#include "action-log.h"
Alexander Afanasyevae43c502012-12-29 17:26:37 -080023#include <iostream>
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080024#include <Ice/Service.h>
25#include <Ice/Identity.h>
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -080026#include <ccnx-wrapper.h>
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080027
28#include "notify-i.h"
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080029#include <boost/make_shared.hpp>
Alexander Afanasyevae43c502012-12-29 17:26:37 -080030
31using namespace std;
32using namespace boost;
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080033using namespace ChronoshareClient;
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -080034using namespace Ccnx;
Alexander Afanasyevae43c502012-12-29 17:26:37 -080035
36typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str;
37
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080038class MyService : public Ice::Service
39{
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080040public:
41 MyService (ActionLogPtr actionLog)
42 : m_actionLog (actionLog)
43 {
44 }
45
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080046protected:
47 virtual bool start (int, char*[], int&)
48 {
49 _adapter = communicator ()->createObjectAdapterWithEndpoints ("ChronoShare", "default -p 55436");
50
51 Ice::Identity identity;
52 identity.name="NotifyDaemon";
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080053 NotifyPtr servant=new NotifyI (m_actionLog);
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080054
55 _adapter->add (servant, identity);
56
57 _adapter->activate();
58 // status = EXIT_SUCCESS;
59 return true;
60 }
61
62private:
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080063 Ice::ObjectAdapterPtr _adapter;
64 ActionLogPtr m_actionLog;
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080065};
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080066
67int
68main (int argc, char **argv)
69{
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080070 int status = 0;
71
Alexander Afanasyevae43c502012-12-29 17:26:37 -080072 try
73 {
Alexander Afanasyeva199f972013-01-02 19:37:26 -080074 // DbHelper db ("./", "/ndn/ucla.edu/alex");
Alexander Afanasyevc9eb68f2013-01-07 13:40:00 -080075 CcnxWrapperPtr ccnx = make_shared<CcnxWrapper> ();
76 ActionLogPtr actionLog = make_shared<ActionLog> (ccnx, "./", "/ndn/ucla.edu/alex", "shared");
Alexander Afanasyevae43c502012-12-29 17:26:37 -080077
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080078 MyService svc (actionLog);
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080079 status = svc.main (argc, argv);
Alexander Afanasyevae43c502012-12-29 17:26:37 -080080
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080081 // HashPtr hash = db.RememberStateInStateLog ();
82 // // should be empty
83 // cout << "Hash: [" << *hash << "]" << endl;
Alexander Afanasyevae43c502012-12-29 17:26:37 -080084
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080085 // //
86 // db.UpdateDeviceSeqno ("Alex", 1);
87 // hash = db.RememberStateInStateLog ();
88 // cout << "Hash: [" << *hash << "]" << endl;
Alexander Afanasyevae43c502012-12-29 17:26:37 -080089
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080090 // db.UpdateDeviceSeqno ("Alex", 2);
91 // hash = db.RememberStateInStateLog ();
92 // cout << "Hash: [" << *hash << "]" << endl;
Alexander Afanasyevae43c502012-12-29 17:26:37 -080093
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080094 // db.UpdateDeviceSeqno ("Alex", 2);
95 // hash = db.RememberStateInStateLog ();
96 // cout << "Hash: [" << *hash << "]" << endl;
Alexander Afanasyevae43c502012-12-29 17:26:37 -080097
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080098 // db.UpdateDeviceSeqno ("Alex", 1);
99 // hash = db.RememberStateInStateLog ();
100 // cout << "Hash: [" << *hash << "]" << endl;
Alexander Afanasyevae43c502012-12-29 17:26:37 -0800101
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -0800102 // db.FindStateDifferences ("00", "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52");
103 // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52", "00");
104 // db.FindStateDifferences ("869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce",
105 // "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52");
106 // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52",
107 // "869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce");
Alexander Afanasyevae43c502012-12-29 17:26:37 -0800108
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -0800109 // db.UpdateDeviceSeqno ("Bob", 1);
110 // hash = db.RememberStateInStateLog ();
111 // cout << "Hash: [" << *hash << "]" << endl;
112
113 // db.FindStateDifferences ("00", "48f4d95b503b9a79c2d5939fa67722b13fc01db861fc501d09efd0a38dbafab8");
114 // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52",
115 // "48f4d95b503b9a79c2d5939fa67722b13fc01db861fc501d09efd0a38dbafab8");
116 }
117 catch (const Ice::Exception& e)
118 {
119 cerr << e << endl;
120 status = 1;
Alexander Afanasyevae43c502012-12-29 17:26:37 -0800121 }
122 catch (const boost::exception &e)
123 {
124 cout << "ERRORR: " << *get_error_info<errmsg_info_str> (e) << endl;
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -0800125 status = 1;
Alexander Afanasyevae43c502012-12-29 17:26:37 -0800126 }
127
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -0800128 return status;
Alexander Afanasyev71b43e72012-12-27 01:03:43 -0800129}