#define IOTAPI_LOG(x...)
#endif
+#define IOTAPI_MESSAGE_QUEUE_EMPTY 0
+#define IOTAPI_MESSAGE_QUEUE_INSERT 1
+#define IOTAPI_MESSAGE_QUEUE_REMOVE 2
struct _iotapi_msg_queue {
int type; // 1 is insert, 2 is remove, 0 is empty
char buf[3];
pthread_mutex_lock(&g_ia_lock);
- if (g_ia_msg_queue[0].type == 1) {
+ if (g_ia_msg_queue[0].type == IOTAPI_MESSAGE_QUEUE_INSERT) {
g_ia_evt_queue[0].fd = g_ia_msg_queue[0].evt.fd;
g_ia_evt_queue[0].data = g_ia_msg_queue[0].evt.data;
g_ia_evt_queue[0].func = g_ia_msg_queue[0].evt.func;
g_ia_evt_size = 1;
- g_ia_msg_queue[0].type = 0;
+ g_ia_msg_queue[0].type = IOTAPI_MESSAGE_QUEUE_EMPTY;
}
pthread_mutex_unlock(&g_ia_lock);
}
if (g_ia_evtlist[0].revents & POLLIN) {
+
+#ifdef CONFIG_IOTAPI_DEBUG
int readed;
readed = read(g_ia_evtlist[0].fd, buf, 3);
IOTAPI_LOG("[iotcom] receive command(%d)\n", readed);
+#else
+ read(g_ia_evtlist[0].fd, buf, 3);
+#endif
+
if (buf[0] == 's' && buf[1] == 't')
break;
pthread_mutex_lock(&g_ia_lock);
- if (g_ia_msg_queue[0].type == 1) {
+ if (g_ia_msg_queue[0].type == IOTAPI_MESSAGE_QUEUE_INSERT) {
g_ia_evt_size++;
int i = 0;
for (; i < IOTAPI_QUEUE_SIZE; i++) {
break;
}
}
- g_ia_msg_queue[0].type = 0;
+ g_ia_msg_queue[0].type = IOTAPI_MESSAGE_QUEUE_EMPTY;
}
- if (g_ia_msg_queue[1].type == 2) {
+ if (g_ia_msg_queue[1].type == IOTAPI_MESSAGE_QUEUE_REMOVE) {
g_ia_evt_size--;
int i = 0;
for (; i < IOTAPI_QUEUE_SIZE; i++) {
break;
}
}
- g_ia_msg_queue[1].type = 0;
+ g_ia_msg_queue[1].type = IOTAPI_MESSAGE_QUEUE_EMPTY;
}
if (g_ia_evt_size == 0) {
IOTAPI_LOG("[iotcom] create iotapi handler fail(%d)\n", ret);
return -1;
}
+ pthread_detach(tid);
return 0;
}
}
if (g_ia_evt_size == 0)
mode = 0;
- g_ia_msg_queue[0].type = 1;
+ g_ia_msg_queue[0].type = IOTAPI_MESSAGE_QUEUE_INSERT;
g_ia_msg_queue[0].evt.fd = item->fd;
g_ia_msg_queue[0].evt.data = item->data;
g_ia_msg_queue[0].evt.func = item->func;
pthread_mutex_unlock(&g_ia_lock);
ret = -1;
}
- g_ia_msg_queue[1].type = 2;
+ g_ia_msg_queue[1].type = IOTAPI_MESSAGE_QUEUE_REMOVE;
g_ia_msg_queue[1].evt.fd = item->fd;
pthread_mutex_unlock(&g_ia_lock);