tizen 2.3.1 release
[framework/web/mobile/wrt.git] / src / wrt-client / client_ide_support.cpp
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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  * @file    client_ide_support.cpp
18  * @author  Jihoon Chung (jihoon.chung@samsung.com)
19  */
20
21 #include "client_ide_support.h"
22 #include <stdarg.h>
23 #include <string>
24 #include <dpl/log/wrt_log.h>
25 #include <dpl/exception.h>
26
27 #include <dlog.h>
28 #include <appsvc.h>
29 #include <bundle.h>
30 #include <widget_data_types.h>
31
32 namespace ClientModule {
33 namespace {
34 const char* const KEY_DEBUG = "debug";
35 const char* const KEY_PORT = "port";
36 const char* const VALUE_TRUE = "true";
37
38 const char* const CONSOLE_MESSAGE_LOG_TAG = "ConsoleMessage";
39 }
40
41 bool IDESupport::getDebugMode(bundle* b)
42 {
43     if (!b) {
44         WrtLogW("bundle is empty");
45         return false;
46     }
47
48     const char* value = bundle_get_val(b, KEY_DEBUG);
49     if (value != NULL && !strcmp(value, VALUE_TRUE)) {
50         return true;
51     } else {
52         return false;
53     }
54 }
55
56 bool IDESupport::sendReply(bundle* b, unsigned int portNum)
57 {
58     bundle* request = NULL;
59     if (appsvc_create_result_bundle(b, &request) != APPSVC_RET_OK) {
60         WrtLogW("Fail to create result bundle");
61         return false;
62     }
63
64     char port[10] = {0,};
65     sprintf(port, "%u", portNum);
66     if (appsvc_add_data(request, KEY_PORT, port) != APPSVC_RET_OK) {
67         WrtLogW("Fail to add data");
68         bundle_free(request);
69         return false;
70     }
71
72     if (appsvc_send_result(request, APPSVC_RES_OK) != APPSVC_RET_OK) {
73         WrtLogW("Fail to send result");
74         bundle_free(request);
75         return false;
76     }
77
78     bundle_free(request);
79     return true;
80 }
81
82 void IDESupport::consoleMessage(int level, const char* format, ...)
83 {
84     va_list args;
85     va_start(args, format);
86     switch (level) {
87     case ConsoleLogLevel::Debug:
88         ALOG_VA(LOG_DEBUG, CONSOLE_MESSAGE_LOG_TAG, format, args);
89         break;
90     case ConsoleLogLevel::Warning:
91         ALOG_VA(LOG_WARN, CONSOLE_MESSAGE_LOG_TAG, format, args);
92         break;
93     case ConsoleLogLevel::Error:
94         ALOG_VA(LOG_ERROR, CONSOLE_MESSAGE_LOG_TAG, format, args);
95         break;
96     default:
97         ALOG_VA(LOG_DEBUG, CONSOLE_MESSAGE_LOG_TAG, format, args);
98         break;
99     }
100     va_end(args);
101 }
102 } // ClientModule