//Source::inputData() end
//Switch::getPadList() begin
+var ValidSwitchGetPadListExceptions = [
+ 'InvalidStateError',
+ 'NotFoundError',
+ 'NotSupportedError',
+ 'AbortError'
+];
+Switch.prototype.getPadList = function() {
+ var nativeArgs = {
+ name: this.name,
+ id: this._pipeline_id
+ };
+
+ var result = native_.callSync('MLPipelineSwitchGetPadList', nativeArgs);
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObjectAndValidate(
+ result,
+ ValidSwitchGetPadListExceptions,
+ AbortError
+ );
+ }
+ return result.result;
+};
//Switch::getPadList() end
+//Switch::select() begin
+var ValidSwitchSelectExceptions = [
+ 'InvalidValuesError',
+ 'NotFoundError',
+ 'NotSupportedError',
+ 'AbortError'
+];
+Switch.prototype.select = function() {
+ var args = validator_.validateArgs(arguments, [
+ {
+ name: 'padName',
+ type: validator_.Types.STRING
+ }
+ ]);
+
+ if (!args.has.padName) {
+ throw new WebAPIException(
+ WebAPIException.INVALID_VALUES_ERR,
+ 'Invalid parameter: pad name is mandatory'
+ );
+ }
+
+ var nativeArgs = {
+ id: this._pipeline_id,
+ name: this.name,
+ padName: args.padName
+ };
+
+ var result = native_.callSync('MLPipelineSwitchSelect', nativeArgs);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObjectAndValidate(
+ result,
+ ValidSwitchSelectExceptions,
+ AbortError
+ );
+ }
+};
+//Switch::select() end
+
//Valve::setOpen() begin
//Valve::setOpen() end
const std::string kDefinition = "definition";
const std::string kPipelineStateChangeListenerName = "listenerName";
const std::string kOtherId = "otherId";
+const std::string kPadName = "padName";
} // namespace
using namespace common;
REGISTER_METHOD(MLPipelineStop);
REGISTER_METHOD(MLPipelineGetNodeInfo);
REGISTER_METHOD(MLPipelineGetSwitch);
+ REGISTER_METHOD(MLPipelineSwitchGetPadList);
+ REGISTER_METHOD(MLPipelineSwitchSelect);
// Pipeline API end
#undef REGISTER_METHOD
}
auto name = args.get(kName).get<std::string>();
- auto pipeline_id = args.get(kId).get<double>();
+ auto pipeline_id = static_cast<int>(args.get(kId).get<double>());
std::string type;
auto ret = pipeline_manager_.GetSwitch(name, pipeline_id, &type);
// Source::inputData() end
// Switch::getPadList() begin
+void MlInstance::MLPipelineSwitchGetPadList(const picojson::value& args, picojson::object& out) {
+ ScopeLogger("args: [%s]", args.serialize().c_str());
+
+ CHECK_ARGS(args, kId, double, out);
+ CHECK_ARGS(args, kName, std::string, out);
+
+ auto pipeline_id = static_cast<int>(args.get(kId).get<double>());
+ auto& switch_name = args.get(kName).get<std::string>();
+
+ picojson::array pad_list;
+ auto ret = pipeline_manager_.SwitchGetPadList(pipeline_id, switch_name, &pad_list);
+ if (!ret) {
+ LogAndReportError(ret, &out);
+ return;
+ }
+ ReportSuccess(picojson::value{std::move(pad_list)}, out);
+}
// Switch::getPadList() end
+// Switch::select() end
+void MlInstance::MLPipelineSwitchSelect(const picojson::value& args, picojson::object& out) {
+ ScopeLogger("args: [%s]", args.serialize().c_str());
+
+ CHECK_ARGS(args, kId, double, out);
+ CHECK_ARGS(args, kName, std::string, out);
+ CHECK_ARGS(args, kPadName, std::string, out);
+
+ auto pipeline_id = args.get(kId).get<double>();
+ auto& switch_name = args.get(kName).get<std::string>();
+ auto& pad_name = args.get(kPadName).get<std::string>();
+
+ auto ret = pipeline_manager_.SwitchSelect(pipeline_id, switch_name, pad_name);
+ if (!ret) {
+ LogAndReportError(ret, &out);
+ return;
+ }
+
+ ReportSuccess(out);
+}
+// Switch::select() end
+
// Valve::setOpen() begin
// Valve::setOpen() end
// Source::inputData() end
// Switch::getPadList() begin
-
+ void MLPipelineSwitchGetPadList(const picojson::value& args, picojson::object& out);
// Switch::getPadList() end
+ // Switch::select() begin
+ void MLPipelineSwitchSelect(const picojson::value& args, picojson::object& out);
+ // Switch::select() end
+
// Valve::setOpen() begin
// Valve::setOpen() end
// Source::inputData() end
// Switch::getPadList() begin
+PlatformResult Pipeline::GetSwitch(const std::string& name, Switch** out) {
+ ScopeLogger("id: [%d], name: [%s]", id_, name.c_str());
+
+ auto switch_it = switches_.find(name);
+ if (switches_.end() != switch_it) {
+ LoggerD("Switch [%s] found", name.c_str());
+ *out = switch_it->second.get();
+ return PlatformResult{};
+ }
+ LoggerE("Switch [%s] not found", name.c_str());
+ return PlatformResult{ErrorCode::ABORT_ERR, "Switch does not exist"};
+}
// Switch::getPadList() end
// Source::inputData() end
// Switch::getPadList() begin
+ PlatformResult GetSwitch(const std::string& name, Switch** out);
// Switch::getPadList() end
// Source::inputData() end
// Switch::getPadList() begin
+PlatformResult PipelineManager::SwitchGetPadList(int pipeline_id, const std::string& switch_name,
+ picojson::array* out) {
+ ScopeLogger("pipeline_id: [%d], switch_name: [%s]", pipeline_id, switch_name.c_str());
+ auto pipeline_it = pipelines_.find(pipeline_id);
+ if (pipelines_.end() == pipeline_it) {
+ LoggerD("Pipeline not found: [%d]", pipeline_id);
+ return PlatformResult{ErrorCode::NOT_FOUND_ERR, "Pipeline not found"};
+ }
+
+ Switch* switch_ptr = nullptr;
+ auto ret = pipeline_it->second->GetSwitch(switch_name, &switch_ptr);
+ if (!ret) {
+ return ret;
+ }
+
+ return switch_ptr->GetPadList(out);
+}
// Switch::getPadList() end
+// Switch::select() begin
+PlatformResult PipelineManager::SwitchSelect(int pipeline_id, const std::string& switch_name,
+ const std::string& pad_name) {
+ ScopeLogger("pipeline_id: [%d], switch_name: [%s], pad_name: [%s]", pipeline_id,
+ switch_name.c_str(), pad_name.c_str());
+
+ auto pipeline_it = pipelines_.find(pipeline_id);
+ if (pipelines_.end() == pipeline_it) {
+ LoggerD("Pipeline not found: [%d]", pipeline_id);
+ return PlatformResult{ErrorCode::NOT_FOUND_ERR, "Pipeline not found"};
+ }
+
+ Switch* switch_ptr = nullptr;
+ auto ret = pipeline_it->second->GetSwitch(switch_name, &switch_ptr);
+ if (!ret) {
+ return ret;
+ }
+
+ return switch_ptr->Select(pad_name);
+}
+// Switch::select() end
+
// Valve::setOpen() begin
// Valve::setOpen() end
// Source::inputData() end
// Switch::getPadList() begin
-
+ PlatformResult SwitchGetPadList(int pipeline_id, const std::string& switch_name,
+ picojson::array* out);
// Switch::getPadList() end
+ // Switch::select() begin
+ PlatformResult SwitchSelect(int pipeline_id, const std::string& switch_name,
+ const std::string& pad_name);
+ // Switch::select() end
+
// Valve::setOpen() begin
// Valve::setOpen() end
* limitations under the License.
*/
+#include <glib.h>
+
#include "ml_pipeline_switch.h"
#include "ml_utils.h"
return type_;
}
+PlatformResult Switch::GetPadList(picojson::array* out) const {
+ ScopeLogger("name: [%s]", name_.c_str());
+
+ gchar** list = nullptr;
+ auto ret = ml_pipeline_switch_get_pad_list(switch_, &list);
+ if (ML_ERROR_NONE != ret) {
+ LoggerE("ml_pipeline_switch_get_pad_list() failed: [%d] (%s)", ret, get_error_message(ret));
+ return util::ToPlatformResult(ret, "Could not get pad list");
+ }
+ LoggerD("ml_pipeline_switch_get_pad_list() succeeded");
+
+ if (!list) {
+ LoggerD("Pad list empty");
+ return PlatformResult{};
+ }
+
+ for (int i = 0; nullptr != list[i]; ++i) {
+ LoggerD("list[%d]: [%s]", i, list[i]);
+ out->push_back(picojson::value{std::string{list[i]}});
+ g_free(list[i]);
+ }
+ g_free(list);
+
+ return PlatformResult{};
+}
+
+PlatformResult Switch::Select(const std::string& pad_name) const {
+ ScopeLogger("name: [%s], pad_name: [%s]", name_.c_str(), pad_name.c_str());
+
+ auto ret = ml_pipeline_switch_select(switch_, pad_name.c_str());
+ if (ML_ERROR_NONE != ret) {
+ LoggerE("ml_pipeline_switch_select() failed: [%d] (%s)", ret, get_error_message(ret));
+ return util::ToPlatformResult(ret, "Could not select pad");
+ }
+ LoggerD("ml_pipeline_switch_select() succeeded");
+
+ return PlatformResult{};
+}
+
} // namespace pipeline
} // namespace ml
} // namespace extension
\ No newline at end of file
std::unique_ptr<Switch>* out);
std::string GetType() const;
+ PlatformResult GetPadList(picojson::array* out) const;
+ PlatformResult Select(const std::string& pad_name) const;
~Switch();