blob: ff031f80b05bc47b86ad66c6ccbbcc11c9cff041 [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001/*
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 <cstdlib>
25#include <cstring>
26#include <string>
27#include <map>
28#include <iostream>
29#include <fstream>
30#include <sstream>
31
32#include "xml2cpp.h"
33#include "generate_adaptor.h"
34#include "generate_proxy.h"
35
36using namespace std;
37using namespace DBus;
38
39//typedef map<string,string> TypeCache;
40
41void usage(const char *argv0)
42{
43 cerr << endl << "Usage: " << argv0 << " <xmlfile> [ --proxy=<outfile.h> ] [ --adaptor=<outfile.h> ]"
44 << endl << endl;
45 exit(-1);
46}
47
48/*int char_to_atomic_type(char t)
49{
50 if (strchr("ybnqiuxtdsgavre", t))
51 return t;
52
53 return DBUS_TYPE_INVALID;
54}*/
55
56
57
58/*bool is_atomic_type(const string &type)
59{
60 return type.length() == 1 && char_to_atomic_type(type[0]) != DBUS_TYPE_INVALID;
61}*/
62
63
64int main(int argc, char **argv)
65{
66 if (argc < 2)
67 {
68 usage(argv[0]);
69 }
70
71 bool proxy_mode, adaptor_mode;
72 char *proxy, *adaptor;
73
74 proxy_mode = false;
75 proxy = 0;
76
77 adaptor_mode = false;
78 adaptor = 0;
79
80 for (int a = 1; a < argc; ++a)
81 {
82 if (!strncmp(argv[a], "--proxy=", 8))
83 {
84 proxy_mode = true;
85 proxy = argv[a] + 8;
86 }
87 else if (!strncmp(argv[a], "--adaptor=", 10))
88 {
89 adaptor_mode = true;
90 adaptor = argv[a] + 10;
91 }
92 }
93
94 if (!proxy_mode && !adaptor_mode) usage(argv[0]);
95
96 ifstream xmlfile(argv[1]);
97
98 if (xmlfile.bad())
99 {
100 cerr << "unable to open file " << argv[1] << endl;
101 return -1;
102 }
103
104 Xml::Document doc;
105
106 try
107 {
108 xmlfile >> doc;
109 //cout << doc.to_xml();
110 }
111 catch (Xml::Error &e)
112 {
113 cerr << "error parsing " << argv[1] << ": " << e.what() << endl;
114 return -1;
115 }
116
117 if (!doc.root)
118 {
119 cerr << "empty document" << endl;
120 return -1;
121 }
122
123 if (proxy_mode) generate_proxy(doc, proxy);
124 if (adaptor_mode) generate_adaptor(doc, adaptor);
125
126 return 0;
127}