Add sample application[phone]
[staging/soundmanager.git] / sample / phone / app / libsmwrapper.h
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 #ifndef SIGNALER_H
17 #define SIGNALER_H
18
19  #include <QObject>
20  #include <QVariant>
21  #include <QJsonDocument>
22  #include <QtCore/QJsonObject>
23  #include <libsoundmanager/libsoundmanager.hpp>
24  #include <QString>
25  #include <string>
26
27
28 class LibSMWrapper : public QObject
29 {
30     Q_OBJECT
31 public: // method
32     explicit LibSMWrapper(QObject *parent = nullptr);
33     LibSMWrapper(const int port, const QString& token, QObject *parent = nullptr);
34     ~LibSMWrapper();
35
36     void wrapper_registerCallback(
37         void (*event_func)(const std::string& event, struct json_object* event_contents), 
38         void (*reply_func)(struct json_object* reply_contents)
39     );
40     void subscribe(const QString event_name);
41     void unsubscribe(const QString event_name);
42     void run_eventloop();
43
44     void emit_event(const QString &event, const QJsonObject &msg);
45     void emit_reply(const QJsonObject &msg);
46 public slots:
47     int call(const QString &verb, const QJsonObject &arg);
48     void print(const QString &str);
49 signals:
50     void smEvent(const QVariant &event, const QVariant &msg);
51     void smReply(const QVariant &msg);
52
53 private:
54     LibSoundmanager* libsm;
55 };
56
57
58 #endif /*SIGNALER_H*/