[Feature]add MT2731_MP2_MR2_SVN388 baseline version
Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/src/lynq/packages/apps/lynq-threadhandle/include/common.h b/src/lynq/packages/apps/lynq-threadhandle/include/common.h
new file mode 100644
index 0000000..02fcdeb
--- /dev/null
+++ b/src/lynq/packages/apps/lynq-threadhandle/include/common.h
@@ -0,0 +1,19 @@
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+
+#define NO_ERROR 0
+#define ERR_VALID 70 //valid error
+#define ERR_CMDVALID 71 //cmd error
+#define ERR_SESSIONVALID 72 //session error
+#define ERR_MALLOCVALID 73 //malloc error
+#define ERR_INVOKE 74 //invoke error
+#define ERR_SYSTEM 75 //system error
+#define ERR_TIMEOUT 76 //time out error
+
+#define BUF_SIZE 8192
+//int th_error;
+
+int str_arr(char *str, char *substr, char parts[][BUF_SIZE]);
+#endif
+
diff --git a/src/lynq/packages/apps/lynq-threadhandle/include/double_list.h b/src/lynq/packages/apps/lynq-threadhandle/include/double_list.h
new file mode 100644
index 0000000..b8682c0
--- /dev/null
+++ b/src/lynq/packages/apps/lynq-threadhandle/include/double_list.h
@@ -0,0 +1,49 @@
+#ifndef __DOUBLE_LIST__H__
+#define __DOUBLE_LIST__H__
+
+
+#include "syn_primitive.h"
+
+
+typedef struct tag_d_list
+{
+ void *data;
+ unsigned int data_len;
+ struct tag_d_list *pre;
+ struct tag_d_list *next;
+}d_list_node_t;
+
+
+typedef struct
+{
+ unsigned int node_count;
+ d_list_node_t *head;
+ d_list_node_t *tail;
+
+ d_list_node_t *cur_idx;
+}d_list_t;
+
+
+typedef int (*compare_func)(void *usr_data, unsigned int udata_len, void *list_data, unsigned int ldata_len);
+
+BOOL is_empty_d_list(d_list_t *list);
+unsigned int get_d_list_node_count(d_list_t *list);
+d_list_t *create_d_list(void);
+void destroy_d_list(d_list_t *list);
+BOOL insert_d_list_head(d_list_t *list, void *data, unsigned int data_len);
+BOOL insert_d_list_tail(d_list_t *list, void *data, unsigned int data_len);
+BOOL insert_d_list_head_node(d_list_t *list, d_list_node_t *node);
+BOOL insert_d_list_tail_node(d_list_t *list, d_list_node_t *node);
+BOOL delete_d_list_head(d_list_t *list);
+BOOL delete_d_list_tail(d_list_t *list);
+BOOL delete_d_list_node_all(d_list_t *list);
+BOOL remove_d_list_node(d_list_t *list, d_list_node_t *node);
+d_list_node_t *remove_d_list_head_node(d_list_t *list);
+d_list_node_t *remove_d_list_tail_node(d_list_t *list);
+d_list_node_t *find_d_list_node(d_list_t *list, void *user_data, unsigned int data_len, compare_func func);
+d_list_node_t *get_d_list_node(d_list_t *list, int idx);
+d_list_node_t *get_next_node(d_list_t *list);
+
+#endif //__DOUBLE_LIST__H__
+
+
diff --git a/src/lynq/packages/apps/lynq-threadhandle/include/ftp_manager.h b/src/lynq/packages/apps/lynq-threadhandle/include/ftp_manager.h
new file mode 100644
index 0000000..bb833ab
--- /dev/null
+++ b/src/lynq/packages/apps/lynq-threadhandle/include/ftp_manager.h
@@ -0,0 +1,29 @@
+#ifndef _FTP_MANAGER_H
+#define _FTP_MANAGER_H
+
+#include "thread_pool.h"
+#include "list.h"
+#include "ftp/lynq_ftp.h"
+#include "common.h"
+
+typedef struct
+{
+ int id;
+ char *action;
+ int (*ftp_action)(lynq_ftp_socker_info* FTP);
+}FTP_MAG_S;
+
+
+typedef struct FTP_LIST_LINK
+{
+ struct list_head list;
+ lynq_ftp_socker_info data;
+}FTP_LIST_LINK_S;
+
+
+void ftp_list_init(void);
+int ftp_list_locate(void);
+int ftp_param_verification(char result[][BUF_SIZE] , int line);
+int ftp_act_handler(thread_pool_t *pool);
+
+#endif
\ No newline at end of file
diff --git a/src/lynq/packages/apps/lynq-threadhandle/include/http_manager.h b/src/lynq/packages/apps/lynq-threadhandle/include/http_manager.h
new file mode 100644
index 0000000..21f5e70
--- /dev/null
+++ b/src/lynq/packages/apps/lynq-threadhandle/include/http_manager.h
@@ -0,0 +1,26 @@
+#ifndef _HTTP_MANAGER_H
+#define _HTTP_MANAGER_H
+
+
+#include "http/lynq_http.h"
+#include "thread_pool.h"
+#include "list.h"
+#include "common.h"
+
+
+
+typedef struct
+{
+ struct list_head list;
+ lynq_http_client_t data;
+}HTTP_LIST_LINK_S;
+
+void http_list_init(void);
+int http_list_locate(void);
+int http_param_verification(char result[][BUF_SIZE], int line);
+int http_act_handler(thread_pool_t *pool);
+
+
+
+#endif
+
diff --git a/src/lynq/packages/apps/lynq-threadhandle/include/list.h b/src/lynq/packages/apps/lynq-threadhandle/include/list.h
new file mode 100644
index 0000000..697ff6f
--- /dev/null
+++ b/src/lynq/packages/apps/lynq-threadhandle/include/list.h
@@ -0,0 +1,122 @@
+#ifndef _LINUX_LIST_H
+#define _LINUX_LIST_H
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+
+#ifndef offsetof
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
+
+#ifndef container_of
+#define container_of(ptr, type, member) ((type *)((char *)ptr - offsetof(type,member)))
+#endif
+
+#define prefetch(x) ((void)x)
+#define LIST_POISON1 (NULL)
+#define LIST_POISON2 (NULL)
+
+struct list_head{
+ struct list_head *next, *prev;
+};
+
+struct hlist_node{
+ struct hlist_node *next, **pprev;
+};
+
+struct hlist_head{
+ struct hlist_node *first;
+};
+
+#define LIST_HEAD_INIT(name) { &(name), &(name) }
+
+#define LIST_HEAD(name) \
+ struct list_head name = LIST_HEAD_INIT(name)
+
+static void INIT_LIST_HEAD(struct list_head *list)
+{
+ list->next = list;
+ list->prev = list;
+}
+
+
+static void __list_add(struct list_head *node,
+ struct list_head *prev,
+ struct list_head *next)
+{
+ next->prev = node;
+ node->next = next;
+ node->prev = prev;
+ prev->next = node;
+}
+
+static void list_add(struct list_head *node, struct list_head *head)
+{
+ __list_add(node, head, head->next);
+}
+
+
+static void list_add_tail(struct list_head *node, struct list_head *head)
+{
+ __list_add(node, head->prev, head);
+}
+
+/*
+ * Delete a list entry by making the prev/next entries
+ * point to each other.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static void __list_del(struct list_head * prev, struct list_head * next)
+{
+ next->prev = prev;
+ prev->next = next;
+}
+
+/**
+ * list_del - deletes entry from list.
+ * @entry: the element to delete from the list.
+ * Note: list_empty() on entry does not return true after this, the entry is
+ * in an undefined state.
+ */
+static void __list_del_entry(struct list_head *entry)
+{
+ __list_del(entry->prev, entry->next);
+}
+
+static void list_del(struct list_head *entry)
+{
+ __list_del(entry->prev, entry->next);
+ entry->next = LIST_POISON1;
+ entry->prev = LIST_POISON2;
+}
+
+/**
+ * list_entry - get the struct for this entry
+ * @ptr: the &struct list_head pointer.
+ * @type: the type of the struct this is embedded in.
+ * @member: the name of the list_struct within the struct.
+ */
+#define list_entry(ptr, type, member) \
+ container_of(ptr, type, member)
+
+
+/**
+ * list_for_each - iterate over a list
+ * @pos: the &struct list_head to use as a loop cursor.
+ * @head: the head for your list.
+ */
+#define list_for_each(pos, head) \
+ for (pos = (head)->next; prefetch(pos->next), pos != (head); \
+ pos = pos->next)
+
+#define list_safe_reset_next(pos, n, member) \
+ n = list_entry(pos->member.next, typeof(*pos), member)
+
+#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
+
+#endif
+
diff --git a/src/lynq/packages/apps/lynq-threadhandle/include/model_manager.h b/src/lynq/packages/apps/lynq-threadhandle/include/model_manager.h
new file mode 100644
index 0000000..78fb3c7
--- /dev/null
+++ b/src/lynq/packages/apps/lynq-threadhandle/include/model_manager.h
@@ -0,0 +1,31 @@
+#ifndef _MODEL_MANAGER_H
+#define _MODEL_MANAGER_H
+
+#include "http_manager.h"
+#include "ftp_manager.h"
+#include "list.h"
+#include "thread_pool.h"
+#include <log/log.h>
+#include "ril_manager.h"
+#include "mqtt_manager.h"
+#include "common.h"
+
+typedef struct
+{
+ char *name;
+ void (*func_list_init)(void);
+ int (*func_param_verification)(char result[][BUF_SIZE], int line);
+ int (*func_list_locate)(void);
+ int (*func_act_handler)(thread_pool_t *pool);
+ int (*func_del)(void);
+ int (*func_get)(void);
+ int (*func_set)(void);
+ int (*func_next)(void);
+}MAG_LIST_S;
+
+
+MAG_LIST_S *list_manager_proc(const char *name);
+
+
+#endif
+
diff --git a/src/lynq/packages/apps/lynq-threadhandle/include/mqtt_manager.h b/src/lynq/packages/apps/lynq-threadhandle/include/mqtt_manager.h
new file mode 100644
index 0000000..5f8cbee
--- /dev/null
+++ b/src/lynq/packages/apps/lynq-threadhandle/include/mqtt_manager.h
@@ -0,0 +1,25 @@
+#ifndef _MQTT_MANAGER_H
+#define _MQTT_MANAGER_H
+
+#include "lynq_mqtt/lynq_mqtt.h"
+#include "thread_pool.h"
+#include "list.h"
+#include "common.h"
+
+
+
+typedef struct
+{
+ struct list_head list;
+ struct mqtt_set_parament data;
+}MQTT_LIST_LINK_S;
+
+
+void mqtt_list_init();
+int mqtt_param_verification(char result[][BUF_SIZE] , int line);
+int mqtt_list_locate();
+int mqtt_act_handler(thread_pool_t *pool);
+
+
+#endif
+
diff --git a/src/lynq/packages/apps/lynq-threadhandle/include/ril_manager.h b/src/lynq/packages/apps/lynq-threadhandle/include/ril_manager.h
new file mode 100644
index 0000000..c491cda
--- /dev/null
+++ b/src/lynq/packages/apps/lynq-threadhandle/include/ril_manager.h
@@ -0,0 +1,7 @@
+#include "model_manager.h"
+#include "common.h"
+
+void ril_list_init();
+int ril_param_verification(char result[][BUF_SIZE] , int line);
+int ril_list_locate();
+int ril_act_handler(thread_pool_t *pool);
diff --git a/src/lynq/packages/apps/lynq-threadhandle/include/seq_queue.h b/src/lynq/packages/apps/lynq-threadhandle/include/seq_queue.h
new file mode 100644
index 0000000..2aed03e
--- /dev/null
+++ b/src/lynq/packages/apps/lynq-threadhandle/include/seq_queue.h
@@ -0,0 +1,43 @@
+#ifndef __SEQ_QUEUE__H_
+#define __SEQ_QUEUE__H_
+
+#include "syn_primitive.h"
+
+
+#ifndef in
+#define in
+#define out
+#endif
+
+#define EXPAND_BLOCK_NUM 100
+
+typedef struct
+{
+ BOOL expandabilit;
+ unsigned int expand_blocks;
+
+ unsigned int block_size;
+ unsigned int total_block;
+
+ unsigned int current_block;
+ unsigned int tail_block;
+ unsigned int used_block;
+
+ void *block_buffer;
+
+ //mutex_handle task_queue_lock;
+ sem_handle task_queue_lock;
+
+}seq_queue_t;
+
+
+seq_queue_t *create_seq_queue(in unsigned int block_size, in unsigned int total_block, in BOOL expand);
+void destroy_seq_queue(in seq_queue_t *queue);
+BOOL en_seq_queue(in seq_queue_t *queue, in void *data);
+BOOL de_seq_queue(in seq_queue_t *queue, out void *data);
+unsigned int get_count_seq_queue(in seq_queue_t *queue);
+unsigned int get_total_seq_queue(in seq_queue_t *queue);
+
+
+#endif //__SEQ_QUEUE__H_
+
diff --git a/src/lynq/packages/apps/lynq-threadhandle/include/syn_primitive.h b/src/lynq/packages/apps/lynq-threadhandle/include/syn_primitive.h
new file mode 100644
index 0000000..77dc2d5
--- /dev/null
+++ b/src/lynq/packages/apps/lynq-threadhandle/include/syn_primitive.h
@@ -0,0 +1,43 @@
+#ifndef __SYN_PRIMITIVE__H_
+#define __SYN_PRIMITIVE__H_
+
+#include <pthread.h>
+#include <semaphore.h>
+#include "typedefs.h"
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "liblog/liblog.h"
+#include "liblog/lynq_deflog.h"
+
+typedef pthread_t thread_id;
+typedef pthread_t thread_handle;
+typedef pthread_cond_t condition_handle;
+typedef pthread_mutex_t mutex_handle;
+typedef sem_t sem_handle;
+
+
+
+#define TIME_WAIT_INFINITE 0x7fffffff
+
+
+
+int init_condition_handle(condition_handle *cond);
+int destroy_condition_handle(condition_handle *cond);
+//int wait_condition(condition_handle *cond, mutex_handle *mutex);
+int wait_condition(condition_handle *cond, mutex_handle *mutex, unsigned int wait);
+int post_condition_signal(condition_handle *cond);
+int init_mutex_handle(mutex_handle *mutex);
+int mutex_lock(mutex_handle *mutex);
+int mutex_unlock(mutex_handle *mutex);
+int mutex_destroy(mutex_handle *mutex);
+int create_sem(sem_handle *sem, int init_count);
+int wait_sem(sem_handle *sem);
+int post_sem(sem_handle *sem);
+int destroy_sem(sem_handle *sem);
+
+
+
+#endif //__SYN_PRIMITIVE__H_
+
+
diff --git a/src/lynq/packages/apps/lynq-threadhandle/include/thread_pool.h b/src/lynq/packages/apps/lynq-threadhandle/include/thread_pool.h
new file mode 100644
index 0000000..cc2cd29
--- /dev/null
+++ b/src/lynq/packages/apps/lynq-threadhandle/include/thread_pool.h
@@ -0,0 +1,83 @@
+#ifndef __THREAD_POOL__H_
+#define __THREAD_POOL__H_
+
+#include "syn_primitive.h"
+#include "double_list.h"
+#include "seq_queue.h"
+
+typedef enum {EThread_pool_unknown, EThread_pool_alloc, EThread_pool_init
+, EThread_pool_run, EThread_pool_exit, EThread_pool_MAX}EThread_pool_status;
+
+
+#define RELEASE_THREAD_INTERVAL 5*60
+
+
+typedef void (*THREAD_FUNC)(void *);
+typedef void (*USER_FUNC)(void *thread_para);
+
+
+typedef struct {
+ USER_FUNC timeout_callback;
+ unsigned long time_out;
+}time_out_t;
+
+typedef struct
+{
+ USER_FUNC process_func;
+ USER_FUNC release_func;
+ void *args;
+ time_out_t time_out_info;
+}thread_func_t;
+
+typedef struct
+{
+ thread_func_t thread_para;
+ unsigned int pri;
+
+ BOOL busy;
+ BOOL release;
+
+ unsigned long launch_time;
+ unsigned long time_out;
+
+ EThread_pool_status *pool_status;
+
+ thread_handle h_thread;
+ condition_handle thread_cond;
+ mutex_handle thread_lock;
+
+}thread_info_t;
+
+typedef struct
+{
+ unsigned int pri;
+ unsigned int min_thread_num;
+ unsigned int max_thread_num;
+
+ unsigned int pool_thread_num;
+
+ condition_handle manage_cond;
+ mutex_handle mange_lock;
+
+ unsigned long release_threads_interval;
+
+ d_list_t *idle_threads;
+ d_list_t *busy_threads;
+ seq_queue_t *task_queue;
+
+ sem_handle sem_inc;
+ thread_handle h_id;
+
+ EThread_pool_status status;
+}thread_pool_t;
+
+
+thread_pool_t *threadpool_create(unsigned int min_thread_num, unsigned int max_thread_num);
+void threadpool_destroy(thread_pool_t *pool);
+BOOL threadpool_add(thread_pool_t *pool, USER_FUNC process_func, void *args);
+BOOL threadpool_add_timeout(thread_pool_t *pool, USER_FUNC process_func
+ , USER_FUNC release_func, void *args, time_out_t *time_out);
+void tp_sleep(unsigned int ms);
+
+#endif //__THREAD_POOL__H_
+
diff --git a/src/lynq/packages/apps/lynq-threadhandle/include/typedefs.h b/src/lynq/packages/apps/lynq-threadhandle/include/typedefs.h
new file mode 100644
index 0000000..d205b1c
--- /dev/null
+++ b/src/lynq/packages/apps/lynq-threadhandle/include/typedefs.h
@@ -0,0 +1,21 @@
+#ifndef __TYPE_DEFS__H_
+#define __TYPE_DEFS__H_
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+#ifndef BOOL
+#define BOOL unsigned char
+#endif
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+
+#endif //__TYPE_DEFS__H_