[Release] wrt_0.8.274
[platform/framework/web/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 <string>
23 #include <dpl/log/log.h>
24 #include <dpl/exception.h>
25
26 #include <appsvc.h>
27 #include <bundle.h>
28
29 namespace ClientModule {
30 namespace {
31 const char* const KEY_DEBUG = "debug";
32 const char* const KEY_PORT = "port";
33 const char* const VALUE_TRUE = "true";
34 }
35
36 bool IDESupport::getDebugMode(bundle* b)
37 {
38     if (!b) {
39         LogWarning("bundle is empty");
40         return false;
41     }
42
43     const char* value = bundle_get_val(b, KEY_DEBUG);
44     if (value != NULL && !strcmp(value, VALUE_TRUE)) {
45         return true;
46     } else {
47         return false;
48     }
49 }
50
51 bool IDESupport::sendReply(bundle* b, unsigned int portNum)
52 {
53     bundle* request = NULL;
54     if (appsvc_create_result_bundle(b, &request) != APPSVC_RET_OK) {
55         LogWarning("Fail to create result bundle");
56         return false;
57     }
58
59     char port[10] = {0,};
60     sprintf(port, "%u", portNum);
61     if (appsvc_add_data(request, KEY_PORT, port) != APPSVC_RET_OK) {
62         LogWarning("Fail to add data");
63         bundle_free(request);
64         return false;
65     }
66
67     if (appsvc_send_result(request, APPSVC_RES_OK) != APPSVC_RET_OK) {
68         LogWarning("Fail to send result");
69         bundle_free(request);
70         return false;
71     }
72
73     bundle_free(request);
74     return true;
75 }
76
77 } // ClientModule