blob: fad4017df40dc26d7e152ba391c3e745c97fce09 [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 Afanasyev242f8772013-01-01 23:26:31 -080022#include "db-helper.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 Afanasyevae43c502012-12-29 17:26:37 -080028
29using namespace std;
30using namespace boost;
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080031using namespace ChronoshareClient;
Alexander Afanasyevae43c502012-12-29 17:26:37 -080032
33typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str;
34
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080035class MyService : public Ice::Service
36{
37protected:
38 virtual bool start (int, char*[], int&)
39 {
40 _adapter = communicator ()->createObjectAdapterWithEndpoints ("ChronoShare", "default -p 55436");
41
42 Ice::Identity identity;
43 identity.name="NotifyDaemon";
44 NotifyPtr servant=new NotifyI;
45
46 _adapter->add (servant, identity);
47
48 _adapter->activate();
49 // status = EXIT_SUCCESS;
50 return true;
51 }
52
53private:
54 Ice::ObjectAdapterPtr _adapter;
55};
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080056
57int
58main (int argc, char **argv)
59{
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080060 int status = 0;
61
Alexander Afanasyevae43c502012-12-29 17:26:37 -080062 try
63 {
64 DbHelper db ("./");
65
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080066 MyService svc;
67 status = svc.main (argc, argv);
Alexander Afanasyevae43c502012-12-29 17:26:37 -080068
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080069 // HashPtr hash = db.RememberStateInStateLog ();
70 // // should be empty
71 // cout << "Hash: [" << *hash << "]" << endl;
Alexander Afanasyevae43c502012-12-29 17:26:37 -080072
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080073 // //
74 // db.UpdateDeviceSeqno ("Alex", 1);
75 // hash = db.RememberStateInStateLog ();
76 // cout << "Hash: [" << *hash << "]" << endl;
Alexander Afanasyevae43c502012-12-29 17:26:37 -080077
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080078 // db.UpdateDeviceSeqno ("Alex", 2);
79 // hash = db.RememberStateInStateLog ();
80 // cout << "Hash: [" << *hash << "]" << endl;
Alexander Afanasyevae43c502012-12-29 17:26:37 -080081
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080082 // db.UpdateDeviceSeqno ("Alex", 2);
83 // hash = db.RememberStateInStateLog ();
84 // cout << "Hash: [" << *hash << "]" << endl;
Alexander Afanasyevae43c502012-12-29 17:26:37 -080085
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080086 // 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.FindStateDifferences ("00", "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52");
91 // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52", "00");
92 // db.FindStateDifferences ("869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce",
93 // "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52");
94 // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52",
95 // "869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce");
Alexander Afanasyevae43c502012-12-29 17:26:37 -080096
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -080097 // db.UpdateDeviceSeqno ("Bob", 1);
98 // hash = db.RememberStateInStateLog ();
99 // cout << "Hash: [" << *hash << "]" << endl;
100
101 // db.FindStateDifferences ("00", "48f4d95b503b9a79c2d5939fa67722b13fc01db861fc501d09efd0a38dbafab8");
102 // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52",
103 // "48f4d95b503b9a79c2d5939fa67722b13fc01db861fc501d09efd0a38dbafab8");
104 }
105 catch (const Ice::Exception& e)
106 {
107 cerr << e << endl;
108 status = 1;
Alexander Afanasyevae43c502012-12-29 17:26:37 -0800109 }
110 catch (const boost::exception &e)
111 {
112 cout << "ERRORR: " << *get_error_info<errmsg_info_str> (e) << endl;
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -0800113 status = 1;
Alexander Afanasyevae43c502012-12-29 17:26:37 -0800114 }
115
Alexander Afanasyev5e9e46e2013-01-02 14:12:50 -0800116 return status;
Alexander Afanasyev71b43e72012-12-27 01:03:43 -0800117}