Skip to content
This repository was archived by the owner on Jul 16, 2020. It is now read-only.

Comments

[Batch - PART1] Handle control update event#81

Merged
JoshSnider merged 2 commits intomasterfrom
feat/control-updates
Jun 20, 2018
Merged

[Batch - PART1] Handle control update event#81
JoshSnider merged 2 commits intomasterfrom
feat/control-updates

Conversation

@Mobius5150
Copy link
Contributor

Add method handlers and update the local scenes cache when receiving an onControlUpdate event.

Stacked PR for batch updates.

Add method handlers and update the scenes cache when receiving an
onControlUpdate event

int cache_new_control(interactive_session_internal& session, const char* sceneId, interactive_control& control, rapidjson::Value& controlJson)
{
if (session.controls.find(control.id) != session.controls.end())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to lock the scenesMutex before calling find on controls or scenes.

std::shared_lock<std::shared_mutex> l(session->scenesMutex);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll snag this one.

{
std::string scenePointer = "/" + std::string(RPC_PARAM_SCENES) + "/" + std::to_string(sceneIndex++);
auto thisSceneId = scene[RPC_SCENE_ID].GetString();
if (nullptr != sceneId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this nullptr check because SCENE_ID wouldn't exist for some reason? If that's at all possible you should actually check if the property exists first using HasMember.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry - confusing names. sceneId is an argument to a function, thisSceneId is a local variable within the for loop.

Purpose is that you can optionally specify a specific scene to update the control pointers for instead of blindly updating them for all scenes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also with regards to the HasMember check it depends how defensive we want to be - in other places in the code we're trusting these fields to be there (and according to the current protocol they should) so I don't check that the member exists here because this value only gets updated with an object from the socket

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right yeah I misread that.
Great, if the protocol should have the field we don't need an extra check.

{
std::string scenePointer = "/" + std::string(RPC_PARAM_SCENES) + "/" + std::to_string(sceneIndex++);
auto thisSceneId = scene[RPC_SCENE_ID].GetString();
if (nullptr != sceneId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right yeah I misread that.
Great, if the protocol should have the field we don't need an extra check.


int cache_new_control(interactive_session_internal& session, const char* sceneId, interactive_control& control, rapidjson::Value& controlJson)
{
if (session.controls.find(control.id) != session.controls.end())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll snag this one.

@JoshSnider JoshSnider merged commit ee32812 into master Jun 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants