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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/* vi:set et ai sw=2 sts=2 ts=2: */
/* -
* Copyright (c) 2012 GENIVI.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <glib.h>
#include <gio/gio.h>
#include <dlt/dlt.h>
#include <nsm-dummy/nsm-consumer-service.h>
#include <nsm-dummy/nsm-dummy-application.h>
#include <nsm-dummy/nsm-lifecycle-control-service.h>
DLT_DECLARE_CONTEXT (nsm_dummy_context);
static void
unregister_dlt (void)
{
DLT_UNREGISTER_CONTEXT (nsm_dummy_context);
DLT_UNREGISTER_APP ();
}
int
main (int argc,
char **argv)
{
NSMLifecycleControlService *lifecycle_control_service;
NSMDummyApplication *application;
NSMConsumerService *consumer_service;
GDBusConnection *connection;
GMainLoop *main_loop;
GError *error = NULL;
/* register the application and context in DLT */
DLT_REGISTER_APP ("NSMD", "GENIVI Node State Manager Dummy");
DLT_REGISTER_CONTEXT (nsm_dummy_context, "NSMC",
"Context of the node state manager dummy itself");
/* have DLT unregistered at exit */
atexit (unregister_dlt);
/* initialize the GType type system */
g_type_init ();
/* attempt to connect to D-Bus */
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (connection == NULL)
{
DLT_LOG (nsm_dummy_context, DLT_LOG_FATAL,
DLT_STRING ("Failed to connect to D-Bus:"),
DLT_STRING (error->message));
/* clean up */
g_error_free (error);
return EXIT_FAILURE;
}
/* instantiate the NSMLifecycleControlService implementation */
lifecycle_control_service = nsm_lifecycle_control_service_new (connection);
if (!nsm_lifecycle_control_service_start (lifecycle_control_service, &error))
{
DLT_LOG (nsm_dummy_context, DLT_LOG_FATAL,
DLT_STRING ("Failed to start the lifecycle control service:"),
DLT_STRING (error->message));
/* clean up */
g_error_free (error);
g_object_unref (lifecycle_control_service);
g_object_unref (connection);
return EXIT_FAILURE;
}
/* instantiate the NSMConsumerService implementation */
consumer_service = nsm_consumer_service_new (connection);
if (!nsm_consumer_service_start (consumer_service, &error))
{
DLT_LOG (nsm_dummy_context, DLT_LOG_FATAL,
DLT_STRING ("Failed to start the consumer service:"),
DLT_STRING (error->message));
/* clean up */
g_error_free (error);
g_object_unref (consumer_service);
g_object_unref (connection);
return EXIT_FAILURE;
}
/* create the main loop */
main_loop = g_main_loop_new (NULL, FALSE);
/* create the main application */
application = nsm_dummy_application_new (main_loop, connection, consumer_service,
lifecycle_control_service);
/* run the main loop */
g_main_loop_run (main_loop);
g_main_loop_unref (main_loop);
/* release allocated objects */
g_object_unref (application);
g_object_unref (lifecycle_control_service);
g_object_unref (consumer_service);
g_object_unref (connection);
return EXIT_SUCCESS;
}
|