summaryrefslogtreecommitdiff
path: root/src/bin/eldbus/client.c
blob: c82ee3c8eb140a7ea0646820da39c2db71808fcd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "codegen.h"

static const Ecore_Getopt optdesc = {
  "eldbus_codegen",
  "%prog [options] <file.xml>",
  "1.0",
  "(C) 2012 - The Enlightenment Project",
  "BSD",
  "Generate DBUS code, making write DBus client applications easy\n",
  0,
  {
    ECORE_GETOPT_STORE_STR('p', "prefix", "The prefix for the generated code."),
    ECORE_GETOPT_STORE_STR('i', "interface", "To generate code of only one interface of xml."),
    ECORE_GETOPT_STORE_STR('o', "output file name", "The name of output files, only used if a interface is selected."),
    ECORE_GETOPT_LICENSE('L', "license"),
    ECORE_GETOPT_COPYRIGHT('C', "copyright"),
    ECORE_GETOPT_VERSION('V', "version"),
    ECORE_GETOPT_HELP('h', "help"),
    ECORE_GETOPT_SENTINEL
  }
};

int
main(int argc, char **argv)
{
   char *xml_buf = NULL;
   DBus_Object *obj = NULL;
   char *prefix = NULL, *interface = NULL, *output = NULL;
   Eina_Bool quit_option = EINA_FALSE;
   int arg_index;
   Ecore_Getopt_Value values[] = {
      ECORE_GETOPT_VALUE_STR(prefix),
      ECORE_GETOPT_VALUE_STR(interface),
      ECORE_GETOPT_VALUE_STR(output),
      ECORE_GETOPT_VALUE_BOOL(quit_option),
      ECORE_GETOPT_VALUE_BOOL(quit_option),
      ECORE_GETOPT_VALUE_BOOL(quit_option),
      ECORE_GETOPT_VALUE_BOOL(quit_option),
      ECORE_GETOPT_VALUE_NONE
   };

   eina_init();

   arg_index = ecore_getopt_parse(&optdesc, values, argc, argv);
   if (arg_index == -1)
     {
        printf("Error: parsing arguments.\n");
        return -1;
     }
   if (quit_option)
     return 0;
   if (argc <= arg_index)
     {
        printf("Error: Missing file name.\n");
        return -1;
     }

   if (!file_read(argv[arg_index], &xml_buf))
     {
        printf("Error reading file.\n");
        goto end;
     }

   if (!eina_simple_xml_parse(xml_buf, strlen(xml_buf), EINA_TRUE,
                              parser, &obj))
     {
        printf("Error: could not parse XML\n");
        goto end;
     }

   source_client_generate(obj, prefix, interface, output);
   util_h_write();

end:
   if (obj)
     object_free(obj);

   free(xml_buf);
   eina_shutdown();
   return 0;
}