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

Commit

Permalink
feat(batch): Initial commit for batch operations
Browse files Browse the repository at this point in the history
Exposing a new batch operations API that allows you to batch updates to
multiple objects (e.g. controls, participants) and multiple property
updates on a single object. This API also allows for the use of custom
data including nested objects and arrays.

Current only exposes batch methods for `controls` - other objects will
come in a subsequent commit.

Tests are not yet complete as we have yet to expose handlers for control
update events and the current implementation does not update internal
state on all events so it is not testable. We also need to invest in
proper teardown methods to kill interactive connection when using
asserts.
  • Loading branch information
Mobius5150 committed Jun 9, 2018
1 parent 39fc8d4 commit b233445
Show file tree
Hide file tree
Showing 15 changed files with 642 additions and 2 deletions.
95 changes: 95 additions & 0 deletions Tests/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -923,5 +923,100 @@ TEST_CLASS(Tests)
Logger::WriteMessage("Disconnecting...");
interactive_close_session(session);
}

TEST_METHOD(ControlBatchTest)
{
g_start = std::chrono::high_resolution_clock::now();
interactive_config_debug(interactive_debug_trace, handle_debug_message);

int err = 0;
std::string clientId = CLIENT_ID;
std::string versionId = VERSION_ID;
std::string shareCode = SHARE_CODE;
std::string auth;

ASSERT_NOERR(do_auth(clientId, "", auth));

interactive_session session;
Logger::WriteMessage("Connecting...");
ASSERT_NOERR(interactive_open_session(&session));
ASSERT_NOERR(interactive_set_error_handler(session, handle_error_assert));
ASSERT_NOERR(interactive_connect(session, auth.c_str(), versionId.c_str(), shareCode.c_str(), true));
ASSERT_NOERR(interactive_set_participants_changed_handler(session, handle_participants_changed));

// Simulate 60 frames/sec for 1 second.
const int fps = 60;
const int seconds = 1;
for (int i = 0; i < fps * seconds; ++i)
{
ASSERT_NOERR(interactive_run(session, 1));
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / fps));
}

interactive_batch batch;
Assert::AreEqual((int)MIXER_OK, interactive_control_batch_begin(session, &batch, "default"));

interactive_batch_entry entry;
Assert::AreEqual((int)MIXER_OK, interactive_control_batch_add(batch, &entry, "GiveHealth"));
Assert::AreEqual((int)MIXER_OK, interactive_batch_add_param_str(batch, entry, "foo", "bar"));
Assert::AreEqual((int)MIXER_OK, interactive_batch_add_param_uint(batch, entry, "number", 42));
Assert::AreEqual((int)MIXER_OK, interactive_batch_add_param_array(batch, entry, "array", [](interactive_batch batch, interactive_batch_array arrayItem)
{
Assert::AreEqual((int)MIXER_OK, interactive_batch_array_push_object(batch, arrayItem, [](interactive_batch batch, interactive_batch_entry objectEntry)
{
Assert::AreEqual((int)MIXER_OK, interactive_batch_add_param_str(batch, objectEntry, "foo", "bar"));
Assert::AreEqual((int)MIXER_OK, interactive_batch_add_param_uint(batch, objectEntry, "number", 42));
}));
Assert::AreEqual((int)MIXER_OK, interactive_batch_array_push_str(batch, arrayItem, "bar"));
Assert::AreEqual((int)MIXER_OK, interactive_batch_array_push_uint(batch, arrayItem, 42));
}));
Assert::AreEqual((int)MIXER_OK, interactive_batch_add_param_object(batch, entry, "object", [](interactive_batch batch, interactive_batch_entry objectEntry)
{
Assert::AreEqual((int)MIXER_OK, interactive_batch_add_param_str(batch, objectEntry, "foo", "bar"));
Assert::AreEqual((int)MIXER_OK, interactive_batch_add_param_uint(batch, objectEntry, "number", 42));
}));
Assert::AreEqual((int)MIXER_OK, interactive_control_batch_end(batch));

// Simulate 60 frames/sec for 1 second.
for (int i = 0; i < fps * seconds; ++i)
{
ASSERT_NOERR(interactive_run(session, 1));
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / fps));
}

