@@ -51,11 +51,9 @@ namespace WPEFramework
51
51
{
52
52
SERVICE_REGISTRATION (HdmiCecSource, API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH);
53
53
54
- HdmiCecSource* HdmiCecSource::_instance = nullptr ;
55
-
56
54
const string HdmiCecSource::Initialize (PluginHost::IShell *service)
57
55
{
58
- LOGWARN (" Initlaizing CEC_2 " );
56
+ LOGWARN (" Initlaizing HdmiCecSource plugin \n " );
59
57
60
58
profileType = searchRdkProfile ();
61
59
@@ -65,36 +63,47 @@ namespace WPEFramework
65
63
return (std::string (" Not supported" ));
66
64
}
67
65
68
- string msg;
66
+ string msg = " " ;
67
+
68
+ ASSERT (nullptr != service);
69
+ ASSERT (nullptr == _service);
70
+ ASSERT (nullptr == _hdmiCecSource);
71
+ ASSERT (0 == _connectionId);
72
+
73
+
69
74
_service = service;
70
75
_service->AddRef ();
71
76
_service->Register (&_notification);
72
- HdmiCecSource::_instance = this ;
73
77
_hdmiCecSource = _service->Root <Exchange::IHdmiCecSource>(_connectionId, 5000 , _T (" HdmiCecSourceImplementation" ));
74
78
75
79
if (nullptr != _hdmiCecSource)
76
80
{
77
81
_hdmiCecSource->Configure (service);
78
82
_hdmiCecSource->Register (&_notification);
79
83
Exchange::JHdmiCecSource::Register (*this , _hdmiCecSource);
80
- msg = " HdmiCecSource plugin is available" ;
81
84
LOGINFO (" HdmiCecSource plugin is available. Successfully activated HdmiCecSource Plugin" );
82
85
}
83
86
else
84
87
{
85
88
msg = " HdmiCecSource plugin is not available" ;
86
89
LOGINFO (" HdmiCecSource plugin is not available. Failed to activate HdmiCecSource Plugin" );
87
- return msg;
90
+ }
91
+
92
+ if (0 != msg.length ())
93
+ {
94
+ Deinitialize (service);
88
95
}
89
96
90
97
// On success return empty, to indicate there is no error text.
91
98
return msg;
92
99
}
93
100
94
101
95
- void HdmiCecSource::Deinitialize (PluginHost::IShell* /* service */ )
102
+ void HdmiCecSource::Deinitialize (PluginHost::IShell* service)
96
103
{
97
- LOGWARN (" Deinitialize CEC_2" );
104
+ LOGWARN (" Deinitialize HdmiCecSource plugin \n " );
105
+
106
+ ASSERT (nullptr != service);
98
107
99
108
100
109
profileType = searchRdkProfile ();
@@ -116,12 +125,48 @@ namespace WPEFramework
116
125
}
117
126
HdmiCecSource::_notification.OnActiveSourceStatusUpdated (false );
118
127
119
- HdmiCecSource::_instance = nullptr ;
128
+ if (nullptr != _hdmiCecSource)
129
+ {
130
+ _hdmiCecSource->Unregister (&_notification);
131
+ Exchange::JHdmiCecSource::Unregister (*this , _hdmiCecSource);
132
+ _hdmiCecSource->Release ();
133
+ _hdmiCecSource = nullptr ;
134
+
135
+ RPC::IRemoteConnection* connection = _service->RemoteConnection (_connectionId);
136
+ if (connection != nullptr )
137
+ {
138
+ try {
139
+ connection->Terminate ();
140
+ }
141
+ catch (const std::exception& e)
142
+ {
143
+ std::string errorMessage = " Failed to terminate connection: " ;
144
+ errorMessage += e.what ();
145
+ LOGWARN (" %s" ,errorMessage.c_str ());
146
+ }
147
+
148
+ connection->Release ();
149
+ }
150
+ }
151
+
152
+ _connectionId = 0 ;
153
+ _service->Release ();
154
+ _service = nullptr ;
155
+ LOGINFO (" HdmiCecSource plugin is deactivated. Successfully deactivated HdmiCecSource Plugin" );
120
156
}
121
157
122
158
string HdmiCecSource::Information () const
123
159
{
124
- return (string ());
160
+ return (" This HdmiCecSource PLugin Facilitates the HDMI CEC Source Control" );
161
+ }
162
+
163
+ void HdmiCecSource::Deactivated (RPC::IRemoteConnection* connection)
164
+ {
165
+ if (connection->Id () == _connectionId)
166
+ {
167
+ ASSERT (_service != nullptr );
168
+ Core::IWorkerPool::Instance ().Submit (PluginHost::IShell::Job::Create (_service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::FAILURE));
169
+ }
125
170
}
126
171
127
172
} // namespace Plugin
0 commit comments