Skip to content

Commit 8c74af1

Browse files
authored
RDKTV-24790: Failed to activate Messenger Plugin, response : ERROR UKNOWN_KEY (#4435) (#4450)
* RDKTV-24790: Failed to activate Messenger Plugin, response : ERROR UKNOWN_KEY Reason for change: Bring Messenger support in sprint branch . Test Procedure: Verify in Jenkin Build Risks: High Signed-off-by: Thamim Razith [email protected] (cherry picked from commit e396f9e)
1 parent a468e3a commit 8c74af1

9 files changed

+154
-37
lines changed

.github/workflows/unit-tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ on:
88

99
env:
1010
BUILD_TYPE: Debug
11-
THUNDER_REF: "39c82df24c7b4a4a10663cf527a3b289e7c1ceae"
12-
INTERFACES_REF: "8d3bd0ddd187c6104543699041ec53e1e186d49a"
11+
THUNDER_REF: "R2-v1.14"
12+
INTERFACES_REF: "R2-v1.14"
1313

1414

1515
jobs:

Messenger/CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ All notable changes to this RDK Service will be documented in this file.
1616

1717
* For more details, refer to [versioning](https://github.com/rdkcentral/rdkservices#versioning) section under Main README.
1818

19+
## [1.1.1]
20+
### Fixed
21+
- Failed to activate Messenger Plugin and bring the Messenger changes to main branch
22+
1923
## [1.0.1]
2024
### Fixed
2125
- Do not send roomupdate on unregister
@@ -26,4 +30,4 @@ All notable changes to this RDK Service will be documented in this file.
2630

2731
### Change
2832
- Reset API version to 1.0.0
29-
- Change README to inform how to update changelog and API version
33+
- Change README to inform how to update changelog and API version

Messenger/Messenger.cpp

+72-19
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "cryptalgo/Hash.h"
2323

2424
#define API_VERSION_NUMBER_MAJOR 1
25-
#define API_VERSION_NUMBER_MINOR 0
25+
#define API_VERSION_NUMBER_MINOR 1
2626
#define API_VERSION_NUMBER_PATCH 1
2727

2828
namespace WPEFramework {
@@ -49,44 +49,84 @@ namespace Plugin {
4949

5050
/* virtual */ const string Messenger::Initialize(PluginHost::IShell* service)
5151
{
52+
string message;
53+
5254
ASSERT(service != nullptr);
5355
ASSERT(_service == nullptr);
5456
ASSERT(_roomAdmin == nullptr);
5557
ASSERT(_roomIds.empty() == true);
5658
ASSERT(_rooms.empty() == true);
5759
ASSERT(_roomACL.empty() == true);
58-
60+
#ifdef USE_THUNDER_R4
61+
ASSERT(_connectionId == 0);
62+
#endif
5963
_service = service;
6064
_service->AddRef();
61-
65+
#ifdef USE_THUNDER_R4
66+
_service->Register(&_notification);
67+
#endif
6268
_roomAdmin = service->Root<Exchange::IRoomAdministrator>(_connectionId, 2000, _T("RoomMaintainer"));
63-
ASSERT(_roomAdmin != nullptr);
64-
65-
_roomAdmin->Register(this);
69+
if(_roomAdmin == nullptr) {
70+
message = _T("RoomMaintainer couldnt be instantiated");
71+
}
72+
else {
73+
_roomAdmin->Register(this);
74+
75+
}
6676

67-
return { };
77+
if(message.length() != 0) {
78+
Deinitialize(service);
79+
}
80+
return message;
6881
}
6982

7083
/* virtual */ void Messenger::Deinitialize(PluginHost::IShell* service)
7184
{
7285
ASSERT(service == _service);
7386

74-
// Exit all the rooms (if any) that were joined by this client
75-
for (auto& room : _roomIds) {
76-
room.second->Release();
77-
}
78-
79-
_roomIds.clear();
80-
81-
_roomAdmin->Unregister(this);
82-
_rooms.clear();
87+
#ifdef USE_THUNDER_R4
88+
_service->Unregister(&_notification);
89+
#endif
8390

84-
_roomAdmin->Release();
85-
_roomAdmin = nullptr;
91+
if(_roomAdmin != nullptr) {
92+
// Exit all the rooms (if any) that were joined by this client
93+
for (auto& room : _roomIds) {
94+
room.second->Release();
95+
}
8696

97+
_roomIds.clear();
98+
_roomAdmin->Unregister(this);
99+
_rooms.clear();
100+
101+
#ifdef USE_THUNDER_R4
102+
RPC::IRemoteConnection* connection(_service->RemoteConnection(_connectionId));
103+
#endif
104+
VARIABLE_IS_NOT_USED uint32_t result = _roomAdmin->Release();
105+
_roomAdmin = nullptr;
106+
107+
#ifdef USE_THUNDER_R4
108+
// It should have been the last reference we are releasing,
109+
// so it should end up in a DESCRUCTION_SUCCEEDED, if not we
110+
// are leaking...
111+
ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED);
112+
113+
// If this was running in a (container) proccess...
114+
if (connection != nullptr) {
115+
116+
// Lets trigger the cleanup sequence for
117+
// out-of-process code. Which will guard
118+
// that unwilling processes, get shot if
119+
// not stopped friendly :~)
120+
connection->Terminate();
121+
connection->Release();
122+
}
123+
#endif
124+
}
87125
_service->Release();
88126
_service = nullptr;
89-
127+
#ifdef USE_THUNDER_R4
128+
_connectionId = 0;
129+
#endif
90130
_roomACL.clear();
91131
}
92132

@@ -205,6 +245,19 @@ namespace Plugin {
205245
return roomId;
206246
}
207247

248+
#ifdef USE_THUNDER_R4
249+
void Messenger::Deactivated(RPC::IRemoteConnection* connection)
250+
{
251+
if (connection->Id() == _connectionId) {
252+
253+
ASSERT(_service != nullptr);
254+
255+
Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(_service,
256+
PluginHost::IShell::DEACTIVATED,
257+
PluginHost::IShell::FAILURE));
258+
}
259+
}
260+
#endif
208261
} // namespace Plugin
209262

210263
} // WPEFramework

