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 | 242f877 | 2013-01-01 23:26:31 -0800 | [diff] [blame] | 22 | #include "db-helper.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 | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 28 | |
| 29 | using namespace std; |
| 30 | using namespace boost; |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame^] | 31 | using namespace ChronoshareClient; |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 32 | |
| 33 | typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str; |
| 34 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame^] | 35 | class MyService : public Ice::Service |
| 36 | { |
| 37 | protected: |
| 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 | |
| 53 | private: |
| 54 | Ice::ObjectAdapterPtr _adapter; |
| 55 | }; |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 56 | |
| 57 | int |
| 58 | main (int argc, char **argv) |
| 59 | { |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame^] | 60 | int status = 0; |
| 61 | |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 62 | try |
| 63 | { |
| 64 | DbHelper db ("./"); |
| 65 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame^] | 66 | MyService svc; |
| 67 | status = svc.main (argc, argv); |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 68 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame^] | 69 | // HashPtr hash = db.RememberStateInStateLog (); |
| 70 | // // should be empty |
| 71 | // cout << "Hash: [" << *hash << "]" << endl; |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 72 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame^] | 73 | // // |
| 74 | // db.UpdateDeviceSeqno ("Alex", 1); |
| 75 | // hash = db.RememberStateInStateLog (); |
| 76 | // cout << "Hash: [" << *hash << "]" << endl; |
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 | // db.UpdateDeviceSeqno ("Alex", 2); |
| 79 | // hash = db.RememberStateInStateLog (); |
| 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 | // db.UpdateDeviceSeqno ("Alex", 2); |
| 83 | // hash = db.RememberStateInStateLog (); |
| 84 | // cout << "Hash: [" << *hash << "]" << endl; |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 85 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame^] | 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.FindStateDifferences ("00", "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52"); |
| 91 | // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52", "00"); |
| 92 | // db.FindStateDifferences ("869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce", |
| 93 | // "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52"); |
| 94 | // db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52", |
| 95 | // "869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce"); |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 96 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame^] | 97 | // 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 Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 109 | } |
| 110 | catch (const boost::exception &e) |
| 111 | { |
| 112 | cout << "ERRORR: " << *get_error_info<errmsg_info_str> (e) << endl; |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame^] | 113 | status = 1; |
Alexander Afanasyev | ae43c50 | 2012-12-29 17:26:37 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame^] | 116 | return status; |
Alexander Afanasyev | 71b43e7 | 2012-12-27 01:03:43 -0800 | [diff] [blame] | 117 | } |