-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add readonly on Get propertry support.
Add callback to retrieve control classes from control_protocol_state
- Loading branch information
Showing
14 changed files
with
1,747 additions
and
1,302 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "nmos/control_protocol_handlers.h" | ||
|
||
#include "cpprest/basic_utils.h" | ||
#include "nmos/control_protocol_state.h" | ||
#include "nmos/slog.h" | ||
|
||
namespace nmos | ||
{ | ||
get_control_protocol_classes_handler make_get_control_protocol_classes_handler(nmos::experimental::control_protocol_state& control_protocol_state, slog::base_gate& gate) | ||
{ | ||
return [&]() | ||
{ | ||
slog::log<slog::severities::more_info>(gate, SLOG_FLF) << "Retrieve all control classes from cache"; | ||
|
||
auto lock = control_protocol_state.read_lock(); | ||
|
||
return control_protocol_state.control_classes; | ||
}; | ||
} | ||
|
||
get_control_protocol_class_handler make_get_control_protocol_class_handler(nmos::experimental::control_protocol_state& control_protocol_state, slog::base_gate& gate) | ||
{ | ||
return [&](const details::nc_class_id& class_id) | ||
{ | ||
using web::json::value; | ||
|
||
slog::log<slog::severities::more_info>(gate, SLOG_FLF) << "Retrieve control class from cache"; | ||
|
||
auto lock = control_protocol_state.read_lock(); | ||
|
||
auto class_id_data = details::make_nc_class_id(class_id); | ||
|
||
auto& control_classes = control_protocol_state.control_classes; | ||
auto found = control_classes.find(class_id_data); | ||
if (control_classes.end() != found) | ||
{ | ||
return found->second; | ||
} | ||
|
||
return experimental::control_class{ value::array(), value::array(), value::array() }; | ||
}; | ||
} | ||
|
||
add_control_protocol_class_handler make_add_control_protocol_class_handler(nmos::experimental::control_protocol_state& control_protocol_state, slog::base_gate& gate) | ||
{ | ||
return [&](const details::nc_class_id& class_id, const experimental::control_class& control_class) | ||
{ | ||
slog::log<slog::severities::more_info>(gate, SLOG_FLF) << "Add control class to cache"; | ||
|
||
auto lock = control_protocol_state.write_lock(); | ||
|
||
auto class_id_data = details::make_nc_class_id(class_id); | ||
|
||
auto& control_classes = control_protocol_state.control_classes; | ||
if (control_classes.end() == control_classes.find(class_id_data)) | ||
{ | ||
return false; | ||
} | ||
|
||
control_classes[class_id_data] = control_class; | ||
return true; | ||
}; | ||
} | ||
} |
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,44 @@ | ||
#ifndef NMOS_CONTROL_PROTOCOL_HANDLERS_H | ||
#define NMOS_CONTROL_PROTOCOL_HANDLERS_H | ||
|
||
#include <cstdint> | ||
#include <functional> | ||
#include "nmos/control_protocol_resource.h" | ||
#include "nmos/control_protocol_state.h" | ||
|
||
namespace slog | ||
{ | ||
class base_gate; | ||
} | ||
|
||
namespace nmos | ||
{ | ||
namespace experimental | ||
{ | ||
struct control_class; | ||
struct control_protocol_state; | ||
} | ||
|
||
// callback to retrieve all control protocol classes | ||
// this callback should not throw exceptions | ||
typedef std::function<experimental::control_classes()> get_control_protocol_classes_handler; | ||
|
||
// callback to retrieve a specific control protocol class | ||
// this callback should not throw exceptions | ||
typedef std::function<experimental::control_class(const details::nc_class_id& class_id)> get_control_protocol_class_handler; | ||
|
||
// callback to add user control protocol class | ||
// this callback should not throw exceptions | ||
typedef std::function<bool(const details::nc_class_id& class_id, const experimental::control_class& control_class)> add_control_protocol_class_handler; | ||
|
||
// construct callback to retrieve all control protocol classes | ||
get_control_protocol_classes_handler make_get_control_protocol_classes_handler(nmos::experimental::control_protocol_state& control_protocol_state, slog::base_gate& gate); | ||
|
||
// construct callback to retrieve control protocol class | ||
get_control_protocol_class_handler make_get_control_protocol_class_handler(nmos::experimental::control_protocol_state& control_protocol_state, slog::base_gate& gate); | ||
|
||
// construct callback to add control protocol class | ||
add_control_protocol_class_handler make_add_control_protocol_class_handler(nmos::experimental::control_protocol_state& control_protocol_state, slog::base_gate& gate); | ||
} | ||
|
||
#endif |
Oops, something went wrong.