blob: 5b953d3c7574c76b3c737d7671c05c0bc7d54b86 [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>
26
27#include "notify-i.h"
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080028#include <boost/make_shared.hpp>
Alexander Afanasyevae43c502012-12-29 17:26:37 -080029
30using namespace std;
31using namespace boost;
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080032using namespace ChronoshareClient;
Alexander Afanasyevae43c502012-12-29 17:26:37 -080033
34typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str;
35
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080036class MyService : public Ice::Service
37{
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080038public:
39 MyService (ActionLogPtr actionLog)
40 : m_actionLog (actionLog)
41 {
42 }
43
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080044protected:
45 virtual bool start (int, char*[], int&)
46 {
47 _adapter = communicator ()->createObjectAdapterWithEndpoints ("ChronoShare", "default -p 55436");
48
49 Ice::Identity identity;
50 identity.name="NotifyDaemon";
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080051 NotifyPtr servant=new NotifyI (m_actionLog);
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080052
53 _adapter->add (servant, identity);
54
55 _adapter->activate();
56 // status = EXIT_SUCCESS;
57 return true;
58 }
59
60private:
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080061 Ice::ObjectAdapterPtr _adapter;
62 ActionLogPtr m_actionLog;
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080063};
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080064
65int
66main (int argc, char **argv)
67{
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080068 int status = 0;
69
Alexander Afanasyevae43c502012-12-29 17:26:37 -080070 try
71 {
Alexander Afanasyeva199f972013-01-02 19:37:26 -080072 // DbHelper db ("./", "/ndn/ucla.edu/alex");
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080073 ActionLogPtr actionLog = make_shared<ActionLog> ("./", "/ndn/ucla.edu/alex");
Alexander Afanasyevae43c502012-12-29 17:26:37 -080074
Alexander Afanasyevb6bc01a2013-01-02 23:34:20 -080075 MyService svc (actionLog);
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080076 status = svc.main (argc, argv);
Alexander Afanasyevae43c502012-12-29 17:26:37 -080077
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080078 // HashPtr hash = db.RememberStateInStateLog ();
79 // // should be empty
80 // cout << "Hash: [" << *hash << "]" << endl;
Alexander Afanasyevae43c502012-12-29 17:26:37 -080081
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080082 // //
83 // db.UpdateDeviceSeqno ("Alex", 1);
84 // hash = db.RememberStateInStateLog ();
85 // cout << "Hash: [" << *hash << "]" << endl;
Alexander Afanasyevae43c502012-12-29 17:26:37 -080086
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080087 // db.UpdateDeviceSeqno ("Alex", 2);
88 // hash = db.RememberStateInStateLog ();
89 // cout << "Hash: [" << *hash << "]" << endl;
Alexander Afanasyevae43c502012-12-29 17:26:37 -080090
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080091 // db.UpdateDeviceSeqno ("Alex", 2);
92 // hash = db.RememberStateInStateLog ();
93 // cout << "Hash: [" << *hash << "]" << endl;
Alexander Afanasyevae43c502012-12-29 17:26:37 -080094
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080095 // db.UpdateDeviceSeqno ("Alex", 1);
96 // hash = db.RememberStateInStateLog ();
97 // cout << "Hash: [" << *hash << "]" << endl;
Alexander Afanasyevae43c502012-12-29 17:26:37 -080098
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080099 // db.FindStateDifferences ("00", "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52");
100 // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52", "00");
101 // db.FindStateDifferences ("869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce",
102 // "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52");
103 // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52",
104 // "869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce");
Alexander Afanasyevae43c502012-12-29 17:26:37 -0800105
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -0800106 // db.UpdateDeviceSeqno ("Bob", 1);
107 // hash = db.RememberStateInStateLog ();
108 // cout << "Hash: [" << *hash << "]" << endl;
109
110 // db.FindStateDifferences ("00", "48f4d95b503b9a79c2d5939fa67722b13fc01db861fc501d09efd0a38dbafab8");
111 // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52",
112 // "48f4d95b503b9a79c2d5939fa67722b13fc01db861fc501d09efd0a38dbafab8");
113 }
114 catch (const Ice::Exception& e)
115 {
116 cerr << e << endl;
117 status = 1;
Alexander Afanasyevae43c502012-12-29 17:26:37 -0800118 }
119 catch (const boost::exception &e)
120 {
121 cout << "ERRORR: " << *get_error_info<errmsg_info_str> (e) << endl;
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -0800122 status = 1;
Alexander Afanasyevae43c502012-12-29 17:26:37 -0800123 }
124
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -0800125 return status;
Alexander Afanasyev71b43e72012-12-27 01:03:43 -0800126}