Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 8811b35 | 2013-01-02 12:51:15 -0800 | [diff] [blame] | 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | * Zhenkai Zhu <zhenkai@cs.ucla.edu> |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | a199f97 | 2013-01-02 19:37:26 -0800 | [diff] [blame] | 22 | #include "action-log.h" |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 23 | #include <iostream> |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 24 | #include <Ice/Service.h> |
| 25 | #include <Ice/Identity.h> |
| 26 | |
| 27 | #include "notify-i.h" |
Alexander Afanasyev | b6bc01a | 2013-01-02 23:34:20 -0800 | [diff] [blame] | 28 | #include <boost/make_shared.hpp> |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 29 | |
| 30 | using namespace std; |
| 31 | using namespace boost; |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 32 | using namespace ChronoshareClient; |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 33 | |
| 34 | typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str; |
| 35 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 36 | class MyService : public Ice::Service |
| 37 | { |
Alexander Afanasyev | b6bc01a | 2013-01-02 23:34:20 -0800 | [diff] [blame] | 38 | public: |
| 39 | MyService (ActionLogPtr actionLog) |
| 40 | : m_actionLog (actionLog) |
| 41 | { |
| 42 | } |
| 43 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 44 | protected: |
| 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 Afanasyev | b6bc01a | 2013-01-02 23:34:20 -0800 | [diff] [blame] | 51 | NotifyPtr servant=new NotifyI (m_actionLog); |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 52 | |
| 53 | _adapter->add (servant, identity); |
| 54 | |
| 55 | _adapter->activate(); |
| 56 | // status = EXIT_SUCCESS; |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | private: |
Alexander Afanasyev | b6bc01a | 2013-01-02 23:34:20 -0800 | [diff] [blame] | 61 | Ice::ObjectAdapterPtr _adapter; |
| 62 | ActionLogPtr m_actionLog; |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 63 | }; |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 64 | |
| 65 | int |
| 66 | main (int argc, char **argv) |
| 67 | { |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 68 | int status = 0; |
| 69 | |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 70 | try |
| 71 | { |
Alexander Afanasyev | a199f97 | 2013-01-02 19:37:26 -0800 | [diff] [blame] | 72 | // DbHelper db ("./", "/ndn/ucla.edu/alex"); |
Alexander Afanasyev | b6bc01a | 2013-01-02 23:34:20 -0800 | [diff] [blame] | 73 | ActionLogPtr actionLog = make_shared<ActionLog> ("./", "/ndn/ucla.edu/alex"); |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 74 | |
Alexander Afanasyev | b6bc01a | 2013-01-02 23:34:20 -0800 | [diff] [blame] | 75 | MyService svc (actionLog); |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 76 | status = svc.main (argc, argv); |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 77 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 78 | // HashPtr hash = db.RememberStateInStateLog (); |
| 79 | // // should be empty |
| 80 | // cout << "Hash: [" << *hash << "]" << endl; |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 81 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 82 | // // |
| 83 | // db.UpdateDeviceSeqno ("Alex", 1); |
| 84 | // hash = db.RememberStateInStateLog (); |
| 85 | // cout << "Hash: [" << *hash << "]" << endl; |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 86 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 87 | // db.UpdateDeviceSeqno ("Alex", 2); |
| 88 | // hash = db.RememberStateInStateLog (); |
| 89 | // cout << "Hash: [" << *hash << "]" << endl; |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 90 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 91 | // db.UpdateDeviceSeqno ("Alex", 2); |
| 92 | // hash = db.RememberStateInStateLog (); |
| 93 | // cout << "Hash: [" << *hash << "]" << endl; |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 94 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 95 | // db.UpdateDeviceSeqno ("Alex", 1); |
| 96 | // hash = db.RememberStateInStateLog (); |
| 97 | // cout << "Hash: [" << *hash << "]" << endl; |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 98 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 99 | // db.FindStateDifferences ("00", "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52"); |
| 100 | // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52", "00"); |
| 101 | // db.FindStateDifferences ("869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce", |
| 102 | // "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52"); |
| 103 | // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52", |
| 104 | // "869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce"); |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 105 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 106 | // 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 Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 118 | } |
| 119 | catch (const boost::exception &e) |
| 120 | { |
| 121 | cout << "ERRORR: " << *get_error_info<errmsg_info_str> (e) << endl; |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 122 | status = 1; |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 123 | } |
| 124 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame] | 125 | return status; |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 126 | } |