This repository has been archived by the owner on Oct 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
NodeStateMachine.c
118 lines (92 loc) · 3.1 KB
/
NodeStateMachine.c
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
#include <gio/gio.h> /* Access dbus using glib */
#include "NodeStateMachine.h" /* Own header file */
#include "NodeStateTypes.h" /* Know the types of the NSM */
#include "NodeStateManager.h" /* Access inhternal NSM interfaces */
#include "SimpleNodeStateMachineApi.h" /* Dbus interface offered by NSMC */
#include <stdio.h>
static gboolean NSM__handle_shutdown(NodeStateOrgGeniviSimpleNodeStateMachine *pStateMachine,
GDBusMethodInvocation *pInvocation,
gpointer pUserData)
{
NsmErrorStatus_e retVal;
const NsmDataType_e enDataType = NsmDataType_NodeState;
const NsmNodeState_e nsmNodeState = NsmNodeState_ShuttingDown;
retVal = NsmSetData(enDataType,
(unsigned char *)&nsmNodeState,
sizeof(NsmDataType_NodeState));
if (retVal != NsmErrorStatus_Ok) {
g_error("Failed to set nsm data %i", retVal);
}
return TRUE;
}
static NodeStateOrgGeniviSimpleNodeStateMachine *pStateMachine = NULL;
static GDBusConnection *pConnection = NULL;
static void on_name_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
if(g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(pStateMachine),
pConnection,
"/org/genivi/SimpleNodeStateMachine",
NULL) == TRUE)
{
(void) g_signal_connect(pStateMachine, "handle_shutdown",
G_CALLBACK(NSM__handle_shutdown),
NULL);
}
else
{
g_warning("Failed to export skeleton\n");
}
}
unsigned char NsmcInit(void)
{
GError *gerr = NULL;
unsigned char retval = 1;
g_info("NsmcInit\n");
pStateMachine = node_state_org_genivi_simple_node_state_machine_skeleton_new();
if (pStateMachine == NULL)
{
g_warning("pStateMachine is Null");
retval = 0;
}
pConnection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &gerr);
if (pConnection == NULL)
{
g_warning("pconnection error: %s\n", gerr->message);
retval = 0;
}
g_bus_own_name (G_BUS_TYPE_SYSTEM,
"org.genivi.SimpleNodeStateMachine",
G_BUS_NAME_OWNER_FLAGS_NONE,
NULL,
on_name_acquired,
NULL,
NULL,
NULL);
return retval;
}
unsigned char NsmcLucRequired(void)
{
return 1;
}
unsigned char NsmcRequestNodeRestart(NsmRestartReason_e enRestartReason, unsigned int u32RestartType)
{
printf("NSMC: NsmcRequestNodeRestart called. Restart reason: %d. RestartType: 0x%02X\n", enRestartReason, u32RestartType);
return 1;
}
unsigned int NsmcGetInterfaceVersion(void)
{
return (unsigned int) NSMC_INTERFACE_VERSION;
}
NsmErrorStatus_e NsmcSetData(NsmDataType_e enData, unsigned char *pData, unsigned int u32DataLen)
{
if((enData == NsmDataType_NodeState)
&& (u32DataLen == sizeof(NsmNodeState_e)
&& ((NsmNodeState_e) *pData) == NsmNodeState_Shutdown))
{
g_object_unref(pConnection);
g_object_unref(pStateMachine);
}
return NsmErrorStatus_Ok;
}