Added initial code for gtest
[platform/core/connectivity/wifi-mesh-manager.git] / src / wmesh-service.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19 #include <glib.h>
20
21 #include "wmesh.h"
22 #include "wmesh-log.h"
23 #include "wmesh-util.h"
24 #include "wmesh-service.h"
25
26 wmesh_service *wmeshd_service_new()
27 {
28         wmesh_service *service;
29
30         service = g_malloc0(sizeof(struct _wmesh_service));
31
32         /* Create g-main loop */
33         service->main_loop = g_main_loop_new(NULL, FALSE);
34         if (G_UNLIKELY(NULL == service->main_loop)) {
35                 /* LCOV_EXCL_START */
36                 WMESH_LOGE("g-main loop creation failed!!!");
37                 g_free(service);
38                 return NULL;
39                 /* LCOV_EXCL_STOP */
40         }
41
42         return service;
43 }
44
45 void wmeshd_service_free(wmesh_service *service)
46 {
47         wmeshd_check_null_ret("service", service);
48
49         /* Unref 'g-main loop' */
50         if (service->main_loop)
51                 g_main_loop_unref(service->main_loop);
52
53         g_free(service);
54 }
55
56 gboolean wmeshd_service_run(wmesh_service *service)
57 {
58         wmeshd_check_null_ret_error("service", service, FALSE);
59         wmeshd_check_null_ret_error("service->main_loop", service->main_loop, FALSE);
60
61         g_main_loop_run(service->main_loop);
62
63         return TRUE;
64 }
65
66 gboolean wmeshd_service_exit(wmesh_service *service)
67 {
68         wmeshd_check_null_ret_error("service", service, FALSE);
69         wmeshd_check_null_ret_error("service->main_loop", service->main_loop, FALSE);
70
71         g_main_loop_quit(service->main_loop);
72
73         return TRUE;
74 }