Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [0.6.3](https://github.com/rdkcentral/firebolt-cpp-client/compare/0.6.2...v0.6.3)
Comment thread
swethasukumarr marked this conversation as resolved.

### Fixed
- `Actions.intent` and `Actions.onIntent` now correctly handle a JSON object payload (`{"intent":"...","intentId":N}`) sent by the Firebolt backend. Previously the client failed to parse the response because it expected a plain string.

## [0.6.2](https://github.com/rdkcentral/firebolt-cpp-client/compare/v0.6.1...v0.6.2)

### Fixed
Expand Down
22 changes: 16 additions & 6 deletions docs/openrpc/the-spec/firebolt-open-rpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,22 @@
"params": [],
"result": {
"name": "intent",
"summary": "The current intent.",
"summary": "The current intent as a JSON document.",
"schema": {
"type": "string"
"type": "object",
"required": ["intent", "intentId"],
"properties": {
"intent": { "type": "string" },
"intentId": { "type": "integer" }
}
}
},
"examples": [
{
"name": "Get the current intent",
"result": {
"name": "Default Result",
"value": "launch"
"value": { "intent": "launch", "intentId": 1 }
}
}
]
Expand Down Expand Up @@ -107,9 +112,14 @@
],
"result": {
"name": "intent",
"summary": "The current intent.",
"summary": "The current intent as a JSON document.",
"schema": {
"type": "string"
"type": "object",
"required": ["intent", "intentId"],
"properties": {
"intent": { "type": "string" },
"intentId": { "type": "integer" }
}
}
},
"examples": [
Expand All @@ -123,7 +133,7 @@
],
"result": {
"name": "Default Result",
"value": "launch"
"value": { "intent": "launch", "intentId": 1 }
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions src/actions_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ ActionsImpl::ActionsImpl(Firebolt::Helpers::IHelper& helper)

Result<std::string> ActionsImpl::intent() const
{
return helper_.get<Firebolt::JSON::String, std::string>("Actions.intent");
return helper_.get<JsonData::JsonString, std::string>("Actions.intent");
}

Result<SubscriptionId> ActionsImpl::subscribeOnIntent(std::function<void(const std::string&)>&& notification)
{
return subscriptionManager_.subscribe<Firebolt::JSON::String>("Actions.onIntent", std::move(notification));
return subscriptionManager_.subscribe<JsonData::JsonString>("Actions.onIntent", std::move(notification));
}

Result<void> ActionsImpl::unsubscribe(SubscriptionId id)
Expand Down
14 changes: 14 additions & 0 deletions src/json_types/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ namespace Firebolt::Actions
namespace JsonData
{

// Serialises any JSON value (object, string, …) to its compact JSON text
// representation. Used for Actions.intent / Actions.onIntent whose wire format
// is the object {"intent":"...","intentId":N} but whose public C++ API surface
// exposes the whole document as a std::string, per the Firebolt 9 spec.
class JsonString : public Firebolt::JSON::NL_Json_Basic<std::string>
{
public:
void fromJson(const nlohmann::json& json) override { value_ = json.dump(); }
Comment thread
swethasukumarr marked this conversation as resolved.
std::string value() const override { return value_; }

private:
std::string value_;
};

} // namespace JsonData

} // namespace Firebolt::Actions
Expand Down
10 changes: 7 additions & 3 deletions test/component/actionsGeneratedTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@ TEST_F(ActionsGeneratedCTest, Intent)
{
auto result = Firebolt::IFireboltAccessor::Instance().ActionsInterface().intent();
ASSERT_TRUE(result) << toError(result);
EXPECT_EQ(*result, "launch");
auto parsed = nlohmann::json::parse(*result);
EXPECT_EQ(parsed.at("intent").get<std::string>(), "launch");
EXPECT_EQ(parsed.at("intentId").get<int>(), 1);
}

TEST_F(ActionsGeneratedCTest, SubscribeOnIntent)
{
auto id = Firebolt::IFireboltAccessor::Instance().ActionsInterface().subscribeOnIntent(
[&](const std::string& intent)
{
EXPECT_EQ(intent, "launch");
auto parsed = nlohmann::json::parse(intent);
EXPECT_EQ(parsed.at("intent").get<std::string>(), "launch");
EXPECT_EQ(parsed.at("intentId").get<int>(), 1);
{
std::lock_guard<std::mutex> lock(mtx);
eventReceived = true;
Expand All @@ -55,7 +59,7 @@ TEST_F(ActionsGeneratedCTest, SubscribeOnIntent)
ASSERT_TRUE(id) << toError(id);
verifyEventSubscription(id);

triggerEvent("Actions.onIntent", R"("launch")");
triggerEvent("Actions.onIntent", R"({"intent":"launch","intentId":1})");
verifyEventReceived(mtx, cv, eventReceived);

auto result = Firebolt::IFireboltAccessor::Instance().ActionsInterface().unsubscribe(id.value());
Expand Down
6 changes: 4 additions & 2 deletions test/unit/actionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ class ActionsUTest : public ::testing::Test, protected MockBase

TEST_F(ActionsUTest, Start)
{
mock_with_response("Actions.intent", "launch");
mock_with_response("Actions.intent", nlohmann::json({{"intent", "launch"}, {"intentId", 1}}));

auto result = actionsImpl_.intent();
ASSERT_TRUE(result) << "ActionsImpl::intent() returned an error";
EXPECT_EQ(*result, "launch");
auto parsed = nlohmann::json::parse(*result);
EXPECT_EQ(parsed.at("intent").get<std::string>(), "launch");
EXPECT_EQ(parsed.at("intentId").get<int>(), 1);
}

TEST_F(ActionsUTest, SubscribeOnIntent)
Expand Down
Loading