Logger::WriteMessage("Enumerating scenes.");
ASSERT_NOERR(interactive_get_scenes(session, [](void* context, interactive_session session, interactive_scene* scene)
{
std::stringstream s;
s << "[Scene] '" << std::string(scene->id, scene->idLength) << "'";
Logger::WriteMessage(s.str().c_str());

Logger::WriteMessage("Controls:");
interactive_scene_get_controls(session, scene->id, [](void* context, interactive_session session, interactive_control* control)
{
if (0 == strcmp(control->id, "GiveHealth")) {
char foo[4];
size_t nameLength = 4;
int number;
print_control_properties(session, control->id);
Assert::AreEqual((int)MIXER_OK, interactive_control_get_property_string(session, "GiveHealth", "foo", foo, &nameLength));
Assert::AreEqual((int)MIXER_OK, interactive_control_get_property_int(session, "GiveHealth", "number", &number));
Assert::AreEqual("bar", foo);
}
});
}));

for (int i = 0; i < fps * seconds; ++i)
{
ASSERT_NOERR(interactive_run(session, 1));
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / fps));
}

Logger::WriteMessage("Disconnecting...");
interactive_close_session(session);

Assert::IsTrue(0 == err);
}

};
}
2 changes: 2 additions & 0 deletions builds/Interactivity.UWP.Cpp/Interactivity.UWP.Cpp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\source\internal\interactive_batch.cpp" />
<ClCompile Include="..\..\source\internal\interactive_control.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -125,6 +126,7 @@
<ClInclude Include="..\..\source\internal\common.h" />
<ClInclude Include="..\..\source\internal\debugging.h" />
<ClInclude Include="..\..\source\internal\http_client.h" />
<ClInclude Include="..\..\source\internal\interactive_batch.h" />
<ClInclude Include="..\..\source\internal\interactive_session.h" />
<ClInclude Include="..\..\source\internal\websocket.h" />
<ClInclude Include="..\..\source\internal\winapp_http_client.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<ClCompile Include="..\..\Source\interactivity.cpp">
<Filter>C++ Source</Filter>
</ClCompile>
<ClCompile Include="..\..\source\internal\interactive_batch.cpp">
<Filter>C++ Source</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\source\interactivity.h">
Expand All @@ -68,5 +71,8 @@
<ClInclude Include="..\..\source\internal\debugging.h">
<Filter>Includes</Filter>
</ClInclude>
<ClInclude Include="..\..\source\internal\interactive_batch.h">
<Filter>Includes</Filter>
</ClInclude>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\source\internal\interactive_batch.cpp" />
<ClCompile Include="..\..\source\internal\interactive_control.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -121,6 +122,7 @@
<ClInclude Include="..\..\source\internal\common.h" />
<ClInclude Include="..\..\source\internal\debugging.h" />
<ClInclude Include="..\..\source\internal\http_client.h" />
<ClInclude Include="..\..\source\internal\interactive_batch.h" />
<ClInclude Include="..\..\source\internal\interactive_session.h" />
<ClInclude Include="..\..\source\internal\json.h" />
<ClInclude Include="..\..\source\internal\websocket.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<ClCompile Include="..\..\source\internal\win_websocket.cpp">
<Filter>C++ Source</Filter>
</ClCompile>
<ClCompile Include="..\..\source\internal\interactive_batch.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\source\interactivity.h">
Expand All @@ -71,5 +72,8 @@
<ClInclude Include="..\..\source\internal\websocket.h">
<Filter>Includes</Filter>
</ClInclude>
<ClInclude Include="..\..\source\internal\interactive_batch.h">
<Filter>Includes</Filter>
</ClInclude>
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions builds/Interactivity.Xbox.Cpp/Interactivity.Xbox.Cpp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Durango'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Durango'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\source\internal\interactive_batch.cpp" />
<ClCompile Include="..\..\source\internal\interactive_control.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Durango'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Durango'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -98,6 +99,7 @@
<ClInclude Include="..\..\source\interactivity.h" />
<ClInclude Include="..\..\source\internal\common.h" />
<ClInclude Include="..\..\source\internal\http_client.h" />
<ClInclude Include="..\..\source\internal\interactive_batch.h" />
<ClInclude Include="..\..\source\internal\interactive_session.h" />
<ClInclude Include="..\..\source\internal\winapp_http_client.h" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<ClCompile Include="..\..\source\internal\winapp_http_client.cpp">
<Filter>C++ Source</Filter>
</ClCompile>
<ClCompile Include="..\..\source\internal\interactive_batch.cpp">
<Filter>C++ Source</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\source\interactivity.h">
Expand All @@ -59,5 +62,8 @@
<ClInclude Include="..\..\source\internal\winapp_http_client.h">
<Filter>Includes</Filter>
</ClInclude>
<ClInclude Include="..\..\source\internal\interactive_batch.h">
<Filter>Includes</Filter>
</ClInclude>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions source/interactivity.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "internal/common.cpp"
#include "internal/http_client.cpp"
#include "internal/interactive_auth.cpp"
#include "internal/interactive_batch.cpp"
#include "internal/interactive_control.cpp"
#include "internal/interactive_group.cpp"
#include "internal/interactive_participant.cpp"
Expand Down
60 changes: 60 additions & 0 deletions source/interactivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,49 @@ extern "C" {
void interactive_close_session(interactive_session session);
/** @} */

/** @name Batch Requests
* @{
*/
struct interactive_batch_public {};
struct interactive_batch_entry_public {};
struct interactive_batch_array_public {};

typedef interactive_batch_public* interactive_batch;

typedef interactive_batch_entry_public* interactive_batch_entry;

typedef interactive_batch_array_public* interactive_batch_array;

typedef void(*interactive_batch_object_callback)(interactive_batch, interactive_batch_entry);

typedef void(*interactive_batch_array_callback)(interactive_batch, interactive_batch_array);

int interactive_batch_add_param_null(interactive_batch batch, interactive_batch_entry entry, const char* name);

int interactive_batch_add_param_str(interactive_batch batch, interactive_batch_entry entry, const char* name, const char* value);

int interactive_batch_add_param_uint(interactive_batch batch, interactive_batch_entry entry, const char* name, unsigned int value);

int interactive_batch_add_param_bool(interactive_batch batch, interactive_batch_entry entry, const char* name, bool value);

int interactive_batch_add_param_object(interactive_batch batch, interactive_batch_entry entry, const char* name, interactive_batch_object_callback callback);

int interactive_batch_add_param_array(interactive_batch batch, interactive_batch_entry entry, const char* name, interactive_batch_array_callback callback);

int interactive_batch_array_push_null(interactive_batch batch, interactive_batch_array arrayItem);

int interactive_batch_array_push_str(interactive_batch batch, interactive_batch_array arrayItem, const char* value);

int interactive_batch_array_push_uint(interactive_batch batch, interactive_batch_array arrayItem, unsigned int value);

int interactive_batch_array_push_bool(interactive_batch batch, interactive_batch_array arrayItem, bool value);

int interactive_batch_array_push_object(interactive_batch batch, interactive_batch_array arrayItem, interactive_batch_object_callback callback);

int interactive_batch_array_push_array(interactive_batch batch, interactive_batch_array arrayItem, interactive_batch_array_callback callback);

/** @} */

/** @name Controls
* @{
*/
Expand Down Expand Up @@ -286,6 +329,12 @@ extern "C" {
/// Get a <c>char*</c> meta property value by name.
/// </summary>
int interactive_control_get_meta_property_string(interactive_session session, const char* controlId, const char* key, char* property, size_t* propertyLength);

int interactive_control_batch_begin(interactive_session session, interactive_batch* batchPtr, const char* sceneId);

int interactive_control_batch_add(interactive_batch batch, interactive_batch_entry* entry, const char* controlId);

int interactive_control_batch_end(interactive_batch batch);
/** @} */

/** @name Groups
Expand Down Expand Up @@ -521,6 +570,17 @@ extern "C" {
/// Get the participant's group name.
/// </summary>
int interactive_participant_get_group(interactive_session session, const char* participantId, char* group, size_t* groupLength);

int interactive_participant_batch_begin(interactive_session session, interactive_batch* batchPtr);

int interactive_participant_batch_add(interactive_batch batch, interactive_batch_entry* entry, const char* participantId);

int interactive_participant_batch_end(interactive_batch batch);

/// <summary>
/// Reads a string value from the participant object.
/// </summary>
int interactive_participant_get_param_string(interactive_session session, const char * participantId, const char *paramName, char* value, size_t* valueLength);
/** @} */

/** @name Manual Protocol Integration
Expand Down
Loading

0 comments on commit b233445

Please sign in to comment.