2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 var kPipelineStateChangeListenerNamePrefix = 'MLPipelineStateChangeListener';
19 //PipelineManager::createPipeline() begin
20 var ValidPipelineDisposeExceptions = ['NotFoundError', 'NotSupportedError', 'AbortError'];
22 var nextPipelineId = 1;
23 function NextPipelineId() {
24 return nextPipelineId++;
27 var ValidPipelineManagerCreatePipelineExceptions = [
35 var CreatePipeline = function() {
36 privUtils_.log('Entered PipelineManager.createPipeline()');
37 var args = validator_.validateArgs(arguments, [
40 type: validator_.Types.STRING
44 type: validator_.Types.FUNCTION,
50 if (!args.has.definition) {
51 throw new WebAPIException(
52 WebAPIException.INVALID_VALUES_ERR,
53 'Invalid parameter: pipeline definition is mandatory'
57 var pipeline = new Pipeline(NextPipelineId());
60 definition: args.definition
64 nativeArgs.listenerName = kPipelineStateChangeListenerNamePrefix + pipeline._id;
65 var stateChangeListener = function(stateObject) {
66 args.listener(stateObject.state);
68 native_.addListener(nativeArgs.listenerName, stateChangeListener);
71 var result = native_.callSync('MLPipelineManagerCreatePipeline', nativeArgs);
73 if (native_.isFailure(result)) {
74 if (nativeArgs.listenerName) {
75 native_.removeListener(nativeArgs.listenerName);
77 throw native_.getErrorObjectAndValidate(
79 ValidPipelineManagerCreatePipelineExceptions,
86 //PipelineManager::createPipeline() end
88 //Pipeline::state begin
89 var ValidPipelineStateExceptions = ['NotSupportedError', 'AbortError'];
90 var Pipeline = function(id) {
91 Object.defineProperties(this, {
95 var result = native_.callSync('MLPipelineGetState', {
98 if (native_.isFailure(result)) {
99 throw native_.getErrorObjectAndValidate(
101 ValidPipelineStateExceptions,
106 return result.result;
114 //Pipeline::state end
116 //Pipeline::start() begin
117 var ValidPipelineStartStopExceptions = [
122 Pipeline.prototype.start = function() {
127 var result = native_.callSync('MLPipelineStart', nativeArgs);
128 if (native_.isFailure(result)) {
129 throw native_.getErrorObjectAndValidate(
131 ValidPipelineStartStopExceptions,
136 //Pipeline::start() end
138 //Pipeline::stop() begin
139 Pipeline.prototype.stop = function() {
144 var result = native_.callSync('MLPipelineStop', nativeArgs);
145 if (native_.isFailure(result)) {
146 throw native_.getErrorObjectAndValidate(
148 ValidPipelineStartStopExceptions,
153 //Pipeline::stop() end
155 //Pipeline::dispose() begin
156 Pipeline.prototype.dispose = function() {
157 var result = native_.callSync('MLPipelineDispose', { id: this._id });
159 if (native_.isFailure(result)) {
160 throw native_.getErrorObjectAndValidate(
162 ValidPipelineDisposeExceptions,
167 //Pipeline::dispose() end
169 //Pipeline::getNodeInfo() begin
170 var NodeInfo = function(name, pipeline_id) {
171 Object.defineProperties(this, {
172 name: { enumerable: true, writable: false, value: name },
173 _pipeline_id: { value: pipeline_id }
177 var ValidPipelineGetNodeInfoExceptions = [
178 'InvalidValuesError',
184 Pipeline.prototype.getNodeInfo = function() {
185 var args = validator_.validateArgs(arguments, [
188 type: validator_.Types.STRING
197 var result = native_.callSync('MLPipelineGetNodeInfo', nativeArgs);
198 if (native_.isFailure(result)) {
199 throw native_.getErrorObjectAndValidate(
201 ValidPipelineGetNodeInfoExceptions,
206 return new NodeInfo(args.name, this._id);
208 //Pipeline::getNodeInfo() end
210 //Pipeline::getSource() begin
212 //Pipeline::getSource() end
214 //Pipeline::getSwitch() begin
215 function Switch(name, type, pipeline_id) {
216 Object.defineProperties(this, {
231 var ValidPipelineGetSwitchExceptions = [
233 'InvalidValuesError',
238 Pipeline.prototype.getSwitch = function() {
239 var args = validator_.validateArgs(arguments, [
242 type: validator_.Types.STRING
250 var result = native_.callSync('MLPipelineGetSwitch', nativeArgs);
251 if (native_.isFailure(result)) {
252 throw native_.getErrorObjectAndValidate(
254 ValidPipelineGetSwitchExceptions,
259 return new Switch(nativeArgs.name, result.type, this._id);
261 //Pipeline::getSwitch() end
263 //Pipeline::getValve() begin
264 function Valve(name, pipeline_id) {
265 Object.defineProperties(this, {
276 var ValidPipelineGetValveExceptions = [
277 'InvalidValuesError',
282 Pipeline.prototype.getValve = function() {
283 var args = validator_.validateArgs(arguments, [
286 type: validator_.Types.STRING
295 var result = native_.callSync('MLPipelineGetValve', nativeArgs);
296 if (native_.isFailure(result)) {
297 throw native_.getErrorObjectAndValidate(
299 ValidPipelineGetValveExceptions,
304 return new Valve(nativeArgs.name, this._id);
306 //Pipeline::getValve() end
308 //Pipeline::registerSinkCallback() begin
310 //Pipeline::registerSinkCallback() end
312 //Pipeline::unregisterSinkCallback() begin
314 //Pipeline::unregisterSinkCallback() end
316 //Pipeline::registerCustomFilter() begin
318 //Pipeline::registerCustomFilter() end
320 //Pipeline::unregisterCustomFilter() begin
322 //Pipeline::unregisterCustomFilter() end
334 //NodeInfo::getProperty() begin
335 var ValidNodeInfoGetPropertyExceptions = [
336 'InvalidValuesError',
342 NodeInfo.prototype.getProperty = function() {
343 var args = validator_.validateArgs(arguments, [
346 type: validator_.Types.STRING
349 name: 'propertyType',
351 values: Object.keys(PropertyType)
356 id: this._pipeline_id,
359 type: args.propertyType
362 var result = native_.callSync('MLPipelineNodeInfoGetProperty', nativeArgs);
363 if (native_.isFailure(result)) {
364 throw native_.getErrorObjectAndValidate(
366 ValidNodeInfoGetPropertyExceptions,
371 return result.property;
373 //NodeInfo::getProperty() end
375 //NodeInfo::setProperty() begin
376 var ValidNodeInfoSetPropertyExceptions = [
377 'InvalidValuesError',
383 NodeInfo.prototype.setProperty = function() {
384 var args = validator_.validateArgs(arguments, [
387 type: validator_.Types.STRING
390 name: 'propertyType',
392 values: Object.keys(PropertyType)
396 type: types_.SIMPLE_TYPE
401 id: this._pipeline_id,
404 type: args.propertyType,
405 property: args.property
408 var result = native_.callSync('MLPipelineNodeInfoSetProperty', nativeArgs);
409 if (native_.isFailure(result)) {
410 throw native_.getErrorObjectAndValidate(
412 ValidNodeInfoSetPropertyExceptions,
417 //NodeInfo::setProperty() end
419 //Source::inputTensorsInfo begin
421 //Source::inputTensorsInfo end
423 //Source::inputData() begin
425 //Source::inputData() end
427 //Switch::getPadList() begin
428 var ValidSwitchGetPadListExceptions = [
434 Switch.prototype.getPadList = function() {
437 id: this._pipeline_id
440 var result = native_.callSync('MLPipelineSwitchGetPadList', nativeArgs);
442 if (native_.isFailure(result)) {
443 throw native_.getErrorObjectAndValidate(
445 ValidSwitchGetPadListExceptions,
450 return result.result;
452 //Switch::getPadList() end
454 //Switch::select() begin
455 var ValidSwitchSelectExceptions = [
456 'InvalidValuesError',
461 Switch.prototype.select = function() {
462 var args = validator_.validateArgs(arguments, [
465 type: validator_.Types.STRING
469 if (!args.has.padName) {
470 throw new WebAPIException(
471 WebAPIException.INVALID_VALUES_ERR,
472 'Invalid parameter: pad name is mandatory'
477 id: this._pipeline_id,
479 padName: args.padName
482 var result = native_.callSync('MLPipelineSwitchSelect', nativeArgs);
483 if (native_.isFailure(result)) {
484 throw native_.getErrorObjectAndValidate(
486 ValidSwitchSelectExceptions,
491 //Switch::select() end
493 //Valve::setOpen() begin
495 //Valve::setOpen() end
496 var MachineLearningPipeline = function() {};
498 MachineLearningPipeline.prototype.createPipeline = CreatePipeline;