--- /dev/null
+#ifndef __NLP_LOG_H__
+#define __NLP_LOG_H__
+
+#include <dlog.h>
+#include <string.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "NLP_SERVICE"
+
+#define COLOR_RED "\033[0;31m"
+#define COLOR_GREEN "\033[0;32m"
+#define COLOR_BROWN "\033[0;33m"
+#define COLOR_BLUE "\033[0;34m"
+#define COLOR_PURPLE "\033[0;35m"
+#define COLOR_CYAN "\033[0;36m"
+#define COLOR_LIGHTBLUE "\033[0;37m"
+#define COLOR_END "\033[0;m"
+
+#define PLOG(fmt, args...) LOGI(fmt, ##args)
+#define PINFO(fmt, args...) LOGI(COLOR_PURPLE"* Info * " fmt COLOR_END, ##args)
+#define PWARNING(fmt, args...) LOGI(COLOR_BLUE"* Warning * " fmt COLOR_END, ##args)
+#define PERR(fmt, args...) LOGE(COLOR_RED"* Critical * " fmt COLOR_END, ##args)
+#define PENTER() LOGI(COLOR_GREEN"BEGIN >>>>"COLOR_END)
+#define PLEAVE() LOGI(COLOR_GREEN"END <<<<"COLOR_END)
+
+#define PRET_VM(expr, val, fmt, arg...) do { \
+ if (expr) { \
+ PERR(fmt, ##arg); \
+ return (val); \
+ } \
+} while (0)
+
+#define PRET_M(expr, fmt, arg...) do { \
+ if (expr) { \
+ PERR(fmt, ##arg); \
+ return; \
+ } \
+} while (0)
+
+#define P_M(expr, fmt, arg...) do { \
+ if (expr) { \
+ PERR(fmt, ##arg); \
+ } \
+} while (0)
+
+#endif /* __NLP_LOG_H__ */
#include <tizen.h>
#include <dlfcn.h>
#include <service_app.h>
-#include "service.h"
-#include <dlog.h>
#include <glib.h>
+#include "service.h"
+#include "nlp_log.h"
#include "message.h"
struct client_s {
static struct client_s *__create_client(const char *id,
rpc_port_message_notify_cb_h cb)
{
+ PENTER();
struct client_s *handle;
handle = calloc(1, sizeof(struct client_s));
if (!handle) {
- LOGE("Out of memory");
+ PERR("Out of memory");
return NULL;
}
handle->id = strdup(id);
if (!handle->id) {
- LOGE("Out of memory");
+ PERR("Out of memory");
free(handle);
return NULL;
}
rpc_port_message_notify_cb_clone(cb, &handle->cb);
if (!handle->cb) {
- LOGE("Out of memory");
+ PERR("Out of memory");
free(handle->id);
free(handle);
return NULL;
static void __destroy_client(gpointer data)
{
+ PENTER();
struct client_s *handle = data;
if (!handle)
static void __messeage_create(rpc_port_stub_message_context_h context,
void *user_data)
{
+ PENTER();
char *sender = NULL;
rpc_port_stub_message_context_get_sender(context, &sender);
if (!sender)
return;
- LOGI("[__RPC_PORT__] sender(%s)", sender);
+ PLOG("[__RPC_PORT__] sender(%s)", sender);
free(sender);
}
static void __message_terminate(rpc_port_stub_message_context_h context,
void *user_data)
{
+ PENTER();
char *sender = NULL;
rpc_port_stub_message_context_get_sender(context, &sender);
if (!sender)
return;
- LOGI("[__RPC_PORT__] sender(%s)", sender);
+ PLOG("[__RPC_PORT__] sender(%s)", sender);
free(sender);
}
{
struct client_s *client;
- LOGI("[__RPC_PORT__] name(%s)", name);
+ PLOG("[__RPC_PORT__] name(%s)", name);
client = __create_client(name, cb);
if (!client)
return -1;
char *message = NULL;
bundle_get_str(msg, "command", &message);
rpc_port_stub_message_context_get_tag(context, (void *)&sender_client);
- LOGI("[__RPC_PORT__] name(%s), msg(%s)", sender_client->id, message);
+ PLOG("[__RPC_PORT__] name(%s), msg(%s)", sender_client->id, message);
bundle *reply = bundle_create();
char *info = NULL;
}
bundle_add_str(reply, "command", "word_tokenize");
bundle_add_str_array(reply, "return_token", tokens, len);
- LOGD("word_tokenize process done");
+ PINFO("word_tokenize process done");
break;
case NLTK_CMD_POSTAG:
args = nltk_make_args_from_string(info);
bundle_add_str(reply, "command", "pos_tag");
bundle_add_str_array(reply, "return_tag", tag, len);
bundle_add_str_array(reply, "return_token", token, len);
- LOGD("pos_tag process done");
+ PINFO("pos_tag process done");
break;
case NLTK_CMD_NECHUNK:
args = nltk_make_args_from_string(info);
bundle_add_str(reply, "command", "ne_chunk");
bundle_add_str_array(reply, "return_tag", s_tag, len);
bundle_add_str_array(reply, "return_token", s_token, len);
- LOGD("ne_chunk process done");
+ PINFO("ne_chunk process done");
break;
case NLTK_CMD_LEMMATIZE:
args = nltk_make_args_from_string(info);
strcpy(lem_buf[0] , nltk_get_string_from_element(lm_result));
bundle_add_str(reply, "command", "lemmatize");
bundle_add_str_array(reply, "return_token", lem_buf, 1);
- LOGD("lemmatize process done");
+ PINFO("lemmatize process done");
break;
case NLTK_CMD_LANGDETECT:
args = nltk_make_args_from_string(info);
strcpy(lang_buf[0] , nltk_get_string_from_element(ld_result));
bundle_add_str(reply, "command", "langdetect");
bundle_add_str_array(reply, "return_token", lang_buf, 1);
- LOGD("langdetect process done");
+ PINFO("langdetect process done");
break;
default:
+ PWARNING("unkonw command, command = [%s]", message);
bundle_add_str(reply, "command", "Exception happens");
break;
}
if (client == NULL)
return;
rpc_port_stub_message_context_set_tag(context, NULL);
- LOGI("[__RPC_PORT__] name(%s)", client->id);
+ PLOG("[__RPC_PORT__] name(%s)", client->id);
__destroy_client(client);
}
{
nltk_initialize();
globe_nltk = nltk_get_module("nltk");
- LOGD("nltk library loaded success: ");
+ PINFO("nltk library loaded success: ");
globe_lemm = nltk_get_module("nltk.stem");
- LOGD("nltk stem library loaded success: ");
+ PINFO("nltk stem library loaded success: ");
globe_lang = nltk_get_module("langdetect");
- LOGD("langdetect library loaded success: ");
+ PINFO("langdetect library loaded success: ");
int ret;
rpc_port_stub_message_callback_s callback = {
void nltk_initialize()
{
+ PENTER();
Py_Initialize();
}
void nltk_finalize()
{
+ PENTER();
Py_Finalize();
}
PyObject* nltk_get_module(char* name)
{
+ PRET_VM(!name, NULL, "Input parameter [name] is NULL!");
return PyImport_ImportModuleNoBlock(name);
}
PyObject* nltk_get_element_from_tuple_by_index(PyObject* tuple, int index)
{
+ PRET_VM(!tuple, NULL, "Input parameter [tuple] is NULL!");
PyObject* element;
if PyTuple_Check(tuple)
{
char* nltk_get_string_from_element(PyObject* elm)
{
+ PRET_VM(!elm, NULL, "Input parameter [elm] is NULL!");
char* ch = (char*) malloc(255);
strcpy(ch, PyString_AsString(elm));
return ch;
PyObject* nltk_get_function_handle(PyObject* module, char * func_name)
{
+ PRET_VM(!module, NULL, "Input parameter [module] is NULL!");
+ PRET_VM(!func_name, NULL, "Input parameter [func_name] is NULL!");
return PyObject_GetAttrString(module, func_name);
}
PyObject* nltk_make_args_from_string(char* info)
{
+ PRET_VM(!info, NULL, "Input parameter [info] is NULL!");
PyObject *pArgs;
//create args tuple struct to fill the arg one by one ,here , only create one string with 1
pArgs = PyTuple_New(1);
PyObject* nltk_make_args_from_pyobject(PyObject* pyobj)
{
+ PRET_VM(!pyobj, NULL, "Input parameter [pyobj] is NULL!");
PyObject *pArgs;
//create args tuple struct to fill the arg one by one ,here ,only create one python object with 1
pArgs = PyTuple_New(1);
PyObject* nltk_call_function_with_args(PyObject* func, PyObject* args)
{
+ PRET_VM(!func, NULL, "Input parameter [func] is NULL!");
return PyObject_CallObject(func, args);
}