Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * D-Bus++ - C++ bindings for D-Bus |
| 4 | * |
| 5 | * Copyright (C) 2005-2007 Paolo Durante <shackan@gmail.com> |
| 6 | * |
| 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2.1 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public |
| 19 | * License along with this library; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <cstring> |
| 25 | #include <signal.h> |
| 26 | #include <unistd.h> |
| 27 | #include <iostream> |
| 28 | #include "introspect.h" |
| 29 | |
| 30 | DBus::BusDispatcher dispatcher; |
| 31 | static bool systembus; |
| 32 | static char *path; |
| 33 | static char *service; |
| 34 | |
| 35 | void niam(int sig) |
| 36 | { |
| 37 | DBus::Connection conn = systembus ? DBus::Connection::SystemBus() : DBus::Connection::SessionBus(); |
| 38 | |
| 39 | IntrospectedObject io(conn, path, service); |
| 40 | |
| 41 | std::cout << io.Introspect(); |
| 42 | |
| 43 | dispatcher.leave(); |
| 44 | } |
| 45 | |
| 46 | int main(int argc, char **argv) |
| 47 | { |
| 48 | signal(SIGTERM, niam); |
| 49 | signal(SIGINT, niam); |
| 50 | signal(SIGALRM, niam); |
| 51 | |
| 52 | if (argc == 1) |
| 53 | { |
| 54 | std::cerr << std::endl << "Usage: " << argv[0] << " [--system] <object_path> [<destination>]" << std::endl << std::endl; |
| 55 | } |
| 56 | else |
| 57 | { |
| 58 | if (strcmp(argv[1], "--system")) |
| 59 | { |
| 60 | systembus = false; |
| 61 | path = argv[1]; |
| 62 | service = argc > 2 ? argv[2] : 0; |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | systembus = true; |
| 67 | path = argv[2]; |
| 68 | service = argc > 3 ? argv[3] : 0; |
| 69 | } |
| 70 | |
| 71 | DBus::default_dispatcher = &dispatcher; |
| 72 | |
| 73 | alarm(1); |
| 74 | |
| 75 | dispatcher.enter(); |
| 76 | } |
| 77 | |
| 78 | return 0; |
| 79 | } |