forked from rdkcentral/rdkservices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextToSpeech.cpp
131 lines (106 loc) · 3.88 KB
/
TextToSpeech.cpp
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
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2020 RDK Management
*
* 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.
*/
#include "TextToSpeech.h"
#define API_VERSION_NUMBER_MAJOR 1
#define API_VERSION_NUMBER_MINOR 0
#define API_VERSION_NUMBER_PATCH 5
#define API_VERSION_NUMBER 1
namespace WPEFramework {
namespace {
static Plugin::Metadata<Plugin::TextToSpeech> metadata(
// Version (Major, Minor, Patch)
API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH,
// Preconditions
{},
// Terminations
{},
// Controls
{}
);
}
namespace Plugin {
/*
*Register TextToSpeech module as wpeframework plugin
**/
SERVICE_REGISTRATION(TextToSpeech, API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH);
const string TextToSpeech::Initialize(PluginHost::IShell* service)
{
ASSERT(_service == nullptr);
_connectionId = 0;
_service = service;
_skipURL = static_cast<uint8_t>(_service->WebPrefix().length());
_service->Register(&_notification);
_tts = _service->Root<Exchange::ITextToSpeech>(_connectionId, 5000, _T("TextToSpeechImplementation"));
std::string message;
if(_tts != nullptr) {
ASSERT(_connectionId != 0);
_tts->Configure(_service);
_tts->Register(&_notification);
RegisterAll();
} else {
message = _T("TextToSpeech could not be instantiated.");
_service->Unregister(&_notification);
_service = nullptr;
}
return message;
}
void TextToSpeech::Deinitialize(PluginHost::IShell* service)
{
ASSERT(_service == service);
ASSERT(_tts != nullptr);
if (!_tts)
return;
_tts->Unregister(&_notification);
_service->Unregister(&_notification);
if(_tts->Release() != Core::ERROR_DESTRUCTION_SUCCEEDED) {
ASSERT(_connectionId != 0);
TRACE_L1("TextToSpeech Plugin is not properly destructed. %d", _connectionId);
RPC::IRemoteConnection* connection(_service->RemoteConnection(_connectionId));
// The process can disappear in the meantime...
if (connection != nullptr) {
// But if it did not dissapear in the meantime, forcefully terminate it. Shoot to kill :-)
connection->Terminate();
connection->Release();
}
}
// Deinitialize what we initialized..
_service = nullptr;
_tts = nullptr;
m_AclCalled = false;
}
TextToSpeech::TextToSpeech()
: PluginHost::JSONRPC()
, _notification(this)
, _apiVersionNumber(API_VERSION_NUMBER)
, m_AclCalled(false)
{
}
TextToSpeech::~TextToSpeech()
{
}
void TextToSpeech::Deactivated(RPC::IRemoteConnection* connection)
{
if (connection->Id() == _connectionId) {
ASSERT(_service != nullptr);
TTSLOG_WARNING("TextToSpeech::Deactivated - %p", this);
Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(_service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::FAILURE));
}
}
} // namespace Plugin
} // namespace WPEFramework