Messenger/Messenger.h

+52-7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,39 @@ namespace Plugin {
3333
class Messenger : public PluginHost::IPlugin
3434
, public Exchange::IRoomAdministrator::INotification
3535
, public PluginHost::JSONRPCSupportsEventStatus {
36+
#ifdef USE_THUNDER_R4
37+
private:
38+
class Notification : public RPC::IRemoteConnection::INotification {
39+
public:
40+
Notification() = delete;
41+
Notification(const Notification&) = delete;
42+
Notification& operator=(const Notification&) = delete;
43+
44+
explicit Notification(Messenger* parent)
45+
: _parent(*parent)
46+
{
47+
ASSERT(parent != nullptr);
48+
}
49+
~Notification() override = default;
50+
51+
public:
52+
virtual void Activated(RPC::IRemoteConnection*)
53+
{
54+
}
55+
virtual void Deactivated(RPC::IRemoteConnection* connection)
56+
{
57+
_parent.Deactivated(connection);
58+
}
59+
60+
BEGIN_INTERFACE_MAP(Notification)
61+
INTERFACE_ENTRY(RPC::IRemoteConnection::INotification)
62+
END_INTERFACE_MAP
63+
64+
private:
65+
Messenger& _parent;
66+
};
67+
#endif
68+
3669
public:
3770
Messenger(const Messenger&) = delete;
3871
Messenger& operator=(const Messenger&) = delete;
@@ -45,6 +78,9 @@ namespace Plugin {
4578
, _roomAdmin(nullptr)
4679
, _roomIds()
4780
, _adminLock()
81+
#ifdef USE_THUNDER_R4
82+
, _notification(this)
83+
#endif
4884
{
4985
RegisterAll();
5086
}
@@ -55,9 +91,9 @@ namespace Plugin {
5591
}
5692

5793
// IPlugin methods
58-
virtual const string Initialize(PluginHost::IShell* service) override;
59-
virtual void Deinitialize(PluginHost::IShell* service) override;
60-
virtual string Information() const override { return { }; }
94+
const string Initialize(PluginHost::IShell* service) override;
95+
void Deinitialize(PluginHost::IShell* service) override;
96+
string Information() const override { return { }; }
6197

6298
// Notification handling
6399
class MsgNotification : public Exchange::IRoomAdministrator::IRoom::IMsgNotification {
@@ -71,7 +107,7 @@ namespace Plugin {
71107
{ /* empty */ }
72108

73109
// IRoom::Notification methods
74-
virtual void Message(const string& senderName, const string& message) override
110+
void Message(const string& senderName, const string& message) override
75111
{
76112
ASSERT(_messenger != nullptr);
77113
_messenger->MessageHandler(_roomId, senderName, message);
@@ -99,13 +135,13 @@ namespace Plugin {
99135
{ /* empty */}
100136

101137
// IRoom::ICallback methods
102-
virtual void Joined(const string& userName) override
138+
void Joined(const string& userName) override
103139
{
104140
ASSERT(_messenger != nullptr);
105141
_messenger->UserJoinedHandler(_roomId, userName);
106142
}
107143

108-
virtual void Left(const string& userName) override
144+
void Left(const string& userName) override
109145
{
110146
ASSERT(_messenger != nullptr);
111147
_messenger->UserLeftHandler(_roomId, userName);
@@ -171,6 +207,9 @@ namespace Plugin {
171207
}
172208

173209
private:
210+
#ifdef USE_THUNDER_R4
211+
void Deactivated(RPC::IRemoteConnection* connection);
212+
#endif
174213
string GenerateRoomId(const string& roomName, const string& userName);
175214
bool SubscribeUserUpdate(const string& roomId, bool subscribe);
176215

@@ -183,15 +222,21 @@ namespace Plugin {
183222
void event_roomupdate(const string& room, const JsonData::Messenger::RoomupdateParamsData::ActionType& action);
184223
void event_userupdate(const string& id, const string& user, const JsonData::Messenger::UserupdateParamsData::ActionType& action);
185224
void event_message(const string& id, const string& user, const string& message);
225+
#ifndef USE_THUNDER_R4
186226
bool CheckToken(const string& token, const string& method, const string& parameters);
187-
227+
#else
228+
PluginHost::JSONRPC::classification CheckToken(const string& token, const string& method, const string& parameters);
229+
#endif
188230
uint32_t _connectionId;
189231
PluginHost::IShell* _service;
190232
Exchange::IRoomAdministrator* _roomAdmin;
191233
std::map<string, Exchange::IRoomAdministrator::IRoom*> _roomIds;
192234
std::set<string> _rooms;
193235
std::map<string, std::list<string>> _roomACL;
194236
mutable Core::CriticalSection _adminLock;
237+
#ifdef USE_THUNDER_R4
238+
Core::Sink<Notification> _notification;
239+
#endif
195240
}; // class Messenger
196241

197242
} // namespace Plugin

Messenger/Messenger.vcxproj

+9-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<ItemGroup>
2222
<ClCompile Include="Messenger.cpp" />
2323
<ClCompile Include="MessengerJsonRpc.cpp" />
24+
<ClCompile Include="MessengerSecurity.cpp" />
2425
<ClCompile Include="Module.cpp" />
2526
<ClCompile Include="RoomMaintainer.cpp" />
2627
</ItemGroup>
@@ -42,26 +43,26 @@
4243
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
4344
<ConfigurationType>DynamicLibrary</ConfigurationType>
4445
<UseDebugLibraries>true</UseDebugLibraries>
45-
<PlatformToolset>v142</PlatformToolset>
46+
<PlatformToolset>v143</PlatformToolset>
4647
<CharacterSet>MultiByte</CharacterSet>
4748
</PropertyGroup>
4849
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
4950
<ConfigurationType>DynamicLibrary</ConfigurationType>
5051
<UseDebugLibraries>false</UseDebugLibraries>
51-
<PlatformToolset>v142</PlatformToolset>
52+
<PlatformToolset>v143</PlatformToolset>
5253
<WholeProgramOptimization>true</WholeProgramOptimization>
5354
<CharacterSet>MultiByte</CharacterSet>
5455
</PropertyGroup>
5556
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
5657
<ConfigurationType>DynamicLibrary</ConfigurationType>
5758
<UseDebugLibraries>true</UseDebugLibraries>
58-
<PlatformToolset>v142</PlatformToolset>
59+
<PlatformToolset>v143</PlatformToolset>
5960
<CharacterSet>MultiByte</CharacterSet>
6061
</PropertyGroup>
6162
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
6263
<ConfigurationType>DynamicLibrary</ConfigurationType>
6364
<UseDebugLibraries>false</UseDebugLibraries>
64-
<PlatformToolset>v142</PlatformToolset>
65+
<PlatformToolset>v143</PlatformToolset>
6566
<WholeProgramOptimization>true</WholeProgramOptimization>
6667
<CharacterSet>MultiByte</CharacterSet>
6768
</PropertyGroup>
@@ -120,6 +121,7 @@
120121
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;SECURITYOFFICER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
121122
<ConformanceMode>true</ConformanceMode>
122123
<AdditionalIncludeDirectories>$(FrameworkPath);$(ContractsPath);$(WindowsPath);$(WindowsPath)zlib</AdditionalIncludeDirectories>
124+
<UseStandardPreprocessor>true</UseStandardPreprocessor>
123125
</ClCompile>
124126
<Link>
125127
<SubSystem>Windows</SubSystem>
@@ -136,6 +138,7 @@
136138
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;SECURITYOFFICER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
137139
<ConformanceMode>true</ConformanceMode>
138140
<AdditionalIncludeDirectories>$(FrameworkPath);$(ContractsPath);$(WindowsPath);$(WindowsPath)zlib</AdditionalIncludeDirectories>
141+
<UseStandardPreprocessor>true</UseStandardPreprocessor>
139142
</ClCompile>
140143
<Link>
141144
<SubSystem>Windows</SubSystem>
@@ -154,6 +157,7 @@
154157
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;SECURITYOFFICER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
155158
<ConformanceMode>true</ConformanceMode>
156159
<AdditionalIncludeDirectories>$(FrameworkPath);$(ContractsPath);$(WindowsPath);$(WindowsPath)zlib</AdditionalIncludeDirectories>
160+
<UseStandardPreprocessor>true</UseStandardPreprocessor>
157161
</ClCompile>
158162
<Link>
159163
<SubSystem>Windows</SubSystem>
@@ -174,6 +178,7 @@
174178
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
175179
<ConformanceMode>true</ConformanceMode>
176180
<AdditionalIncludeDirectories>$(FrameworkPath);$(ContractsPath);$(WindowsPath);$(WindowsPath)zlib</AdditionalIncludeDirectories>
181+
<UseStandardPreprocessor>true</UseStandardPreprocessor>
177182
</ClCompile>
178183
<Link>
179184
<SubSystem>Windows</SubSystem>

Messenger/Messenger.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
<ClCompile Include="RoomMaintainer.cpp">
2222
<Filter>Source Files</Filter>
2323
</ClCompile>
24+
<ClCompile Include="MessengerSecurity.cpp">
25+
<Filter>Source Files</Filter>
26+
</ClCompile>
2427
</ItemGroup>
2528
<ItemGroup>
2629
<ClInclude Include="Module.h">

Messenger/MessengerJsonRpc.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
* limitations under the License.
1818
*/
1919

20+
#include "Module.h"
2021
#include <interfaces/json/JsonData_Messenger.h>
2122
#include "Messenger.h"
22-
#include "Module.h"
2323

2424
namespace WPEFramework {
2525

@@ -32,7 +32,7 @@ namespace Plugin {
3232

3333
void Messenger::RegisterAll()
3434
{
35-
RegisterEventStatusListener(_T("roomupdate"), [this](const string& client, Status status) {
35+
RegisterEventStatusListener(_T("roomupdate"), [this](const string&, Status status) {
3636
if (status == Status::registered) {
3737
// Notify of all rooms created to date.
3838
for (const string& room : _rooms) {

0 commit comments

Comments
 (0)