add pilot version of receiver module
[apps/native/gear-racing-car.git] / src / receiver.c
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.1 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdlib.h>
18 #include "log.h"
19 #include "receiver_internal.h"
20
21 typedef struct __receiver_h {
22         receiver_type_e receiver_type;
23         /* TODO */
24 } receiver_h;
25
26 static receiver_h *ghandle = NULL;
27
28 int receiver_init(receiver_type_e type)
29 {
30         int ret = 0;
31
32         if (ghandle) {
33                 _E("receiver is already initialized");
34                 return -1;
35         }
36
37         ghandle = (receiver_h *)malloc(sizeof(receiver_h));
38         if (!ghandle) {
39                 _E("failed to malloc handle");
40                 return -1;
41         }
42
43         switch (type) {
44         case RECEIVER_TYPE_UDP:
45                 ghandle->receiver_type = type;
46                 ret = receiver_udp_start();
47                 if (ret)
48                         goto ERROR;
49                 break;
50         case RECEIVER_TYPE_BLUETOOTH:
51                 /* TODO */
52                 break;
53         }
54         return 0;
55
56 ERROR:
57         free(ghandle);
58         ghandle = NULL;
59         return -1;
60 }
61
62 void receiver_fini(void)
63 {
64         if (ghandle) {
65                 switch (ghandle->receiver_type) {
66                 case RECEIVER_TYPE_UDP:
67                         receiver_udp_stop();
68                         break;
69                 case RECEIVER_TYPE_BLUETOOTH:
70                         /* TODO */
71                         break;
72                 }
73
74                 free(ghandle);
75                 ghandle = NULL;
76         }
77         return;
78 }