Skip to content

Commit 3135535

Browse files
committed
native service: Move everything luna-service related to service.c
1 parent bdd3505 commit 3135535

File tree

3 files changed

+45
-35
lines changed

3 files changed

+45
-35
lines changed

service/src/main.c

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@
44

55
GMainLoop *gmainLoop;
66

7-
// This is a deprecated symbol present in meta-lg-webos-ndk but missing in
8-
// latest buildroot NDK. It is required for proper public service registration
9-
// before webOS 3.5.
10-
//
11-
// SECURITY_COMPATIBILITY flag present in CMakeList disables deprecation notices, see:
12-
// https://github.com/webosose/luna-service2/blob/b74b1859372597fcd6f0f7d9dc3f300acbf6ed6c/include/public/luna-service2/lunaservice.h#L49-L53
13-
bool LSRegisterPubPriv(const char* name, LSHandle** sh,
14-
bool public_bus,
15-
LSError* lserror) __attribute__((weak));
16-
177
int main()
188
{
199
service_t service = {0};
@@ -34,41 +24,21 @@ int main()
3424

3525
bool ret = false;
3626

37-
if (&LSRegisterPubPriv != 0) {
38-
ret = LSRegisterPubPriv(SERVICE_NAME, &handle, true, &lserror);
39-
} else {
40-
ret = LSRegister(SERVICE_NAME, &handle, &lserror);
41-
}
42-
43-
if (!ret) {
44-
ERR("Unable to register on Luna bus: %s", lserror.message);
45-
goto exit;
46-
}
47-
48-
if ((ret = service_init(handle, &service, &lserror)) && !ret ) {
27+
if ((ret = service_init(handle, gmainLoop, &service, &lserror)) && !ret ) {
4928
ERR("Unable to init service: %s", lserror.message);
5029
goto exit;
5130
}
5231

53-
if ((ret = LSGmainAttach(handle, gmainLoop, &lserror)) && !ret ) {
54-
ERR("Unable to attach main loop: %s", lserror.message);
55-
goto exit;
56-
}
57-
5832
DBG("Going into main loop..");
5933

6034
// run to check continuously for new events from each of the event sources
6135
g_main_loop_run(gmainLoop);
6236

6337
DBG("Main loop quit...");
6438

65-
DBG("Cleaning up service...");
66-
daemon_terminate(&service);
67-
6839
exit:
69-
if (handle) {
70-
DBG("Unregistering service...");
71-
LSUnregister(handle, &lserror);
40+
if ((ret = service_destroy(handle, &service, &lserror)) && !ret) {
41+
WARN("Destroying service properly failed: %s", lserror.message);
7242
}
7343

7444
LSErrorFree(&lserror);

service/src/service.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,34 @@ LSMethod methods[] = {
150150
{ 0, 0, 0 }
151151
};
152152

153-
bool service_init(LSHandle *handle, service_t *service, LSError *lserror)
153+
bool service_destroy(LSHandle *handle, service_t *service, LSError *lserror)
154+
{
155+
DBG("Cleaning up service...");
156+
daemon_terminate(service);
157+
158+
if (handle) {
159+
DBG("Unregistering service...");
160+
LSUnregister(handle, lserror);
161+
}
162+
163+
return true;
164+
}
165+
166+
bool service_init(LSHandle *handle, GMainLoop* loop, service_t *service, LSError *lserror)
154167
{
155168
bool ret = false;
156169

170+
if (&LSRegisterPubPriv != 0) {
171+
ret = LSRegisterPubPriv(SERVICE_NAME, &handle, true, lserror);
172+
} else {
173+
ret = LSRegister(SERVICE_NAME, &handle, lserror);
174+
}
175+
176+
if (!ret) {
177+
ERR("Unable to register on Luna bus: %s", lserror->message);
178+
return false;
179+
}
180+
157181
if ((ret = LSRegisterCategory(handle, "/", methods, NULL, NULL, lserror)) && !ret ) {
158182
ERR("Unable to register category on Luna bus: %s", lserror->message);
159183
return false;
@@ -164,5 +188,10 @@ bool service_init(LSHandle *handle, service_t *service, LSError *lserror)
164188
return false;
165189
}
166190

191+
if ((ret = LSGmainAttach(handle, loop, lserror)) && !ret ) {
192+
ERR("Unable to attach main loop: %s", lserror->message);
193+
return false;
194+
}
195+
167196
return true;
168197
}

service/src/service.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
#define DAEMON_EXECUTABLE "hyperiond"
1212
#define DAEMON_NAME "Hyperion.NG"
1313

14+
// This is a deprecated symbol present in meta-lg-webos-ndk but missing in
15+
// latest buildroot NDK. It is required for proper public service registration
16+
// before webOS 3.5.
17+
//
18+
// SECURITY_COMPATIBILITY flag present in CMakeList disables deprecation notices, see:
19+
// https://github.com/webosose/luna-service2/blob/b74b1859372597fcd6f0f7d9dc3f300acbf6ed6c/include/public/luna-service2/lunaservice.h#L49-L53
20+
bool LSRegisterPubPriv(const char* name, LSHandle** sh,
21+
bool public_bus,
22+
LSError* lserror) __attribute__((weak));
23+
1424
// Global from main.c
1525
extern GMainLoop *gmainLoop;
1626

@@ -22,4 +32,5 @@ typedef struct {
2232

2333
int service_start(service_t* service);
2434
int service_stop(service_t* service);
25-
bool service_init(LSHandle *handle, service_t *service, LSError *lserror);
35+
bool service_init(LSHandle *handle, GMainLoop* loop, service_t *service, LSError *lserror);
36+
bool service_destroy(LSHandle *handle, service_t *service, LSError *lserror);

0 commit comments

Comments
 (0)