Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / protocol-plugin / plugins / mqtt-light / src / lightserver_mqtt_plugin.cpp
1 #include "lightserver_mqtt_plugin.h"
2 #include "lightserver.h"
3 #include <cstdlib>
4 #include <pthread.h>                            // 2
5
6 //int start_fanserver(void*);                   // 1
7 void *start_lightserver(void *d);     // 2
8
9 typedef struct plugin_data_t plugin_data_t;
10
11 struct plugin_data_t
12 {
13     cp_context_t *ctx;
14     pthread_t m_thread;                                 // 2
15     void *str;
16     bool flag;
17 };
18
19
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24
25 static void *create(cp_context_t *ctx)
26 {
27     plugin_data_t *data = (plugin_data_t *)malloc(sizeof(plugin_data_t));
28
29     if (data != NULL)
30     {
31         data->ctx = ctx;
32         data->flag = true;
33     }
34     else
35     {
36         printf("[MQTT] ERROR: Plug-in Data - NULL\n");
37     }
38
39     return data;
40 }
41
42 static int start(void *d)
43 {
44     plugin_data_t *data = (plugin_data_t *)d;
45
46     //data->str = (void *)cp_resolve_symbol(data->ctx, "lightserver_mqtt_plugin", "START_ARGUMENT", NULL);
47
48     //cp_run_function(data->ctx, (cp_run_func_t)start_fanserver);           // 1
49     pthread_create(&(data->m_thread), NULL, start_lightserver, data);         // 2
50     return 0;
51 }
52
53 static void stop(void *d)
54 {
55     printf("function_stop\n");
56     plugin_data_t *data = (plugin_data_t *)d;
57
58     data->flag = false;
59     //cp_release_symbol(data->ctx, data->str);
60     pthread_join(data->m_thread, (void **)NULL);
61 }
62
63 static void destroy(void *d)
64 {
65     printf("function_destroy\n");
66     plugin_data_t *data = (plugin_data_t *)d;
67     free(data);
68 }
69
70 CP_EXPORT cp_plugin_runtime_t mqtt_plugin_lightserver_funcs =
71 {
72     create,
73     start,
74     stop,
75     destroy
76 };
77
78 #ifdef __cplusplus
79 }
80 #endif