Add a wrapper library of libhomescreen
[src/libqthomescreen.git] / src / qlibhomescreen.cpp
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
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 #include "qlibhomescreen.h"
18 #include <QJsonDocument>
19 #include <QJsonObject>
20 using namespace std;
21
22 #define _POPUPREPLY "on_screen_reply"
23 #define _REQ_POPUP_MESSAGE "on_screen_message"
24 #define _TAPSHORTCUT "tap_shortcut"
25 #define _KEY_DATA "data"
26 #define _KEY_APPLICATION_DATA "application_name"
27 #define _KEY_REPLY_MESSAGE "reply_message"
28 #define _KEY_REQUEST_MESSAGE "display_message"
29
30 static QLibHomeScreen* myThis;
31
32 // Note: qlibhomescreen will be integrated to libqtappfw
33
34 QLibHomeScreen::QLibHomeScreen(QObject *parent) :
35     QObject(parent),
36     mp_hs(NULL)
37 {
38
39 }
40
41 QLibHomeScreen::~QLibHomeScreen()
42 {
43     if (mp_hs != NULL) {
44         delete mp_hs;
45     }
46 }
47
48 void QLibHomeScreen::init(int port, const QString &token)
49 {
50     string ctoken = token.toStdString();
51     mp_hs = new LibHomeScreen();
52     mp_hs->init(port, ctoken.c_str());
53
54     myThis = this;
55 }
56
57 int QLibHomeScreen::onScreenMessage(const QString &message)
58 {
59     string str = message.toStdString();
60     return mp_hs->onScreenMessage(str.c_str());
61 }
62
63 int QLibHomeScreen::subscribe(const QString &evetName)
64 {
65     string str = evetName.toStdString();
66     return mp_hs->subscribe(str);
67 }
68
69 int QLibHomeScreen::unsubscribe(const QString &evetName)
70 {
71     string str = evetName.toStdString();
72     return mp_hs->unsubscribe(str);
73 }
74
75 void QLibHomeScreen::set_event_handler(enum QEventType et, handler_fun f)
76 {
77     LibHomeScreen::EventType hs_et = (LibHomeScreen::EventType)et;
78     return this->mp_hs->set_event_handler(hs_et, std::move(f));
79 }