-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAVS.h
228 lines (189 loc) · 7.24 KB
/
AVS.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2020 Metrological
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "Module.h"
#include <interfaces/IAVSClient.h>
#include <interfaces/JAVSController.h>
#include <AVS/SampleApp/SampleApplicationReturnCodes.h>
#if defined(ENABLE_SMART_SCREEN_SUPPORT)
#include "SmartScreen/SmartScreen.h"
#endif
namespace WPEFramework {
namespace Plugin {
class AVS
: public PluginHost::IPlugin,
public PluginHost::JSONRPC {
public:
AVS(const AVS&) = delete;
AVS& operator=(const AVS&) = delete;
private:
class ConnectionNotification : public RPC::IRemoteConnection::INotification {
public:
ConnectionNotification() = delete;
ConnectionNotification(const ConnectionNotification&) = delete;
ConnectionNotification& operator=(const ConnectionNotification&) = delete;
public:
explicit ConnectionNotification(AVS* parent)
: _parent(*parent)
{
ASSERT(parent != nullptr);
}
virtual ~ConnectionNotification() = default;
BEGIN_INTERFACE_MAP(ConnectionNotification)
INTERFACE_ENTRY(RPC::IRemoteConnection::INotification)
END_INTERFACE_MAP
public:
void Activated(RPC::IRemoteConnection* connection) override
{
_parent.Activated(connection);
}
void Deactivated(RPC::IRemoteConnection* connection) override
{
_parent.Deactivated(connection);
}
private:
AVS& _parent;
};
class AudiosourceNotification : public PluginHost::IPlugin::INotification {
public:
AudiosourceNotification() = delete;
AudiosourceNotification(const AudiosourceNotification&) = delete;
AudiosourceNotification& operator=(const AudiosourceNotification&) = delete;
public:
explicit AudiosourceNotification(AVS* parent)
: _parent(*parent)
{
ASSERT(parent != nullptr);
}
~AudiosourceNotification() = default;
BEGIN_INTERFACE_MAP(AudiosourceNotification)
INTERFACE_ENTRY(PluginHost::IPlugin::INotification)
END_INTERFACE_MAP
public:
void StateChange(WPEFramework::PluginHost::IShell* service) override
{
if (!service) {
TRACE_L1(_T("Service is a nullptr!"));
return;
}
if (service->Callsign() == _parent._audiosourceName) {
if (_parent._AVSClient) {
_parent._AVSClient->StateChange(service);
}
}
}
private:
AVS& _parent;
};
class DialogueNotification : public Exchange::IAVSController::INotification {
public:
DialogueNotification() = delete;
DialogueNotification(const DialogueNotification&) = delete;
DialogueNotification& operator=(const DialogueNotification&) = delete;
public:
explicit DialogueNotification(AVS* parent)
: _parent(*parent)
{
ASSERT(parent != nullptr);
}
~DialogueNotification() = default;
BEGIN_INTERFACE_MAP(DialogueNotification)
INTERFACE_ENTRY(Exchange::IAVSController::INotification)
END_INTERFACE_MAP
public:
void DialogueStateChange(const Exchange::IAVSController::INotification::dialoguestate state) override
{
Exchange::JAVSController::Event::DialogueStateChange(_parent, state);
}
private:
AVS& _parent;
};
class Config : public Core::JSON::Container {
public:
Config(const Config&) = delete;
Config& operator=(const Config&) = delete;
public:
Config()
: Core::JSON::Container()
, Audiosource()
, AlexaClientConfig()
, SmartScreenConfig()
, LogLevel()
, KWDModelsPath()
, EnableSmartScreen()
, EnableKWD()
{
Add(_T("audiosource"), &Audiosource);
Add(_T("alexaclientconfig"), &AlexaClientConfig);
Add(_T("smartscreenconfig"), &SmartScreenConfig);
Add(_T("loglevel"), &LogLevel);
Add(_T("kwdmodelspath"), &KWDModelsPath);
Add(_T("enablesmartscreen"), &EnableSmartScreen);
Add(_T("enablekwd"), &EnableKWD);
}
~Config() = default;
public:
Core::JSON::String Audiosource;
Core::JSON::String AlexaClientConfig;
Core::JSON::String SmartScreenConfig;
Core::JSON::String LogLevel;
Core::JSON::String KWDModelsPath;
Core::JSON::Boolean EnableSmartScreen;
Core::JSON::Boolean EnableKWD;
};
public:
static constexpr uint32_t ImplWaitTime = 2000;
AVS()
: _AVSClient(nullptr)
, _controller(nullptr)
, _service(nullptr)
, _audiosourceName()
, _connectionId(0)
, _audiosourceNotification(this)
, _connectionNotification(this)
, _dialogueNotification(this)
{
}
virtual ~AVS()
{
}
BEGIN_INTERFACE_MAP(AVS)
INTERFACE_ENTRY(PluginHost::IPlugin)
INTERFACE_ENTRY(PluginHost::IDispatcher)
END_INTERFACE_MAP
// IPlugin methods
// -------------------------------------------------------------------------------------------------------
const string Initialize(PluginHost::IShell* service) override;
void Deinitialize(PluginHost::IShell* service) override;
string Information() const override;
private:
void Activated(RPC::IRemoteConnection* connection);
void Deactivated(RPC::IRemoteConnection* connection);
const string CreateInstance(const string& name, const Config& config);
Exchange::IAVSClient* _AVSClient;
Exchange::IAVSController* _controller;
PluginHost::IShell* _service;
string _audiosourceName;
uint32_t _connectionId;
Core::Sink<AudiosourceNotification> _audiosourceNotification;
Core::Sink<ConnectionNotification> _connectionNotification;
Core::Sink<DialogueNotification> _dialogueNotification;
};
} // namespace Plugin
} // namespace WPEFramework