generated from AMWA-TV/info-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathManagers.ts
962 lines (879 loc) · 50.7 KB
/
Managers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
import { jsonIgnoreReplacer, jsonIgnore } from 'json-ignore';
import { CommandResponseError, CommandResponseNoValue, CommandResponseWithValue } from '../NCProtocol/Commands';
import { NcPropertyChangedEventData } from '../NCProtocol/Notifications';
import { WebSocketConnection } from '../Server';
import { INotificationContext } from '../SessionManager';
import { NcBlock } from './Blocks';
import {
BaseType,
myIdDecorator,
NcBlockMemberDescriptor,
NcClassDescriptor,
NcDatatypeDescriptor,
NcDatatypeDescriptorEnum,
NcDatatypeDescriptorPrimitive,
NcDatatypeDescriptorStruct,
NcDatatypeDescriptorTypeDef,
NcDescriptor,
NcElementId,
NcEnumItemDescriptor,
NcEventDescriptor,
NcEventId,
NcFieldDescriptor,
NcMethodDescriptor,
NcMethodId,
NcMethodResult,
NcMethodResultBlockMemberDescriptors,
NcMethodResultClassDescriptor,
NcMethodResultDatatypeDescriptor,
NcMethodResultError,
NcMethodResultId,
NcMethodResultLength,
NcMethodResultPropertyValue,
NcMethodStatus,
NcObject,
NcParameterConstraints,
NcParameterConstraintsNumber,
NcParameterConstraintsString,
NcParameterDescriptor,
NcPropertyChangeType,
NcPropertyConstraints,
NcPropertyConstraintsNumber,
NcPropertyConstraintsString,
NcPropertyDescriptor,
NcPropertyId,
NcTouchpoint,
NcTouchpointNmos,
NcTouchpointNmosChannelMapping,
NcTouchpointResource,
NcTouchpointResourceNmos,
NcTouchpointResourceNmosChannelMapping} from './Core';
import { ExampleDataType, ExampleControl, GainControl, NcIdentBeacon, NcReceiverMonitor, NcWorker, NcStatusMonitor, NcMethodResultCounters, NcCounter, NcSenderMonitor } from './Features';
export abstract class NcManager extends NcObject
{
public static staticClassID: number[] = [ 1, 3 ];
@myIdDecorator('1p1')
public override classID: number[] = NcManager.staticClassID;
public constructor(
oid: number,
constantOid: boolean,
ownerObject: NcObject | null,
role: string,
userLabel: string,
touchpoints: NcTouchpoint[] | null,
runtimePropertyConstraints: NcPropertyConstraints[] | null,
description: string,
notificationContext: INotificationContext)
{
super(oid, constantOid, ownerObject, role, userLabel, touchpoints, runtimePropertyConstraints, description, notificationContext);
}
public static override GetClassDescriptor(includeInherited: boolean): NcClassDescriptor
{
let currentClassDescriptor = new NcClassDescriptor(`${NcManager.name} class descriptor`,
NcManager.staticClassID, NcManager.name, null,
[], [], []);
if(includeInherited)
{
let baseDescriptor = super.GetClassDescriptor(includeInherited);
currentClassDescriptor.properties = currentClassDescriptor.properties.concat(baseDescriptor.properties);
currentClassDescriptor.methods = currentClassDescriptor.methods.concat(baseDescriptor.methods);
currentClassDescriptor.events = currentClassDescriptor.events.concat(baseDescriptor.events);
}
return currentClassDescriptor;
}
}
export class NcManufacturer extends BaseType
{
public name: string;
public organizationId: null;
public website: string;
constructor(
name: string,
website: string)
{
super();
this.name = name;
this.organizationId = null;
this.website = website;
}
public static override GetTypeDescriptor(includeInherited: boolean): NcDatatypeDescriptor
{
return new NcDatatypeDescriptorStruct("NcManufacturer", [
new NcFieldDescriptor("name", "NcString", false, false, null, "Manufacturer's name"),
new NcFieldDescriptor("organizationId", "NcOrganizationId", true, false, null, "IEEE OUI or CID of manufacturer"),
new NcFieldDescriptor("website", "NcUri", true, false, null, "URL of the manufacturer's website")
], null, null, "Manufacturer descriptor");
}
public ToJson()
{
return JSON.stringify(this, jsonIgnoreReplacer);
}
}
export class NcProduct extends BaseType
{
public name: string;
public key: string;
public revisionLevel: string;
public brandName: string;
public uuid: string;
public description: string;
constructor(
name: string,
key: string,
revisionLevel: string,
brandName: string,
uuid: string,
description: string)
{
super();
this.name = name;
this.key = key;
this.revisionLevel = revisionLevel;
this.brandName = brandName;
this.uuid = uuid;
this.description = description;
}
public static override GetTypeDescriptor(includeInherited: boolean): NcDatatypeDescriptor
{
return new NcDatatypeDescriptorStruct("NcProduct", [
new NcFieldDescriptor("name", "NcString", false, false, null, "Product name"),
new NcFieldDescriptor("key", "NcString", false, false, null, "Manufacturer's unique key to product - model number, SKU, etc"),
new NcFieldDescriptor("revisionLevel", "NcString", false, false, null, "Manufacturer's product revision level code"),
new NcFieldDescriptor("brandName", "NcString", true, false, null, "Brand name under which product is sold"),
new NcFieldDescriptor("uuid", "NcUuid", true, false, null, "Unique UUID of product (not product instance)"),
new NcFieldDescriptor("description", "NcString", true, false, null, "Text description of product"),
], null, null, "Product descriptor");
}
public ToJson()
{
return JSON.stringify(this, jsonIgnoreReplacer);
}
}
export class NcDeviceOperationalState extends BaseType
{
public generic: NcDeviceGenericState;
public deviceSpecificDetails: string | null;
constructor(
generic: NcDeviceGenericState)
{
super();
this.generic = generic;
this.deviceSpecificDetails = null;
}
public static override GetTypeDescriptor(includeInherited: boolean): NcDatatypeDescriptor
{
return new NcDatatypeDescriptorStruct("NcDeviceOperationalState", [
new NcFieldDescriptor("generic", "NcDeviceGenericState", false, false, null, "Generic operational state"),
new NcFieldDescriptor("deviceSpecificDetails", "NcString", true, false, null, "Specific device details")
], null, null, "Device operational state");
}
public ToJson()
{
return JSON.stringify(this, jsonIgnoreReplacer);
}
}
export enum NcDeviceGenericState
{
Unknown = 0,
NormalOperation = 1,
Initializing = 2,
Updating = 3,
LicensingError = 4,
InternalError = 5
}
export enum NcResetCause
{
Unknown = 0,
PowerOn = 1,
InternalError = 2,
Upgrade = 3,
ControllerRequest = 4,
ManualReset = 5
}
export class NcDeviceManager extends NcManager
{
public static staticClassID: number[] = [ 1, 3, 1 ];
@myIdDecorator('1p1')
public override classID: number[] = NcDeviceManager.staticClassID;
@myIdDecorator('3p1')
public ncVersion: string = "v1.0.0";
@myIdDecorator('3p2')
public manufacturer: NcManufacturer;
@myIdDecorator('3p3')
public product: NcProduct;
@myIdDecorator('3p4')
public serialNumber: string;
@myIdDecorator('3p5')
public userInventoryCode: string | null;
@myIdDecorator('3p6')
public deviceName: string | null;
@myIdDecorator('3p7')
public deviceRole: string | null;
@myIdDecorator('3p8')
public operationalState: NcDeviceOperationalState;
@myIdDecorator('3p9')
public resetCause: NcResetCause;
@myIdDecorator('3p10')
public message: string | null;
public static staticRole: string = "DeviceManager";
public constructor(
oid: number,
constantOid: boolean,
ownerObject: NcObject | null,
userLabel: string,
touchpoints: NcTouchpoint[] | null,
runtimePropertyConstraints: NcPropertyConstraints[] | null,
description: string,
notificationContext: INotificationContext)
{
super(oid, constantOid, ownerObject, NcDeviceManager.staticRole, userLabel, touchpoints, runtimePropertyConstraints, description, notificationContext);
this.manufacturer = new NcManufacturer("Mock manufacturer", "https://specs.amwa.tv/nmos/");
this.product = new NcProduct("Mock device", "mock-001", "1.0.0", "Mock brand", "2dcd15f6-aecc-4f01-bf66-b1044c677ef4", "Mock device for testing and prototyping");
this.serialNumber = "123-mock";
this.userInventoryCode = null;
this.deviceName = null;
this.deviceRole = null;
this.operationalState = new NcDeviceOperationalState(NcDeviceGenericState.NormalOperation);
this.resetCause = NcResetCause.Unknown;
this.message = "Nothing to report";
}
//'1m1'
public override Get(oid: number, propertyId: NcElementId, handle: number) : CommandResponseNoValue
{
if(oid == this.oid)
{
let key: string = `${propertyId.level}p${propertyId.index}`;
switch(key)
{
case '3p1':
return new CommandResponseWithValue(handle, NcMethodStatus.OK, this.ncVersion);
case '3p2':
return new CommandResponseWithValue(handle, NcMethodStatus.OK, this.manufacturer);
case '3p3':
return new CommandResponseWithValue(handle, NcMethodStatus.OK, this.product);
case '3p4':
return new CommandResponseWithValue(handle, NcMethodStatus.OK, this.serialNumber);
case '3p5':
return new CommandResponseWithValue(handle, NcMethodStatus.OK, this.userInventoryCode);
case '3p6':
return new CommandResponseWithValue(handle, NcMethodStatus.OK, this.deviceName);
case '3p7':
return new CommandResponseWithValue(handle, NcMethodStatus.OK, this.deviceRole);
case '3p8':
return new CommandResponseWithValue(handle, NcMethodStatus.OK, this.operationalState);
case '3p9':
return new CommandResponseWithValue(handle, NcMethodStatus.OK, this.resetCause);
case '3p10':
return new CommandResponseWithValue(handle, NcMethodStatus.OK, this.message);
default:
return super.Get(oid, propertyId, handle);
}
}
return new CommandResponseError(handle, NcMethodStatus.BadOid, 'OID could not be found');
}
//'1m2'
public override Set(oid: number, id: NcElementId, value: any, handle: number) : CommandResponseNoValue
{
if(oid == this.oid)
{
let key: string = `${id.level}p${id.index}`;
switch(key)
{
case '3p1':
case '3p2':
case '3p3':
case '3p4':
case '3p8':
case '3p9':
case '3p10':
return new CommandResponseError(handle, NcMethodStatus.Readonly, 'Property is readonly');
case '3p5':
this.userInventoryCode = value;
this.notificationContext.NotifyPropertyChanged(this.oid, id, NcPropertyChangeType.ValueChanged, this.userInventoryCode, null);
return new CommandResponseNoValue(handle, NcMethodStatus.OK);
case '3p6':
this.deviceName = value;
this.notificationContext.NotifyPropertyChanged(this.oid, id, NcPropertyChangeType.ValueChanged, this.deviceName, null);
return new CommandResponseNoValue(handle, NcMethodStatus.OK);
case '3p7':
this.deviceRole = value;
this.notificationContext.NotifyPropertyChanged(this.oid, id, NcPropertyChangeType.ValueChanged, this.deviceRole, null);
return new CommandResponseNoValue(handle, NcMethodStatus.OK);
default:
return super.Set(oid, id, value, handle);
}
}
return new CommandResponseError(handle, NcMethodStatus.BadOid, 'OID could not be found');
}
public static override GetClassDescriptor(includeInherited: boolean): NcClassDescriptor
{
let currentClassDescriptor = new NcClassDescriptor(`${NcDeviceManager.name} class descriptor`,
NcDeviceManager.staticClassID, NcDeviceManager.name, NcDeviceManager.staticRole,
[
new NcPropertyDescriptor(new NcElementId(3, 1), "ncVersion", "NcVersionCode", true, false, false, null, "Version of nc this dev uses"),
new NcPropertyDescriptor(new NcElementId(3, 2), "manufacturer", "NcManufacturer", true, false, false, null, "Manufacturer descriptor", false),
new NcPropertyDescriptor(new NcElementId(3, 3), "product", "NcProduct", true, false, false, null, "Product descriptor", false),
new NcPropertyDescriptor(new NcElementId(3, 4), "serialNumber", "NcString", true, false, false, null, "Serial number"),
new NcPropertyDescriptor(new NcElementId(3, 5), "userInventoryCode", "NcString", false, true, false, null, "Asset tracking identifier (user specified)"),
new NcPropertyDescriptor(new NcElementId(3, 6), "deviceName", "NcString", false, true, false, null, "Name of this device in the application. Instance name, not product name."),
new NcPropertyDescriptor(new NcElementId(3, 7), "deviceRole", "NcString", false, true, false, null, "Role of this device in the application."),
new NcPropertyDescriptor(new NcElementId(3, 8), "operationalState", "NcDeviceOperationalState", true, false, false, null, "Device operational state"),
new NcPropertyDescriptor(new NcElementId(3, 9), "resetCause", "NcResetCause", true, false, false, null, "Reason for most recent reset"),
new NcPropertyDescriptor(new NcElementId(3, 10), "message", "NcString", true, true, false, null, "Arbitrary message from dev to controller"),
],
[],
[]
);
if(includeInherited)
{
let baseDescriptor = super.GetClassDescriptor(includeInherited);
currentClassDescriptor.properties = currentClassDescriptor.properties.concat(baseDescriptor.properties);
currentClassDescriptor.methods = currentClassDescriptor.methods.concat(baseDescriptor.methods);
currentClassDescriptor.events = currentClassDescriptor.events.concat(baseDescriptor.events);
}
return currentClassDescriptor;
}
}
export class NcClassManager extends NcManager
{
public static staticClassID: number[] = [ 1, 3, 2 ];
@myIdDecorator('1p1')
public override classID: number[] = NcClassManager.staticClassID;
@myIdDecorator('3p1')
public controlClasses: NcClassDescriptor[];
@myIdDecorator('3p2')
public dataTypes: NcDatatypeDescriptor[];
public static staticRole: string = "ClassManager";
private controlClassesRegister: { [key: string]: NcClassDescriptor };
private dataTypesRegister: { [key: string]: NcDatatypeDescriptor };
public constructor(
oid: number,
constantOid: boolean,
ownerObject: NcObject | null,
userLabel: string,
touchpoints: NcTouchpoint[] | null,
runtimePropertyConstraints: NcPropertyConstraints[] | null,
description: string,
notificationContext: INotificationContext)
{
super(oid, constantOid, ownerObject, NcClassManager.staticRole, userLabel, touchpoints, runtimePropertyConstraints, description, notificationContext);
this.controlClassesRegister = this.GenerateClassDescriptors();
this.controlClasses = Object.values(this.controlClassesRegister);
this.dataTypesRegister = this.GenerateTypeDescriptors();
this.dataTypes = Object.values(this.dataTypesRegister);
}
//'1m1'
public override Get(oid: number, propertyId: NcElementId, handle: number) : CommandResponseNoValue
{
if(oid == this.oid)
{
let key: string = `${propertyId.level}p${propertyId.index}`;
switch(key)
{
case '3p1':
return new CommandResponseWithValue(handle, NcMethodStatus.OK, this.controlClasses);
case '3p2':
return new CommandResponseWithValue(handle, NcMethodStatus.OK, this.dataTypes);
default:
return super.Get(oid, propertyId, handle);
}
}
return new CommandResponseError(handle, NcMethodStatus.BadOid, 'OID could not be found');
}
public override InvokeMethod(socket: WebSocketConnection, oid: number, methodId: NcElementId, args: { [key: string]: any; } | null, handle: number): CommandResponseNoValue
{
if(oid == this.oid)
{
let key: string = `${methodId.level}m${methodId.index}`;
switch(key)
{
case '1m3': //GetSequenceItem
{
if(args != null &&
'id' in args &&
'index' in args)
{
let propertyId = args['id'] as NcElementId;
let index = args['index'] as number;
if(propertyId)
{
if(index >= 0)
{
let propertyKey: string = `${propertyId.level}p${propertyId.index}`;
switch(propertyKey)
{
case '3p1':
{
let itemValue = this.controlClasses[index];
if(itemValue)
return new CommandResponseWithValue(handle, NcMethodStatus.OK, itemValue);
else
return new CommandResponseError(handle, NcMethodStatus.IndexOutOfBounds, 'Index could not be found');
}
case '3p2':
{
let itemValue = this.dataTypes[index];
if(itemValue)
return new CommandResponseWithValue(handle, NcMethodStatus.OK, itemValue);
else
return new CommandResponseError(handle, NcMethodStatus.IndexOutOfBounds, 'Index could not be found');
}
default:
return new CommandResponseError(handle, NcMethodStatus.PropertyNotImplemented, 'Property could not be found');
}
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid index argument provided');
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid id argument provided');
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid arguments provided');
}
case '1m4': //SetSequenceItem
{
if(args != null &&
'id' in args &&
'index' in args &&
'value' in args)
{
let propertyId = args['id'] as NcElementId;
if(propertyId)
{
let propertyKey: string = `${propertyId.level}p${propertyId.index}`;
return new CommandResponseError(handle, NcMethodStatus.Readonly, `Property ${propertyKey} is readonly`);
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid id argument provided');
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid arguments provided');
}
case '1m5': //AddSequenceItem
{
if(args != null &&
'id' in args &&
'value' in args)
{
let propertyId = args['id'] as NcElementId;
if(propertyId)
{
let propertyKey: string = `${propertyId.level}p${propertyId.index}`;
return new CommandResponseError(handle, NcMethodStatus.Readonly, `Property ${propertyKey} is readonly`);
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid id argument provided');
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid arguments provided');
}
case '1m6': //RemoveSequenceItem
{
if(args != null &&
'id' in args &&
'index' in args)
{
let propertyId = args['id'] as NcElementId;
if(propertyId)
{
let propertyKey: string = `${propertyId.level}p${propertyId.index}`;
return new CommandResponseError(handle, NcMethodStatus.Readonly, `Property ${propertyKey} is readonly`);
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid id argument provided');
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid arguments provided');
}
case '1m7': //GetSequenceLength
{
if(args != null &&
'id' in args)
{
let propertyId = args['id'] as NcElementId;
if(propertyId)
{
let propertyKey: string = `${propertyId.level}p${propertyId.index}`;
switch(propertyKey)
{
case '3p1':
{
let length = this.controlClasses.length;
return new CommandResponseWithValue(handle, NcMethodStatus.OK, length);
}
case '3p2':
{
let length = this.dataTypes.length;
return new CommandResponseWithValue(handle, NcMethodStatus.OK, length);
}
default:
return new CommandResponseError(handle, NcMethodStatus.PropertyNotImplemented, 'Property could not be found');
}
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid id argument provided');
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Invalid arguments provided');
}
case '3m1':
{
if(args != null && 'classId' in args)
{
if('includeInherited' in args)
{
let classId = args['classId'] as number[];
let includeInherited = args['includeInherited'] as boolean;
if(includeInherited)
{
let descriptor = this.GetClassDescriptor(classId, true);
if(descriptor)
return new CommandResponseWithValue(handle, NcMethodStatus.OK, descriptor);
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Descriptor for class could not be found');
}
else
{
let descriptor = this.GetClassDescriptor(classId, false);
if(descriptor)
return new CommandResponseWithValue(handle, NcMethodStatus.OK, descriptor);
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Descriptor for class could not be found');
}
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'No includeInherited argument provided');
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'No class identity has been provided');
}
case '3m2':
{
if(args != null && 'name' in args)
{
if('includeInherited' in args)
{
let name = args['name'] as string;
let includeInherited = args['includeInherited'] as boolean;
if(includeInherited)
{
let descriptor = this.GetTypeDescriptor(name, true);
if(descriptor)
return new CommandResponseWithValue(handle, NcMethodStatus.OK, descriptor);
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Descriptor for type could not be found');
}
else
{
let descriptor = this.GetTypeDescriptor(name, false);
if(descriptor)
return new CommandResponseWithValue(handle, NcMethodStatus.OK, descriptor);
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'Descriptor for type could not be found');
}
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'No includeInherited argument provided');
}
else
return new CommandResponseError(handle, NcMethodStatus.InvalidRequest, 'No type name has been provided');
}
default:
return super.InvokeMethod(socket, oid, methodId, args, handle);
}
}
return new CommandResponseError(handle, NcMethodStatus.BadOid, 'OID could not be found');
}
public static override GetClassDescriptor(includeInherited: boolean): NcClassDescriptor
{
let currentClassDescriptor = new NcClassDescriptor(`${NcClassManager.name} class descriptor`,
NcClassManager.staticClassID, NcClassManager.name, NcClassManager.staticRole,
[
new NcPropertyDescriptor(new NcElementId(3, 1), "controlClasses", "NcClassDescriptor", true, false, true, null, "Descriptions of all control classes in the device (descriptors do not contain inherited elements)"),
new NcPropertyDescriptor(new NcElementId(3, 2), "datatypes", "NcDatatypeDescriptor", true, false, true, null, "Descriptions of all data types in the device (descriptors do not contain inherited elements)")
],
[
new NcMethodDescriptor(new NcElementId(3, 1), "GetControlClass", "NcMethodResultClassDescriptor", [
new NcParameterDescriptor("classId", "NcClassId", false, false, null, "class ID"),
new NcParameterDescriptor("includeInherited", "NcBoolean", false, false, null, "if set the descriptor would contain all inherited elements")
], "Get a single class descriptor"),
new NcMethodDescriptor(new NcElementId(3, 2), "GetDatatype", "NcMethodResultDatatypeDescriptor", [
new NcParameterDescriptor("name", "NcName", false, false, null, "name of datatype"),
new NcParameterDescriptor("includeInherited", "NcBoolean", false, false, null, "if set the descriptor would contain all inherited elements")
], "Get a single datatype descriptor")
],
[]
);
if(includeInherited)
{
let baseDescriptor = super.GetClassDescriptor(includeInherited);
currentClassDescriptor.properties = currentClassDescriptor.properties.concat(baseDescriptor.properties);
currentClassDescriptor.methods = currentClassDescriptor.methods.concat(baseDescriptor.methods);
currentClassDescriptor.events = currentClassDescriptor.events.concat(baseDescriptor.events);
}
return currentClassDescriptor;
}
private GenerateClassDescriptors() : { [key: string]: NcClassDescriptor }
{
let register = {
'1': NcObject.GetClassDescriptor(false),
'1.1': NcBlock.GetClassDescriptor(false),
'1.2': NcWorker.GetClassDescriptor(false),
'1.2.0.1': GainControl.GetClassDescriptor(false),
'1.2.0.2': ExampleControl.GetClassDescriptor(false),
'1.2.1': NcIdentBeacon.GetClassDescriptor(false),
'1.2.2': NcStatusMonitor.GetClassDescriptor(false),
'1.2.2.1': NcReceiverMonitor.GetClassDescriptor(false),
'1.2.2.2': NcSenderMonitor.GetClassDescriptor(false),
'1.3': NcManager.GetClassDescriptor(false),
'1.3.1': NcDeviceManager.GetClassDescriptor(false),
'1.3.2': NcClassManager.GetClassDescriptor(false)
};
return register;
}
private GenerateClassDescriptorWithInheritedElements(identity: number[]) : NcClassDescriptor | null
{
let key: string = identity.join('.');
switch (key)
{
case '1': return NcObject.GetClassDescriptor(true);
case '1.1': return NcBlock.GetClassDescriptor(true);
case '1.2': return NcWorker.GetClassDescriptor(true);
case '1.2.0.1': return GainControl.GetClassDescriptor(true);
case '1.2.0.2': return ExampleControl.GetClassDescriptor(true);
case '1.2.1': return NcIdentBeacon.GetClassDescriptor(true);
case '1.2.2': return NcStatusMonitor.GetClassDescriptor(true);
case '1.2.2.1': return NcReceiverMonitor.GetClassDescriptor(true);
case '1.2.2.2': return NcSenderMonitor.GetClassDescriptor(true);
case '1.3': return NcManager.GetClassDescriptor(true);
case '1.3.1': return NcDeviceManager.GetClassDescriptor(true);
case '1.3.2': return NcClassManager.GetClassDescriptor(true);
default: return null;
}
}
private GenerateTypeDescriptors() : { [key: string]: NcDatatypeDescriptor }
{
let register = {
'NcBoolean': new NcDatatypeDescriptorPrimitive("NcBoolean", null, "Boolean primitive type"),
'NcInt16': new NcDatatypeDescriptorPrimitive("NcInt16", null, "short"),
'NcInt32': new NcDatatypeDescriptorPrimitive("NcInt32", null, "long"),
'NcInt64': new NcDatatypeDescriptorPrimitive("NcInt64", null, "longlong"),
'NcUint16': new NcDatatypeDescriptorPrimitive("NcUint16", null, "unsignedshort"),
'NcUint32': new NcDatatypeDescriptorPrimitive("NcUint32", null, "unsignedlong"),
'NcUint64': new NcDatatypeDescriptorPrimitive("NcUint64", null, "unsignedlonglong"),
'NcFloat32': new NcDatatypeDescriptorPrimitive("NcFloat32", null, "unrestrictedfloat"),
'NcFloat64': new NcDatatypeDescriptorPrimitive("NcFloat64", null, "unrestricteddouble"),
'NcString': new NcDatatypeDescriptorPrimitive("NcString", null, "UTF-8 string"),
'NcClassId': new NcDatatypeDescriptorTypeDef("NcClassId", "NcInt32", true, null, "Sequence of class ID fields."),
'NcVersionCode': new NcDatatypeDescriptorTypeDef("NcVersionCode", "NcString", false, null, "Version code in semantic versioning format"),
'NcUri': new NcDatatypeDescriptorTypeDef("NcUri", "NcString", false, null, "Uniform resource identifier"),
'NcOrganizationId': new NcDatatypeDescriptorTypeDef("NcOrganizationId", "NcInt32", false, null, "Unique 24-bit organization ID"),
'NcManufacturer': NcManufacturer.GetTypeDescriptor(false),
'NcProduct': NcProduct.GetTypeDescriptor(false),
'NcDeviceGenericState': new NcDatatypeDescriptorEnum("NcDeviceGenericState", [
new NcEnumItemDescriptor("Unknown", 0, "Unknown"),
new NcEnumItemDescriptor("NormalOperation", 1, "Normal operation"),
new NcEnumItemDescriptor("Initializing", 2, "Device is initializing"),
new NcEnumItemDescriptor("Updating", 3, "Device is performing a software or firmware update"),
new NcEnumItemDescriptor("LicensingError", 4, "Device is experiencing a licensing error"),
new NcEnumItemDescriptor("InternalError", 5, "Device is experiencing an internal error")
], null, "Device generic operational state"),
'NcResetCause': new NcDatatypeDescriptorEnum("NcResetCause", [
new NcEnumItemDescriptor("Unknown", 0, "Unknown"),
new NcEnumItemDescriptor("PowerOn", 1, "Power on"),
new NcEnumItemDescriptor("InternalError", 2, "Internal error"),
new NcEnumItemDescriptor("Upgrade", 3, "Upgrade"),
new NcEnumItemDescriptor("ControllerRequest", 4, "Controller request"),
new NcEnumItemDescriptor("ManualReset", 5, "Manual request from the front panel")
], null, "Reset cause enum"),
'NcDeviceOperationalState': NcDeviceOperationalState.GetTypeDescriptor(false),
'NcOid': new NcDatatypeDescriptorTypeDef("NcOid", "NcUint32", false, null, "Object id"),
'NcName': new NcDatatypeDescriptorTypeDef("NcName", "NcString", false, null, "Programmatically significant name, alphanumerics + underscore, no spaces"),
'NcUuid': new NcDatatypeDescriptorTypeDef("NcUuid", "NcString", false, null, "UUID"),
'NcRolePath': new NcDatatypeDescriptorTypeDef("NcRolePath", "NcString", true, null, "Role path"),
'NcId': new NcDatatypeDescriptorTypeDef("NcId", "NcUint32", false, null, "Identity handler"),
'NcTimeInterval': new NcDatatypeDescriptorTypeDef("NcTimeInterval", "NcInt64", false, null, "Time interval described in nanoseconds"),
'NcElementId': NcElementId.GetTypeDescriptor(false),
'NcPropertyId': NcPropertyId.GetTypeDescriptor(false),
'NcMethodId': NcMethodId.GetTypeDescriptor(false),
'NcEventId': NcEventId.GetTypeDescriptor(false),
'NcDescriptor': NcDescriptor.GetTypeDescriptor(false),
'NcDatatypeDescriptor': NcDatatypeDescriptor.GetTypeDescriptor(false),
'NcDatatypeDescriptorPrimitive': NcDatatypeDescriptorPrimitive.GetTypeDescriptor(false),
'NcDatatypeDescriptorTypeDef': NcDatatypeDescriptorTypeDef.GetTypeDescriptor(false),
'NcDatatypeDescriptorStruct': NcDatatypeDescriptorStruct.GetTypeDescriptor(false),
'NcDatatypeDescriptorEnum': NcDatatypeDescriptorEnum.GetTypeDescriptor(false),
'NcPropertyDescriptor': NcPropertyDescriptor.GetTypeDescriptor(false),
'NcFieldDescriptor': NcFieldDescriptor.GetTypeDescriptor(false),
'NcEnumItemDescriptor': NcEnumItemDescriptor.GetTypeDescriptor(false),
'NcParameterDescriptor': NcParameterDescriptor.GetTypeDescriptor(false),
'NcMethodDescriptor': NcMethodDescriptor.GetTypeDescriptor(false),
'NcEventDescriptor': NcEventDescriptor.GetTypeDescriptor(false),
'NcClassDescriptor': NcClassDescriptor.GetTypeDescriptor(false),
'NcParameterConstraints': NcParameterConstraints.GetTypeDescriptor(false),
'NcParameterConstraintsNumber': NcParameterConstraintsNumber.GetTypeDescriptor(false),
'NcParameterConstraintsString': NcParameterConstraintsString.GetTypeDescriptor(false),
'NcCounter': NcCounter.GetTypeDescriptor(false),
'NcPropertyChangeType': new NcDatatypeDescriptorEnum("NcPropertyChangeType", [
new NcEnumItemDescriptor("ValueChanged", 0, "Current value changed"),
new NcEnumItemDescriptor("SequenceItemAdded", 1, "Sequence item added"),
new NcEnumItemDescriptor("SequenceItemChanged", 2, "Sequence item changed"),
new NcEnumItemDescriptor("SequenceItemRemoved", 3, "Sequence item removed")
], null, "Type of property change"),
'NcDatatypeType': new NcDatatypeDescriptorEnum("NcDatatypeType", [
new NcEnumItemDescriptor("Primitive", 0, "Primitive datatype"),
new NcEnumItemDescriptor("Typedef", 1, "Simple alias of another datatype"),
new NcEnumItemDescriptor("Struct", 2, "Data structure"),
new NcEnumItemDescriptor("Enum", 3, "Enum datatype")
], null, "Datatype type"),
'NcPropertyChangedEventData': NcPropertyChangedEventData.GetTypeDescriptor(false),
'NcMethodStatus': new NcDatatypeDescriptorEnum("NcMethodStatus", [
new NcEnumItemDescriptor("Ok", 200, "Method call was successful"),
new NcEnumItemDescriptor("PropertyDeprecated", 298, "Method call was successful but targeted property is deprecated"),
new NcEnumItemDescriptor("MethodDeprecated", 299, "Method call was successful but method is deprecated"),
new NcEnumItemDescriptor("BadCommandFormat", 400, "Badly-formed command"),
new NcEnumItemDescriptor("Unauthorized", 401, "Client is not authorized"),
new NcEnumItemDescriptor("BadOid", 404, "Command addresses a nonexistent object"),
new NcEnumItemDescriptor("Readonly", 405, "Attempt to change read-only state"),
new NcEnumItemDescriptor("InvalidRequest", 406, "Method call is invalid in current operating context"),
new NcEnumItemDescriptor("Conflict", 409, "There is a conflict with the current state of the device"),
new NcEnumItemDescriptor("BufferOverflow", 413, "Something was too big"),
new NcEnumItemDescriptor("IndexOutOfBounds", 414, "Index is outside the available range"),
new NcEnumItemDescriptor("ParameterError", 417, "Method parameter does not meet expectations"),
new NcEnumItemDescriptor("Locked", 423, "Addressed object is locked"),
new NcEnumItemDescriptor("DeviceError", 500, "Internal device error"),
new NcEnumItemDescriptor("MethodNotImplemented", 501, "Addressed method is not implemented by the addressed object"),
new NcEnumItemDescriptor("PropertyNotImplemented", 502, "Addressed property is not implemented by the addressed object"),
new NcEnumItemDescriptor("NotReady", 503, "The device is not ready to handle any commands"),
new NcEnumItemDescriptor("Timeout", 504, "Method call did not finish within the allotted time")
], null, "Method invokation status"),
'NcMethodResult': NcMethodResult.GetTypeDescriptor(false),
'NcMethodResultError': NcMethodResultError.GetTypeDescriptor(false),
'NcMethodResultPropertyValue': NcMethodResultPropertyValue.GetTypeDescriptor(false),
'NcMethodResultId': NcMethodResultId.GetTypeDescriptor(false),
'NcMethodResultLength': NcMethodResultLength.GetTypeDescriptor(false),
'NcBlockMemberDescriptor': NcBlockMemberDescriptor.GetTypeDescriptor(false),
'NcMethodResultBlockMemberDescriptors': NcMethodResultBlockMemberDescriptors.GetTypeDescriptor(false),
'NcMethodResultClassDescriptor': NcMethodResultClassDescriptor.GetTypeDescriptor(false),
'NcMethodResultDatatypeDescriptor': NcMethodResultDatatypeDescriptor.GetTypeDescriptor(false),
'NcMethodResultCounters': NcMethodResultCounters.GetTypeDescriptor(false),
'NcOverallStatus': new NcDatatypeDescriptorEnum("NcOverallStatus", [
new NcEnumItemDescriptor("Inactive", 0, "Inactive"),
new NcEnumItemDescriptor("Healthy", 1, "Active and healthy"),
new NcEnumItemDescriptor("PartiallyHealthy", 2, "Active and partially healthy"),
new NcEnumItemDescriptor("Unhealthy", 3, "Active and unhealthy")
], null, "Overall monitor status enum data type"),
'NcLinkStatus': new NcDatatypeDescriptorEnum("NcLinkStatus", [
new NcEnumItemDescriptor("AllUp", 1, "All the associated network interfaces are down"),
new NcEnumItemDescriptor("SomeDown", 2, "Some of the associated network interfaces are down"),
new NcEnumItemDescriptor("AllDown", 3, "All the associated network interfaces are up")
], null, "Link status enum data type"),
'NcConnectionStatus': new NcDatatypeDescriptorEnum("NcConnectionStatus", [
new NcEnumItemDescriptor("Inactive", 0, "Inactive"),
new NcEnumItemDescriptor("Healthy", 1, "Active and healthy"),
new NcEnumItemDescriptor("PartiallyHealthy", 2, "Active and partially healthy"),
new NcEnumItemDescriptor("Unhealthy", 3, "Active and unhealthy")
], null, "Connection status enum data type"),
'NcTransmissionStatus': new NcDatatypeDescriptorEnum("NcTransmissionStatus", [
new NcEnumItemDescriptor("Inactive", 0, "Inactive"),
new NcEnumItemDescriptor("Healthy", 1, "Active and healthy"),
new NcEnumItemDescriptor("PartiallyHealthy", 2, "Active and partially healthy"),
new NcEnumItemDescriptor("Unhealthy", 3, "Active and unhealthy")
], null, "Transmission status enum data type"),
'NcSynchronizationStatus': new NcDatatypeDescriptorEnum("NcSynchronizationStatus", [
new NcEnumItemDescriptor("NotUsed", 0, "Feature not in use"),
new NcEnumItemDescriptor("Healthy", 1, "Locked to a synchronization source"),
new NcEnumItemDescriptor("PartiallyHealthy", 2, "Partially locked to a synchronization source"),
new NcEnumItemDescriptor("Unhealthy", 3, "Not locked to a synchronization source")
], null, "Synchronization status enum data type"),
'NcStreamStatus': new NcDatatypeDescriptorEnum("NcStreamStatus", [
new NcEnumItemDescriptor("Inactive", 0, "Inactive"),
new NcEnumItemDescriptor("Healthy", 1, "Active and healthy"),
new NcEnumItemDescriptor("PartiallyHealthy", 2, "Active and partially healthy"),
new NcEnumItemDescriptor("Unhealthy", 3, "Active and unhealthy")
], null, "Stream status enum data type"),
'NcEssenceStatus': new NcDatatypeDescriptorEnum("NcEssenceStatus", [
new NcEnumItemDescriptor("Inactive", 0, "Inactive"),
new NcEnumItemDescriptor("Healthy", 1, "Active and healthy"),
new NcEnumItemDescriptor("PartiallyHealthy", 2, "Active and partially healthy"),
new NcEnumItemDescriptor("Unhealthy", 3, "Active and unhealthy")
], null, "Essence status enum data type"),
'NcTouchpoint': NcTouchpoint.GetTypeDescriptor(false),
'NcTouchpointResource': NcTouchpointResource.GetTypeDescriptor(false),
'NcTouchpointNmos': NcTouchpointNmos.GetTypeDescriptor(false),
'NcTouchpointResourceNmos': NcTouchpointResourceNmos.GetTypeDescriptor(false),
'NcTouchpointNmosChannelMapping': NcTouchpointNmosChannelMapping.GetTypeDescriptor(false),
'NcTouchpointResourceNmosChannelMapping': NcTouchpointResourceNmosChannelMapping.GetTypeDescriptor(false),
'ExampleEnum': new NcDatatypeDescriptorEnum("ExampleEnum", [
new NcEnumItemDescriptor("Undefined", 0, "Not defined option"),
new NcEnumItemDescriptor("Alpha", 1, "Alpha option"),
new NcEnumItemDescriptor("Beta", 2, "Beta option"),
new NcEnumItemDescriptor("Gamma", 3, "Gamma option")
], null, "Example enum data type"),
'ExampleDataType': ExampleDataType.GetTypeDescriptor(false),
'NcRegex': new NcDatatypeDescriptorTypeDef("NcRegex", "NcString", false, null, "Regex pattern"),
'NcPropertyConstraints': NcPropertyConstraints.GetTypeDescriptor(false),
'NcPropertyConstraintsNumber': NcPropertyConstraintsNumber.GetTypeDescriptor(false),
'NcPropertyConstraintsString': NcPropertyConstraintsString.GetTypeDescriptor(false)
};
return register;
}
private GenerateTypeDescriptorWithInheritedElements(name: string) : NcDatatypeDescriptor | null
{
switch (name)
{
case 'NcPropertyId': return NcPropertyId.GetTypeDescriptor(true);
case 'NcMethodId': return NcMethodId.GetTypeDescriptor(true);
case 'NcEventId': return NcEventId.GetTypeDescriptor(true);
case 'NcDatatypeDescriptor': return NcDatatypeDescriptor.GetTypeDescriptor(true);
case 'NcDatatypeDescriptorPrimitive': return NcDatatypeDescriptorPrimitive.GetTypeDescriptor(true);
case 'NcDatatypeDescriptorTypeDef': return NcDatatypeDescriptorTypeDef.GetTypeDescriptor(true);
case 'NcDatatypeDescriptorStruct': return NcDatatypeDescriptorStruct.GetTypeDescriptor(true);
case 'NcDatatypeDescriptorEnum': return NcDatatypeDescriptorEnum.GetTypeDescriptor(true);
case 'NcPropertyDescriptor': return NcPropertyDescriptor.GetTypeDescriptor(true);
case 'NcFieldDescriptor': return NcFieldDescriptor.GetTypeDescriptor(true);
case 'NcEnumItemDescriptor': return NcEnumItemDescriptor.GetTypeDescriptor(true);
case 'NcParameterDescriptor': return NcParameterDescriptor.GetTypeDescriptor(true);
case 'NcMethodDescriptor': return NcMethodDescriptor.GetTypeDescriptor(true);
case 'NcEventDescriptor': return NcEventDescriptor.GetTypeDescriptor(true);
case 'NcClassDescriptor': return NcClassDescriptor.GetTypeDescriptor(true);
case 'NcParameterConstraintsNumber': return NcParameterConstraintsNumber.GetTypeDescriptor(true);
case 'NcParameterConstraintsString': return NcParameterConstraintsString.GetTypeDescriptor(true);
case 'NcCounter': return NcCounter.GetTypeDescriptor(true);
case 'NcBlockMemberDescriptor': return NcBlockMemberDescriptor.GetTypeDescriptor(true);
case 'NcTouchpointNmos': return NcTouchpointNmos.GetTypeDescriptor(true);
case 'NcTouchpointNmosChannelMapping': return NcTouchpointNmosChannelMapping.GetTypeDescriptor(true);
case 'NcTouchpointResourceNmos': return NcTouchpointResourceNmos.GetTypeDescriptor(true);
case 'NcTouchpointResourceNmosChannelMapping': return NcTouchpointResourceNmosChannelMapping.GetTypeDescriptor(true);
case 'NcPropertyConstraintsNumber': return NcPropertyConstraintsNumber.GetTypeDescriptor(true);
case 'NcPropertyConstraintsString': return NcPropertyConstraintsString.GetTypeDescriptor(true);
case 'NcMethodResultError': return NcMethodResultError.GetTypeDescriptor(true);
case 'NcMethodResultPropertyValue': return NcMethodResultPropertyValue.GetTypeDescriptor(true);
case 'NcMethodResultBlockMemberDescriptors': return NcMethodResultBlockMemberDescriptors.GetTypeDescriptor(true);
case 'NcMethodResultClassDescriptor': return NcMethodResultClassDescriptor.GetTypeDescriptor(true);
case 'NcMethodResultDatatypeDescriptor': return NcMethodResultDatatypeDescriptor.GetTypeDescriptor(true);
case 'NcMethodResultId': return NcMethodResultId.GetTypeDescriptor(true);
case 'NcMethodResultLength': return NcMethodResultLength.GetTypeDescriptor(true);
case 'NcMethodResultCounters': return NcMethodResultCounters.GetTypeDescriptor(true);
default: return this.dataTypesRegister[name];
}
}
private GetClassDescriptor(identity: number[], includeInherited: boolean) : NcClassDescriptor | null
{
if(includeInherited)
return this.GenerateClassDescriptorWithInheritedElements(identity);
else
{
let key: string = identity.join('.');
return this.controlClassesRegister[key];
}
}
private GetTypeDescriptor(name: string, includeInherited: boolean) : NcDatatypeDescriptor | null
{
if(includeInherited)
return this.GenerateTypeDescriptorWithInheritedElements(name);
else
return this.dataTypesRegister[name];
}
}