Alexander Afanasyev | f289063 | 2013-01-02 13:40:02 -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 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | * Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 20 | */ |
| 21 | |
| 22 | #include <iostream> |
| 23 | #include <boost/algorithm/string.hpp> |
| 24 | #include <config.h> |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame^] | 25 | #include <Ice/Ice.h> |
| 26 | #include <chronoshare-client.ice.h> |
Alexander Afanasyev | f289063 | 2013-01-02 13:40:02 -0800 | [diff] [blame] | 27 | |
| 28 | using namespace std; |
| 29 | using namespace boost; |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame^] | 30 | using namespace ChronoshareClient; |
Alexander Afanasyev | f289063 | 2013-01-02 13:40:02 -0800 | [diff] [blame] | 31 | |
| 32 | void |
| 33 | usage () |
| 34 | { |
| 35 | cerr << "Usage: chronoshare <cmd> [<options>]\n" |
| 36 | << "\n" |
| 37 | << " <cmd> is one of:\n" |
| 38 | << " version\n" |
| 39 | << " update <filename>\n" |
| 40 | << " delete <filename>\n" |
| 41 | << " move <filename> <filename>\n"; |
| 42 | exit (1); |
| 43 | } |
| 44 | |
| 45 | int |
| 46 | main (int argc, char **argv) |
| 47 | { |
| 48 | if (argc < 2) |
| 49 | { |
| 50 | usage (); |
| 51 | } |
| 52 | |
| 53 | string cmd = argv[1]; |
| 54 | algorithm::to_lower (cmd); |
| 55 | |
| 56 | if (cmd == "version") |
| 57 | { |
| 58 | cout << "chronoshare version " << CHRONOSHARE_VERSION << endl; |
| 59 | exit (0); |
| 60 | } |
| 61 | else if (cmd == "update") |
| 62 | { |
| 63 | if (argc != 3) |
| 64 | { |
| 65 | usage (); |
| 66 | } |
| 67 | } |
| 68 | else if (cmd == "delete") |
| 69 | { |
| 70 | if (argc != 3) |
| 71 | { |
| 72 | usage (); |
| 73 | } |
| 74 | } |
| 75 | else if (cmd == "move") |
| 76 | { |
| 77 | if (argc != 4) |
| 78 | { |
| 79 | usage (); |
| 80 | } |
| 81 | } |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame^] | 82 | |
| 83 | |
| 84 | int status = 0; |
| 85 | Ice::CommunicatorPtr ic; |
| 86 | try |
| 87 | { |
| 88 | // Create a communicator |
| 89 | // |
| 90 | ic = Ice::initialize (argc, argv); |
| 91 | |
| 92 | Ice::ObjectPrx base = ic->stringToProxy("NotifyDaemon:default -p 55436"); |
| 93 | if (!base) |
| 94 | { |
| 95 | throw "Could not create proxy"; |
| 96 | } |
| 97 | |
| 98 | NotifyPrx notify = NotifyPrx::checkedCast (base); |
| 99 | if (notify) |
| 100 | { |
| 101 | notify->deleteFile ("bla"); |
| 102 | } |
| 103 | else |
| 104 | { |
| 105 | cerr << "Cannot connect to the daemon\n"; |
| 106 | status = 1; |
| 107 | } |
| 108 | } |
| 109 | catch (const Ice::Exception& ex) |
| 110 | { |
| 111 | cerr << ex << endl; |
| 112 | status = 1; |
| 113 | } |
Alexander Afanasyev | f289063 | 2013-01-02 13:40:02 -0800 | [diff] [blame] | 114 | |
Alexander Afanasyev | 5e9e46e | 2013-01-02 14:12:50 -0800 | [diff] [blame^] | 115 | if (ic) |
| 116 | ic->destroy(); |
| 117 | return status; |
Alexander Afanasyev | f289063 | 2013-01-02 13:40:02 -0800 | [diff] [blame] | 118 | } |