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