Sound Manager
libsoundmanager.hpp
Go to the documentation of this file.
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 #ifndef LIBSOUNDMANAGER_H
18 #define LIBSOUNDMANAGER_H
19 #include <audiomanagertypes.h>
20 #include <vector>
21 #include <map>
22 #include <string>
23 #include <json-c/json.h>
24 #include <systemd/sd-event.h>
25 extern "C"
26 {
27 #include <afb/afb-binding.h>
28 #include <afb/afb-wsj1.h>
29 #include <afb/afb-ws-client.h>
30 }
31 
32 using namespace am;
33 
34 const std::vector<std::string> api_list{
35  std::string("connect"),
36  std::string("disconnect"),
37  std::string("setVolume"),
38  std::string("volumeStep"),
39  std::string("setSinkMuteState"),
40  std::string("getListMainConnections"),
41  std::string("ackConnect"),
42  std::string("ackDisconnect"),
43  std::string("ackSetSourceState"),
44  std::string("registerSource"),
45  std::string("deregisterSource"),
46  std::string("subscribe"),
47  std::string("unsubscribe")
48 };
49 
50 const std::vector<std::string> event_list{
51  std::string("newMainConnection"),
52  std::string("volumeChanged"),
53  std::string("removedMainConnection"),
54  std::string("sinkMuteStateChanged"),
55  std::string("mainConnectionStateChanged"),
56  std::string("setRoutingReady"),
57  std::string("setRoutingRundown"),
58  std::string("asyncConnect"),
59  std::string("ackSetSourceState")
60 };
61 
63 {
64 private:
65  LibSoundmanager() = delete;
66 public:
67  LibSoundmanager(const int port, const std::string& token);
68  //LibSoundmanager(const std::string& uri);
69  ~LibSoundmanager();
70 
71  /* Method */
72  void register_callback(
73  void (*event_cb)(const std::string& event, struct json_object* event_contents),
74  void (*reply_cb)(struct json_object* reply_contents)
75  );
76  int run_eventloop();
77  int call(const std::string& verb, struct json_object* arg);
78  int call_sync(const std::string& verb, struct json_object* arg, struct json_object* ret);
79  int subscribe(const std::string& event_name);
80  int unsubscribe(const std::string& event_name);
81  /*const struct afb_wsj1* get_websocket_handler();
82  const struct sd_event* get_sd_event();*/
83 
84 private:
85  int initialize_websocket();
86  void (*onEvent)(const std::string& event, struct json_object* event_contents);
87  void (*onReply)(struct json_object* reply);
88 
89  struct afb_wsj1* sp_websock;
90  struct afb_wsj1_itf minterface;
91  sd_event* mploop;
92  std::string muri;
93  int mport = 12345;
94  std::string mtoken = "123456";
95 
96  am_Error_e connect(const am_sourceID_t sourceID, const am_sinkID_t sinkID, am::am_mainConnectionID_t& mainConnectionID);
97  am_Error_e disconnect(const am_mainConnectionID_t mainConnectionID);
98 
99 public:
100  /* Don't use/ Internal only */
101  void on_hangup(void *closure, struct afb_wsj1 *wsj);
102  void on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg);
103  void on_event(void *closure, const char *event, struct afb_wsj1_msg *msg);
104  void on_reply(void *closure, struct afb_wsj1_msg *msg);
105 };
106 #endif /* LIBSOUNDMANAGER_H */
const std::vector< std::string > api_list
const std::vector< std::string > event_list