-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: gateway abstraction layer for bidirectional communication over ws
- Loading branch information
1 parent
4055fde
commit b450cb9
Showing
15 changed files
with
388 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2023 Comcast Cable Communications Management, LLC | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "Gateway.h" | ||
|
||
namespace FireboltSDK { | ||
|
||
Gateway* Gateway::_instance = nullptr; | ||
|
||
Gateway& Gateway::Instance() | ||
{ | ||
if (_instance == nullptr) { | ||
_instance = new Gateway(new GatewayImpl()); | ||
ASSERT(_instance != nullptr); | ||
} | ||
return *_instance; | ||
} | ||
|
||
void Gateway::Dispose() | ||
{ | ||
ASSERT(_instance != nullptr); | ||
if (_instance != nullptr) { | ||
delete _instance; | ||
_instance = nullptr; | ||
} | ||
} | ||
|
||
Gateway::Gateway(GatewayImpl *implementation) | ||
: _implementation(implementation) | ||
{ | ||
_instance = this; | ||
} | ||
|
||
Gateway::~Gateway() | ||
{ | ||
delete _implementation; | ||
} | ||
|
||
void Gateway::Configure(Transport<WPEFramework::Core::JSON::IElement>* transport) | ||
{ | ||
_implementation->Configure(transport); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2024 Comcast Cable Communications Management, LLC | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#pragma once | ||
|
||
#ifndef MODULE_NAME | ||
#define MODULE_NAME OpenRPCNativeSDK | ||
#endif | ||
#include <core/core.h> | ||
#include "error.h" | ||
|
||
#include "Transport/Transport.h" | ||
|
||
#include <functional> | ||
#include <string> | ||
|
||
#ifdef GATEWAY_BIDIRECTIONAL | ||
#include "gateway_impl_bidi.h" | ||
#else | ||
#include "gateway_impl_unidi.h" | ||
#endif | ||
|
||
namespace FireboltSDK | ||
{ | ||
using EventCallback = std::function<void(const std::string & /* eventName */, const JsonObject & /* parameters */, Firebolt::Error /* error */)>; | ||
|
||
class Gateway | ||
{ | ||
static Gateway *_instance; | ||
|
||
GatewayImpl *_implementation; | ||
|
||
private: | ||
Gateway(GatewayImpl *implementation); | ||
|
||
public: | ||
Gateway(const Gateway&) = delete; | ||
Gateway& operator=(const Gateway&) = delete; | ||
~Gateway(); | ||
|
||
static Gateway& Instance(); | ||
static void Dispose(); | ||
|
||
void Configure(Transport<WPEFramework::Core::JSON::IElement>* transport); | ||
|
||
template <typename RESPONSETYPE> | ||
Firebolt::Error Request(const std::string &method, const JsonObject ¶meters, RESPONSETYPE &response) | ||
{ | ||
return _implementation->Request(method, parameters, response); | ||
} | ||
|
||
template <typename RESPONSETYPE> | ||
Firebolt::Error Subscribe(const string& event, const string& parameters, RESPONSETYPE& response) | ||
{ | ||
return _implementation->Subscribe(event, parameters, response); | ||
} | ||
|
||
Firebolt::Error Unsubscribe(const string& event, const string& parameters) | ||
{ | ||
return _implementation->Unsubscribe(event, parameters); | ||
} | ||
|
||
}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2024 Comcast Cable Communications Management, LLC | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#pragma once | ||
|
||
#include "error.h" | ||
#include "Accessor/Accessor.h" | ||
|
||
#include <string> | ||
#include <stdio.h> | ||
|
||
namespace FireboltSDK | ||
{ | ||
|
||
using EventCallback = std::function<void(const std::string & /* eventName */, const JsonObject & /* parameters */, Firebolt::Error /* error */)>; | ||
|
||
class Client | ||
{ | ||
Firebolt::Error Request(const std::string &method, const JsonObject ¶meters) | ||
{ | ||
return Firebolt::Error::None; | ||
} | ||
}; | ||
|
||
class Server | ||
{ | ||
Firebolt::Error Subscribe(const std::string &eventName, const EventCallback &callback) | ||
{ | ||
return Firebolt::Error::None; | ||
} | ||
|
||
Firebolt::Error Request(const std::string &methodName, const JsonObject ¶meters) | ||
{ | ||
return Firebolt::Error::None; | ||
} | ||
|
||
Firebolt::Error Notify() | ||
{ | ||
return Firebolt::Error::None; | ||
} | ||
}; | ||
|
||
class Provider | ||
{ | ||
// TBD | ||
}; | ||
|
||
class GatewayImpl : public Gateway | ||
{ | ||
Client _client; | ||
Server _server; | ||
|
||
void receive(const JsonObject &response) | ||
{ | ||
|
||
} | ||
|
||
public: | ||
Firebolt::Error Request(const std::string &method, const JsonObject ¶meters, JsonObject &response) | ||
{ | ||
return _client.Request(method, parameters); | ||
} | ||
|
||
virtual Firebolt::Error Subscribe(const std::string &eventName, const EventCallback &callback) | ||
{ | ||
return _server.Subscribe(eventName, callback); | ||
} | ||
|
||
virtual Firebolt::Error Unsubsribe(const std::string &eventName) | ||
{ | ||
return Firebolt::Error::None; | ||
} | ||
|
||
virtual Firebolt::Error Provide(const std::string &interfaceName, const Provider &provider) | ||
{ | ||
return Firebolt::Error::None; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright 2024 Comcast Cable Communications Management, LLC | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
#pragma once | ||
|
||
#ifndef MODULE_NAME | ||
#define MODULE_NAME OpenRPCNativeSDK | ||
#endif | ||
#include <core/core.h> | ||
#include "error.h" | ||
|
||
#include "Transport/Transport.h" | ||
|
||
#include <string> | ||
#include <stdio.h> | ||
|
||
namespace FireboltSDK | ||
{ | ||
|
||
using EventCallback = std::function<void(const std::string & /* eventName */, const JsonObject & /* parameters */, Firebolt::Error /* error */)>; | ||
|
||
class GatewayImpl | ||
{ | ||
|
||
Transport<WPEFramework::Core::JSON::IElement>* _transport; | ||
|
||
public: | ||
GatewayImpl() | ||
{ | ||
} | ||
|
||
public: | ||
|
||
void Configure(Transport<WPEFramework::Core::JSON::IElement>* transport) | ||
{ | ||
_transport = transport; | ||
} | ||
|
||
template <typename RESPONSETYPE> | ||
Firebolt::Error Request(const std::string &method, const JsonObject ¶meters, RESPONSETYPE &response) | ||
{ | ||
if (_transport == nullptr) { | ||
return Firebolt::Error::NotConnected; | ||
} | ||
return _transport->Invoke(method, parameters, response); | ||
} | ||
|
||
template <typename RESPONSETYPE> | ||
Firebolt::Error Subscribe(const string& event, const string& parameters, RESPONSETYPE& response) | ||
{ | ||
if (_transport == nullptr) { | ||
return Firebolt::Error::NotConnected; | ||
} | ||
return _transport->Subscribe(event, parameters, response); | ||
} | ||
|
||
Firebolt::Error Unsubscribe(const string& event, const string& parameters) | ||
{ | ||
if (_transport == nullptr) { | ||
return Firebolt::Error::NotConnected; | ||
} | ||
return _transport->Unsubscribe(event, parameters); | ||
} | ||
|
||
// virtual Firebolt::Error Provide(const std::string &interfaceName, const Provider &provider) | ||
// { | ||
// return Firebolt::Error::None; | ||
// } | ||
}; | ||
} | ||
|
Oops, something went wrong.