EPTF_CLL_DataSourceClient_Functions.ttcn 114 KB
Newer Older
Elemer Lelik's avatar
Elemer Lelik committed
1
2
///////////////////////////////////////////////////////////////////////////////
//                                                                           //
balaskoa's avatar
balaskoa committed
3
// Copyright (c) 2000-2018 Ericsson Telecom AB                               //
Elemer Lelik's avatar
Elemer Lelik committed
4
5
//                                                                           //
// All rights reserved. This program and the accompanying materials          //
balaskoa's avatar
balaskoa committed
6
// are made available under the terms of the Eclipse Public License v2.0     //
Elemer Lelik's avatar
Elemer Lelik committed
7
// which accompanies this distribution, and is available at                  //
balaskoa's avatar
balaskoa committed
8
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html                                 //
Elemer Lelik's avatar
Elemer Lelik committed
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
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////
//  Module: EPTF_CLL_DataSourceClient_Functions
// 
//  Purpose:
//    This module contains the implementation of EPTF_CLL_DataSource functions.
// 
//  Module depends on:
//    <EPTF_CLL_Base_Functions>
//    <EPTF_CLL_Variable_Functions>
//    <EPTF_CLL_DataSource_Definitions>
//    <EPTF_CLL_HashMapStr2Int_Functions>
//    <EPTF_CLL_HashMap_Functions>
//    <EPTF_CLL_Semaphore_Functions>
//    <EPTF_CLL_Variable_Definitions>
//
//  Module Parameters:
//    tsp_debug_EPTF_DataSource_Functions - boolean - enable/disable debug logs
//
//  Current Owner:
//    Jozsef Gyurusi (ethjgi)
// 
//  Last Review Date:
//    2011-02-03
//
//  Detailed Comments:
//    This module contains the interface functions for the EPTF_CLL_DataSource.
//
//    Public functions:
//       <f_EPTF_DataSourceClient_init_CT>
//       <f_EPTF_DataSourceClient_connectToServer>
//       <f_EPTF_DataSourceClient_registerData>
//       <f_EPTF_DataSourceClient_registerDataValue>
//       <f_EPTF_DataSourceClient_registerSetDataValue>
//       <f_EPTF_DataSourceClient_registerCondition>
//       <f_EPTF_DataSourceClient_sendReady>
//       <f_EPTF_DataSourceClient_getData>
//       <f_EPTF_DataSourceClient_getData_nonBlocking>
//       <f_EPTF_DataSourceClient_getDataValue>
//       <f_EPTF_DataSourceClient_getDataValue_nonBlocking>
//       <f_EPTF_DataSourceClient_setDataValue>
//       <f_EPTF_DataSourceClient_setDataValue_nonBlocking>
//       <f_EPTF_DataSourceClient_checkData>
//       <f_EPTF_DataSourceClient_enableUpdate>
//       <f_EPTF_DataSourceClient_disableUpdate>
//       <f_EPTF_DataSourceClient_getCondition> - to be implemented
//       <f_EPTF_DataSourceClient_getCondition_nonBlocking>
//       <f_EPTF_DataSourceClient_extractParams>
//
//    All other functions in this module are private! 
//
///////////////////////////////////////////////////////////////

module EPTF_CLL_DataSourceClient_Functions {
import from EPTF_CLL_Logging_Definitions all;

import from EPTF_CLL_Logging_Functions all;

import from EPTF_CLL_Common_Definitions all;


import from EPTF_CLL_Base_Functions all;
import from EPTF_CLL_Variable_Functions all;
import from EPTF_CLL_DataSource_Definitions all;
import from EPTF_CLL_DataSource_Functions all;
import from EPTF_CLL_HashMapStr2Int_Functions all;
import from EPTF_CLL_HashMap_Functions all;
import from EPTF_CLL_Semaphore_Functions all;
import from EPTF_CLL_Variable_Definitions all;


///////////////////////////////////////////////////////////
//  Function: f_EPTF_DataSourceClient_init_CT
// 
//  Purpose:
//    Init function for DataSourceClient_CT
//
//  Parameters:
//    *in charstring pl_selfName* - the name of the component
//    *in* <EPTF_DataSource_CT> *pl_sourceCompRef* - the 
//      main DataSource component (server).
//      If it is null, no connection is made, the function
//      <f_EPTF_DataSourceClient_connectToServer> should be called
//      later.
//
//  Return Value:
//    -
//
//  Detailed Comments:
//    Has to be called before any other DataSourceClient
//    function is used
///////////////////////////////////////////////////////////
public function f_EPTF_DataSourceClient_init_CT(in charstring pl_selfName, in EPTF_DataSource_CT pl_sourceCompRef)
runs on EPTF_DataSourceClient_CT {
  if (v_EPTF_DataSourceClient_initialized) {
    return;
  }
  f_EPTF_Base_init_CT(pl_selfName);
  f_EPTF_Logging_init_CT(pl_selfName);
  f_EPTF_Var_init_CT(pl_selfName);
  f_EPTF_HashMap_init_CT(pl_selfName);
  f_EPTF_Semaphore_init_CT(pl_selfName);
  v_EPTF_DataSourceClient_connected := false;
  f_EPTF_DataSourceClient_connectToServer(pl_sourceCompRef);
  v_EPTF_DataSourceClient_initialized := true;
  v_DataSourceClient_handler := activate(as_EPTF_DataSourceClient_EventHandler());
  f_EPTF_Base_registerCleanup(refers(f_EPTF_DataSourceClient_cleanup_CT));

  v_fcb_EPTF_DataSourceClient_dataHandler_List := {};
  v_fcb_EPTF_DataSourceClient_dataValueHandler_List := {};
  v_fcb_EPTF_DataSourceClient_setDataValueHandler_List := {};
  v_EPTF_DataSourceClient_dataHandlerHash := f_EPTF_str2int_HashMap_New(c_EPTF_DataSourceClient_dataHandlerHashName);
  
  v_fcb_EPTF_DataSourceClient_conditionHandler_List := {};

  v_EPTF_DataSourceClient_dataValueHash := f_EPTF_str2int_HashMap_New(c_EPTF_DataSourceClient_dataValueHashName);
  v_EPTF_DataSourceClient_dataValue_List := {};
  v_EPTF_DataSourceClient_Msg_List := {};
  v_EPTF_DataSourceClient_GetDataHandler_DB := {};
  v_EPTF_DataSourceClient_GetDataValueHandler_DB := {};
  v_EPTF_DataSourceClient_pendingGetDataHash := f_EPTF_str2int_HashMap_New(c_EPTF_DataSourceClient_pendingGetDataHashName);
}


///////////////////////////////////////////////////////////
//  Function: f_EPTF_DataSourceClient_connectToServer
// 
//  Purpose:
//    Connects to the specified DataSource component
//
//  Parameters:
//    *in <EPTF_DataSource_CT> pl_sourceCompRef* - the DataSource_CT componentRef
//       to connect to. If it is null, no connection is made.
//
//  Return Value:
//    -
//
//  Detailed Comments:
//    If this function is called only once with non-null argument,
//    the <f_EPTF_DataSourceClient_registerData> can be called
//    without specifying the *pl_sourceCompRef* argument.
///////////////////////////////////////////////////////////
public function f_EPTF_DataSourceClient_connectToServer(in EPTF_DataSource_CT pl_sourceCompRef) runs on EPTF_DataSourceClient_CT {
  if (pl_sourceCompRef!=null) {
    connect(pl_sourceCompRef:EPTF_DataSourceIf,self:EPTF_DataSourceClientIf);
    v_EPTF_DataSourceClient_connected := true;
  }
}

///////////////////////////////////////////////////////////
//  Function: f_EPTF_DataSourceClient_registerData
// 
//  Purpose:
//    Registers a data handler into the DataSource_CT
//
//  Parameters:
//    *in charstring pl_source* - the name of the dataSource 'feature'
//    *in charstring pl_ptcName* - the name of the PTC
//         (dataSource+ptcName should be a unigue id of the data). Default: "" (i.e. PTC name is ignored)
//    *in <fcb_EPTF_DataSourceClient_dataHandler> pl_dataHandler* - this function is called
//       when a data is requested for the given dataSource and ptcName
//       The function should return the name of the EPTF Variable that contains the value
//       of the requested data.
//    *in <EPTF_DataSource_CT> pl_sourceCompRef* - the DataSource_CT componentRef
//       to register the data into. If not specified the data is registered to the only one
//       DataSource component which is connected (= for which the <f_EPTF_DataSourceClient_connectToServer> was called)
//
//  Return Value:
//    -
//
//  Detailed Comments:
//    Only one handler can be registered for the same pl_source and pl_ptcName,
//    but it processes all dataElements and its parameters.
//    The function might create the variable, or just return
//    its name if it already existed before.
//    The registered function can be called by calling <f_EPTF_DataSource_getData>
//    on the component pl_sourceCompRef with the pl_source and pl_ptcName arguments registered here.
//    Compare with <f_EPTF_DataSourceClient_registerDataValue>.
///////////////////////////////////////////////////////////
public function f_EPTF_DataSourceClient_registerData(
  in charstring pl_source,
  in charstring pl_ptcName := "",
  in fcb_EPTF_DataSourceClient_dataHandler pl_dataHandler,
  in EPTF_DataSource_CT pl_sourceCompRef := null
) runs on EPTF_DataSourceClient_CT {
  if(not v_EPTF_DataSourceClient_connected) {
    f_EPTF_DataSourceClient_warning(log2str(%definitionId&": Cannot register handler fn ",pl_dataHandler,
        "for pl_source: ",pl_source," pl_ptcName: ",pl_ptcName, " into pl_sourceCompRef: ",pl_sourceCompRef,": Not connected to DataSource"));
    return;
  }
  
  var charstring vl_handlerIdStr := pl_source&"@"&pl_ptcName;
  var integer vl_handlerId := -1;
  if (not f_EPTF_str2int_HashMap_Find(v_EPTF_DataSourceClient_dataHandlerHash,vl_handlerIdStr,vl_handlerId)) {
    vl_handlerId := sizeof(v_fcb_EPTF_DataSourceClient_dataHandler_List);
    v_fcb_EPTF_DataSourceClient_dataHandler_List[vl_handlerId] := pl_dataHandler;
    f_EPTF_str2int_HashMap_Insert(v_EPTF_DataSourceClient_dataHandlerHash,vl_handlerIdStr,vl_handlerId);
  } else {
    f_EPTF_DataSourceClient_warning(log2str(%definitionId&": Cannot register handler fn ",pl_dataHandler,
        "for pl_source: ",pl_source," pl_ptcName: ",pl_ptcName,": Handler already registered"));
    return;
  }
  f_EPTF_DataSourceClient_registerSource(pl_source,pl_ptcName,pl_sourceCompRef);
}

///////////////////////////////////////////////////////////
//  Function: f_EPTF_DataSourceClient_registerDataValue
// 
//  Purpose:
//    Registers a dataValue handler into the DataSource_CT
//
//  Parameters:
//    *in charstring pl_source* - the name of the dataSource 'feature'
//    *in charstring pl_ptcName* - the name of the PTC
//         (dataSource+ptcName should be a unigue id of the data). Default: "" (i.e. PTC name is ignored)
//    *in <fcb_EPTF_DataSourceClient_dataValueHandler> pl_dataValueHandler* - this function is called
//       when a data value is requested for the given dataSource and ptcName
//       The function should return the value of the requested data.
//    *in <EPTF_DataSource_CT> pl_sourceCompRef* - the DataSource_CT componentRef
//       to register the data into. If not specified the data is registered to the only one
//       DataSource component which is connected (= for which the <f_EPTF_DataSourceClient_connectToServer> was called)
//
//  Return Value:
//    -
//
//  Detailed Comments:
//    Only one value-handler can be registered for the same pl_source and pl_ptcName,
//    but it processes all dataElements and its parameters.
//    
//    The registered function can be called by calling <f_EPTF_DataSource_getDataValue>
//    on the component pl_sourceCompRef with the pl_source and pl_ptcName arguments registered here.
//    
//    Note, that if no dataValue-handler was specified, getData handlers are checked
//    if they can return the variable name for the requested data. If they can, the value
//    contained in the variable will be returned.
//    If there is no such variable, the condition handlers are checked. If there is a condition,
//    its value will be retured.
//    This means that getDataValue can be used for dataElements with getDataHandler only or request the value
//    of conditions.
///////////////////////////////////////////////////////////
public function f_EPTF_DataSourceClient_registerDataValue(
  in charstring pl_source,
  in charstring pl_ptcName := "",
  in fcb_EPTF_DataSourceClient_dataValueHandler pl_dataValueHandler,
  in EPTF_DataSource_CT pl_sourceCompRef := null
) runs on EPTF_DataSourceClient_CT {
  if(not v_EPTF_DataSourceClient_connected) {
    f_EPTF_DataSourceClient_warning(log2str(%definitionId&": Cannot register value-handler fn ",pl_dataValueHandler,
        "for pl_source: ",pl_source," pl_ptcName: ",pl_ptcName, " into pl_sourceCompRef: ",pl_sourceCompRef,": Not connected to DataSource"));
    return;
  }
  
  // data value handler names will be prefixed with "DVH_", uses same hashTable
  var charstring vl_handlerIdStr := "DVH_"&pl_source&"@"&pl_ptcName;
  var integer vl_handlerId := -1;
  if (not f_EPTF_str2int_HashMap_Find(v_EPTF_DataSourceClient_dataHandlerHash,vl_handlerIdStr,vl_handlerId)) {
    vl_handlerId := sizeof(v_fcb_EPTF_DataSourceClient_dataValueHandler_List);
    v_fcb_EPTF_DataSourceClient_dataValueHandler_List[vl_handlerId] := pl_dataValueHandler;
    f_EPTF_str2int_HashMap_Insert(v_EPTF_DataSourceClient_dataHandlerHash,vl_handlerIdStr,vl_handlerId);
  } else {
    f_EPTF_DataSourceClient_warning(log2str(%definitionId&": Cannot register value-handler fn ",pl_dataValueHandler,
        "for pl_source: ",pl_source," pl_ptcName: ",pl_ptcName,": Value-handler already registered"));
    return;
  }
  f_EPTF_DataSourceClient_registerSource(pl_source,pl_ptcName,pl_sourceCompRef);
}

///////////////////////////////////////////////////////////
//  Function: f_EPTF_DataSourceClient_registerSetDataValue
// 
//  Purpose:
//    Registers a setDataValue handler into the DataSource_CT
//
//  Parameters:
//    *in charstring pl_source* - the name of the dataSource 'feature'
//    *in charstring pl_ptcName* - the name of the PTC
//         (dataSource+ptcName should be a unigue id of the data). Default: "" (i.e. PTC name is ignored)
//    *in <fcb_EPTF_DataSourceClient_setDataValueHandler> pl_setDataValueHandler* - this function is called
//       when a set data value is requested for the given dataSource and ptcName
//    *in <EPTF_DataSource_CT> pl_sourceCompRef* - the DataSource_CT componentRef
//       to register the data into. If not specified the data is registered to the only one
//       DataSource component which is connected (= for which the <f_EPTF_DataSourceClient_connectToServer> was called)
//
//  Return Value:
//    -
//
//  Detailed Comments:
//    Only one setDataValue handler can be registered for the same pl_source and pl_ptcName,
//    but it processes all dataElements and its parameters.
//    
//    The registered function can be called by calling <f_EPTF_DataSource_setDataValue>
//    on the component pl_sourceCompRef with the pl_source and pl_ptcName arguments registered here.
//
//    Note, that if there is a getData handler but no setDataValue handler for the given data,
//    the value of the variable returned by the getData handler will be set to the requested value.
///////////////////////////////////////////////////////////
public function f_EPTF_DataSourceClient_registerSetDataValue(
  in charstring pl_source,
  in charstring pl_ptcName := "",
  in fcb_EPTF_DataSourceClient_setDataValueHandler pl_setDataValueHandler,
  in EPTF_DataSource_CT pl_sourceCompRef := null
) runs on EPTF_DataSourceClient_CT {
  if(not v_EPTF_DataSourceClient_connected) {
    f_EPTF_DataSourceClient_warning(log2str(%definitionId&": Cannot register set-value-handler fn ",pl_setDataValueHandler,
        "for pl_source: ",pl_source," pl_ptcName: ",pl_ptcName, " into pl_sourceCompRef: ",pl_sourceCompRef,": Not connected to DataSource"));
    return;
  }
  
  // set data value handler names will be prefixed with "SDVH_", uses same hashTable
  var charstring vl_handlerIdStr := "SDVH_"&pl_source&"@"&pl_ptcName;
  var integer vl_handlerId := -1;
  if (not f_EPTF_str2int_HashMap_Find(v_EPTF_DataSourceClient_dataHandlerHash,vl_handlerIdStr,vl_handlerId)) {
    vl_handlerId := sizeof(v_fcb_EPTF_DataSourceClient_setDataValueHandler_List);
    v_fcb_EPTF_DataSourceClient_setDataValueHandler_List[vl_handlerId] := pl_setDataValueHandler;
    f_EPTF_str2int_HashMap_Insert(v_EPTF_DataSourceClient_dataHandlerHash,vl_handlerIdStr,vl_handlerId);
  } else {
    f_EPTF_DataSourceClient_warning(log2str(%definitionId&": Cannot register value-handler fn ",pl_setDataValueHandler,
        "for pl_source: ",pl_source," pl_ptcName: ",pl_ptcName,": Set-Value-handler already registered"));
    return;
  }
  f_EPTF_DataSourceClient_registerSource(pl_source,pl_ptcName,pl_sourceCompRef);
}

///////////////////////////////////////////////////////////
//  Function: f_EPTF_DataSourceClient_registerCondition
// 
//  Purpose:
//    Registers a condition handler into the DataSource_CT
//
//  Parameters:
//    *in charstring pl_source* - the name of the dataSource 'feature'
//    *in charstring pl_ptcName* - the name of the PTC
//         (dataSource+ptcName should be a unigue id of the data). Default: "" (i.e. PTC name is ignored)
//    *in <fcb_EPTF_DataSourceClient_conditionHandler> pl_conditionHandler* - this function is called
//       when a condition value is requested for the given dataSource, ptcName and method
//    *in charstring pl_method* - the name of the method that corresponds to this condition handler
//         (dataSource+ptcName should be a unigue id of the location of the condition) and
//         (dataSource+ptcName+method should be a unigue id of the condition). Default: "" which means
//        that log2str(pl_conditionHandler) is used for the method.
//    *in <EPTF_DataSource_CT> pl_sourceCompRef* - the DataSource_CT componentRef
//       to register the data into. If not specified the data is registered to the only one
//       DataSource component which is connected (= for which the <f_EPTF_DataSourceClient_connectToServer> was called)
//
//  Return Value:
//    -
//
//  Detailed Comments:
//    Only one handler can be registered for the same pl_source, pl_ptcName and pl_method,
//    but it processes all parameters.
//    The registered function can be called by calling <f_EPTF_DataSource_getCondition>
//    on the component pl_sourceCompRef with the pl_source,pl_ptcName and pl_method arguments registered here.
///////////////////////////////////////////////////////////
public function f_EPTF_DataSourceClient_registerCondition(
  in charstring pl_source,
  in charstring pl_ptcName := "",
  in fcb_EPTF_DataSourceClient_conditionHandler pl_conditionHandler,
  in charstring pl_method := "",
  in EPTF_DataSource_CT pl_sourceCompRef := null
) runs on EPTF_DataSourceClient_CT {
  if(not v_EPTF_DataSourceClient_connected) {
    f_EPTF_DataSourceClient_warning(log2str(%definitionId&": Cannot register condition handler fn ",pl_conditionHandler,
        "for pl_source: ",pl_source," pl_ptcName: ",pl_ptcName, " pl_method: ",pl_method, " into pl_sourceCompRef: ",pl_sourceCompRef,": Not connected to DataSource"));
    return;
  }
  if (pl_method=="") {
    pl_method := log2str(pl_conditionHandler);
  }
  var charstring vl_handlerIdStr := pl_source&"@"&pl_ptcName&"/"&pl_method;
  var integer vl_handlerId := -1;
  if (not f_EPTF_str2int_HashMap_Find(v_EPTF_DataSourceClient_dataHandlerHash,vl_handlerIdStr,vl_handlerId)) {
    vl_handlerId := sizeof(v_fcb_EPTF_DataSourceClient_conditionHandler_List);
    v_fcb_EPTF_DataSourceClient_conditionHandler_List[vl_handlerId] := pl_conditionHandler;
    f_EPTF_str2int_HashMap_Insert(v_EPTF_DataSourceClient_dataHandlerHash,vl_handlerIdStr,vl_handlerId);
  } else {
    f_EPTF_DataSourceClient_warning(log2str(%definitionId&": Cannot register condition handler fn ",pl_conditionHandler,
        "for pl_source: ",pl_source," pl_ptcName: ",pl_ptcName," pl_method: ",pl_method,": Handler already registered"));
    return;
  }
  f_EPTF_DataSourceClient_registerSource(pl_source,pl_ptcName,pl_sourceCompRef);
}


private function f_EPTF_DataSourceClient_registerSource(
  in charstring pl_source,
  in charstring pl_ptcName := "",
  in EPTF_DataSource_CT pl_sourceCompRef := null
) runs on EPTF_DataSourceClient_CT {
  // send registerData if it was not already sent:
  var charstring vl_handlerIdStr := "Registered:"&pl_source&"@"&pl_ptcName;
  var integer vl_handlerId := -1;
  if (not f_EPTF_str2int_HashMap_Find(v_EPTF_DataSourceClient_dataHandlerHash,vl_handlerIdStr,vl_handlerId)) {
    f_EPTF_str2int_HashMap_Insert(v_EPTF_DataSourceClient_dataHandlerHash,vl_handlerIdStr,vl_handlerId);
    f_EPTF_DataSourceClient_sendMsg(EPTF_DataSource_Msg:{registerData:={pl_source,pl_ptcName}},pl_sourceCompRef);
  }
}

///////////////////////////////////////////////////////////
//  Function: f_EPTF_DataSourceClient_sendReady
// 
//  Purpose:
//    Notifies the DataSource_CT that the client is ready to receive data requests
//
//  Parameters:
//    *in charstring pl_source* - the name of the dataSource 'feature'
//    *in charstring pl_ptcName* - the name of the PTC
//         (dataSource+ptcName should be a unigue id of the data)
//    *in <EPTF_DataSource_CT> pl_sourceCompRef* - the DataSource_CT componentRef
//       If not specified the data is sent to the only one
//       DataSource component which is connected (= for which the <f_EPTF_DataSourceClient_connectToServer> was called)
//
//  Return Value:
//    -
//
//  Detailed Comments:
//    Notifies the DataSource_CT that the client is ready to receive data requests.
//    When a client becomes ready on the DataSource component, the callback functions
//    registered by <f_EPTF_DataSource_registerReadyCallback> are called.
///////////////////////////////////////////////////////////
public function f_EPTF_DataSourceClient_sendReady(
  in charstring pl_source,
  in charstring pl_ptcName,
  in EPTF_DataSource_CT pl_sourceCompRef := null)
runs on EPTF_DataSourceClient_CT {
  if(not v_EPTF_DataSourceClient_connected) {
    f_EPTF_DataSourceClient_warning(log2str(%definitionId&": Cannot send Ready ",
        "for pl_source: ",pl_source," pl_ptcName: ",pl_ptcName, " to pl_sourceCompRef: ",pl_sourceCompRef,": Not connected to DataSource"));
    return;
  }
  f_EPTF_DataSourceClient_sendMsg(EPTF_DataSource_Msg:{clientReady:={pl_source, pl_ptcName}}, pl_sourceCompRef);
}

///////////////////////////////////////////////////////////
//  Function: f_EPTF_DataSourceClient_getData
// 
//  Purpose:
//    To get the value of a given data
//
//  Parameters:
//    *out charstring pl_dataVarName* - this is the name of the variable
//       that stores the values of the data on the local component
//    *in charstring pl_source* - the name of the dataSource 'feature'
//    *in charstring pl_ptcName* - the name of the PTC
//         (dataSource+ptcName should be a unigue id of the data). Default: "" (i.e. PTC name is ignored)
//    *in charstring pl_element* - the type of data
//    *in* <EPTF_DataSource_Params> *pl_params* - additional parameters (default: {})
//       The parameters are sorted lexicographically according to the paramNames
//    *in* <EPTF_Var_SubscriptionMode> - pl_subscriptionMode - subscription mode: sampled or timeLine: buffered; realtime: non-buffered
//       Default: tsp_EPTF_DataSource_subscriptionMode
//    *in integer* - pl_refreshRate - the refresh rate for the subscription.
//      default: tsp_EPTF_DataSource_refreshRate
//    *in <EPTF_DataSource_CT> pl_sourceCompRef* - the DataSource_CT componentRef to get the value from
//       If not specified the data is requested from the only one
//       DataSource component which is connected (= for which the <f_EPTF_DataSourceClient_connectToServer> was called)
//
//  Return Value:
//    integer - 0 if OK, nonzero in case of failure to show that the pl_dataVarName is not valid
//
//  Detailed Comments:
//    This function will make a request for the given data source and return the name of the
//    variable that contains the value of the data.
//
//    How it works:
//    Sends a request to the main DataSource_CT component
//    to request the EPTF Variable name for the given dataSource.
//    It will automatically subscribe to the source variable.
//    The subscription is done directly to the source PTC, there is no subscription
//    performed by the DataSource_CT
//
//    In case of error, the pl_dataVarName argument may contain a charstring with an error message.
///////////////////////////////////////////////////////////
public function f_EPTF_DataSourceClient_getData(
  out charstring pl_dataVarName,
  in charstring pl_source,
  in charstring pl_ptcName := "",
  in charstring pl_element,
  in EPTF_DataSource_Params pl_params := {},
  in EPTF_Var_SubscriptionMode pl_subscriptionMode := tsp_EPTF_DataSource_subscriptionMode,
  in integer pl_refreshRate := tsp_EPTF_DataSource_refreshRate,
  in EPTF_DataSource_CT pl_sourceCompRef := null
) runs on EPTF_DataSourceClient_CT return integer {
  if(not v_EPTF_DataSourceClient_connected) {
    f_EPTF_DataSourceClient_warning(log2str(%definitionId&": Cannot get data ",
        "for pl_source: ",pl_source," pl_ptcName: ",pl_ptcName, " pl_element: ",pl_element," pl_params: ",pl_params, " from pl_sourceCompRef: ",pl_sourceCompRef,": Not connected to DataSource"));
    pl_dataVarName := "";
    return -99;
  }
  
  f_EPTF_DataSource_sortParams(pl_params);

  pl_dataVarName := "";
  var integer vl_localDataVarId;
  var EPTF_Var_CT vl_ownerCompRef;
  var charstring vl_remoteDataVarName;
  // check if already subscribed:
  var charstring vl_dataValueIdStr := pl_source&"@"&pl_ptcName&"."&pl_element&":"&log2str(pl_params);
  var integer vl_dataValueId;
  var integer vl_errorCode;
  if (f_EPTF_str2int_HashMap_Find(v_EPTF_DataSourceClient_dataValueHash,vl_dataValueIdStr,vl_dataValueId)) {

    if (vl_dataValueId==-1) {
      // PTC name is not given, but should be specified
      pl_dataVarName := "";
      return 1;
    }
    
    vl_localDataVarId := v_EPTF_DataSourceClient_dataValue_List[vl_dataValueId].localDataVarId;
    pl_dataVarName := f_EPTF_Var_getName(vl_localDataVarId);

    // check if var exists: it is needed because checkData does not create it, but stores it in the hashMap
    // if var is not subscribed, subscribe is needed => no error if variable is not found
    if(f_EPTF_Var_checkSubscriptionMode(vl_localDataVarId,pl_subscriptionMode)) {
      return 0;
    }

    vl_remoteDataVarName := v_EPTF_DataSourceClient_dataValue_List[vl_dataValueId].remoteDataVarName;
    vl_ownerCompRef := v_EPTF_DataSourceClient_dataValue_List[vl_dataValueId].ownerCompRef;
    vl_errorCode := 0;
  } else {
  
    var integer vl_transactionId := f_EPTF_Semaphore_new();
    f_EPTF_DataSourceClient_sendMsg(EPTF_DataSource_Msg:{getData:={
      transactionId := vl_transactionId,
      dataSource := pl_source,
      ptcName := pl_ptcName,
      dataElement := pl_element,
      params := pl_params
    }}, pl_sourceCompRef);

    //wait for the result:
    if (f_EPTF_Semaphore_waitForUnlock(vl_transactionId,tsp_EPTF_DataSourceClient_maxWaitTime)) {
      // max wait time expired before response received:
      f_EPTF_DataSourceClient_warning(log2str(%definitionId&": Communication error: No response received for getData message: ",vl_transactionId));
      pl_dataVarName := "";
      return -1;
    }

    // copy the values from the message database because it might be possible that they will be overwritten because
    // the semaphore is released and there is a blocking statement before they are used:
    vl_ownerCompRef := v_EPTF_DataSourceClient_Msg_List[vl_transactionId].dataValue.ownerCompRef;
    vl_remoteDataVarName := v_EPTF_DataSourceClient_Msg_List[vl_transactionId].dataValue.dataVarName;
    vl_errorCode := v_EPTF_DataSourceClient_Msg_List[vl_transactionId].dataValue.errorCode;

    //set the variable name
    // this will always be true if errorCode == 0:
    if (f_EPTF_str2int_HashMap_Find(v_EPTF_DataSourceClient_dataValueHash,vl_dataValueIdStr,vl_dataValueId)) {
      vl_localDataVarId := v_EPTF_DataSourceClient_dataValue_List[vl_dataValueId].localDataVarId;
      pl_dataVarName := f_EPTF_Var_getName(vl_localDataVarId);

      if(f_EPTF_Var_checkSubscriptionMode(vl_localDataVarId,pl_subscriptionMode)) {
        return 0;
      }
    }
  }
  
  //subscribe to the source variable:
  // if returned error code is 0 (no error) subscibe to the provider data variable:
  if (vl_errorCode==0) {
    // The presence of the source variable is not checked. It was done on the main dataSource component.
    // If error code is 0, it will be there

    f_EPTF_Var_resubscribeRemote(
      vl_ownerCompRef,
      vl_remoteDataVarName,
      pl_subscriptionMode,
      vl_localDataVarId,
      pl_dataVarName,
      pl_refreshRate
    );
  } else {
    f_EPTF_DataSourceClient_warning(vl_remoteDataVarName); // warning message is received in the dataVarName
  }
  return vl_errorCode;
}

///////////////////////////////////////////////////////////
//  Function: f_EPTF_DataSourceClient_getData_nonBlocking
// 
//  Purpose:
//    To get the value of a given data in non-blocking way.
//    The specified handler is called when the response arrives.
//
//  Parameters:
//    *in charstring pl_source* - the name of the dataSource 'feature'
//    *in charstring pl_ptcName* - the name of the PTC
//         (dataSource+ptcName should be a unigue id of the data). Default: "" (i.e. PTC name is ignored)
//    *in charstring pl_element* - the type of data
//    *in* <EPTF_DataSource_Params> *pl_params* - additional parameters (default: {})
//       The parameters are sorted lexicographically according to the paramNames
//    *in* <EPTF_DataSource_GetDataHandler> - pl_getDataHandler - the handler function (with user arguments) to call
//       when response is received
//    *in <EPTF_DataSource_CT> pl_sourceCompRef* - the DataSource_CT componentRef to get the value from
//       If not specified the data is requested from the only one
//       DataSource component which is connected (= for which the <f_EPTF_DataSourceClient_connectToServer> was called)
//
//  Return Value:
//    integer - 0 if request is OK, nonzero if request is invalid. In both cases the handler will be called.
//
//  Detailed Comments:
//    Sends a request to the main DataSource_CT component
//    to request the EPTF Variable name for the given dataSource.
//    The given handler function is called when the response is available.
//    A local variable is created which stores the current value of the dataSource,
//    but this variable is not subscribed to the data owner.
///////////////////////////////////////////////////////////
public function f_EPTF_DataSourceClient_getData_nonBlocking(
  in charstring pl_source,
  in charstring pl_ptcName := "",
  in charstring pl_element,
  in EPTF_DataSource_Params pl_params := {},
  in EPTF_DataSource_GetDataHandler pl_getDataHandler := cg_EPTF_DataSource_GetDataHandler_null,
  in EPTF_DataSource_CT pl_sourceCompRef := null
) runs on EPTF_DataSourceClient_CT return integer {

  var integer vl_errorCode;

  if(not v_EPTF_DataSourceClient_connected) {
    vl_errorCode := -99;
    var charstring vl_errorMsg := log2str(%definitionId&": Cannot get data ",
        "for pl_source: ",pl_source," pl_ptcName: ",pl_ptcName, " pl_element: ",pl_element," pl_params: ",pl_params, " from pl_sourceCompRef: ",pl_sourceCompRef,": Not connected to DataSource");
    f_EPTF_DataSourceClient_warning(vl_errorMsg);

    // call handler:
    if (pl_getDataHandler.getDataHandler!=null) {
      pl_getDataHandler.getDataHandler.apply(
        //request parameters:
        pl_source := pl_source,
        pl_ptcName := pl_ptcName,                   // response may fill this if it was ""
        pl_element := pl_element,
        pl_params := pl_params,
        // reponse parameters:
        pl_errorCode := vl_errorCode,               // error code in the response
        pl_remoteDataVarName := vl_errorMsg,     // var name on the remote component. In case errorCode!=0: it contains the error message
        pl_ownerCompRef := null,         // reference to the remote component
        pl_localDataVarId := -1,               // var id on the local component (contains the current value, not subscribed to remote!)
        pl_dataValue := {charstringVal:=vl_errorMsg},               // the value of the data
        // user data
        pl_userData := pl_getDataHandler.userData  // user specific data given at the request
      );
    }
    return vl_errorCode;
  }
  
  f_EPTF_DataSource_sortParams(pl_params);

  // check if already subscribed:
  var charstring vl_dataValueIdStr := pl_source&"@"&pl_ptcName&"."&pl_element&":"&log2str(pl_params);
  var integer vl_dataValueId;
  if (f_EPTF_str2int_HashMap_Find(v_EPTF_DataSourceClient_dataValueHash,vl_dataValueIdStr,vl_dataValueId)) {
    
    var EPTF_Var_CT vl_ownerCompRef;
    var charstring vl_remoteDataVarName;  // for nonzero error code it contains the error message
    var integer vl_localDataVarId;
    var EPTF_Var_DirectContent vl_dataValue;

    if (vl_dataValueId==-1) {
      // PTC name is not given, but should be specified
      vl_errorCode := 1;
      vl_remoteDataVarName := log2str(%definitionId&": Cannot get source component for dataSource ",pl_source, " and ptcName ",pl_ptcName,
        ": PTC name is not given, but should be specified since more than one PTC exist with the same source.");

      vl_ownerCompRef := null;
      vl_localDataVarId := -1;
      vl_dataValue := {unknownVal:={omit}};
    } else {
//     pl_dataVarName := f_EPTF_Var_getName(vl_localDataVarId);
      vl_errorCode := 0;
      vl_remoteDataVarName := v_EPTF_DataSourceClient_dataValue_List[vl_dataValueId].remoteDataVarName;
      vl_ownerCompRef := v_EPTF_DataSourceClient_dataValue_List[vl_dataValueId].ownerCompRef;
      vl_localDataVarId := v_EPTF_DataSourceClient_dataValue_List[vl_dataValueId].localDataVarId;
      vl_dataValue := {unknownVal:={omit}};
      if(vl_localDataVarId!=-1) {
        f_EPTF_Var_getContent(vl_localDataVarId,vl_dataValue);
      }
    }

    // call handler:
    if (pl_getDataHandler.getDataHandler!=null) {

      pl_getDataHandler.getDataHandler.apply(
        //request parameters:
        pl_source := pl_source,
        pl_ptcName := pl_ptcName,                   // response may fill this if it was ""
        pl_element := pl_element,
        pl_params := pl_params,
        // reponse parameters:
        pl_errorCode := vl_errorCode,               // error code in the response
        pl_remoteDataVarName := vl_remoteDataVarName,     // var name on the remote component. In case errorCode!=0: it contains the error message
        pl_ownerCompRef := vl_ownerCompRef,         // reference to the remote component
        pl_localDataVarId := vl_localDataVarId,               // var id on the local component (contains the current value, not subscribed to remote!)
        pl_dataValue := vl_dataValue,               // the value of the data
        // user data
        pl_userData := pl_getDataHandler.userData  // user specific data given at the request
      );

    }
    return vl_errorCode;
  } else {
  
    //recalculate vl_dataValueIdStr with given PTCName:
    vl_dataValueIdStr := pl_source&"@"&pl_ptcName&"."&pl_element&":"&log2str(pl_params);
    var integer vl_transactionId;
    // check if there is a pending request:
    if (f_EPTF_str2int_HashMap_Find(v_EPTF_DataSourceClient_pendingGetDataHash,vl_dataValueIdStr,vl_transactionId)) {
      v_EPTF_DataSourceClient_GetDataHandler_DB[vl_transactionId] := v_EPTF_DataSourceClient_GetDataHandler_DB[vl_transactionId] & {pl_getDataHandler};
    } else {
      vl_transactionId := f_EPTF_Semaphore_new();
      v_EPTF_DataSourceClient_GetDataHandler_DB[vl_transactionId] := {pl_getDataHandler};
      //f_EPTF_str2int_HashMap_Insert(v_EPTF_DataSourceClient_pendingGetDataHash,vl_dataValueIdStr,vl_transactionId);
      f_EPTF_DataSourceClient_sendMsg(EPTF_DataSource_Msg:{getData:={
        transactionId := vl_transactionId,
        dataSource := pl_source,
        ptcName := pl_ptcName,
        dataElement := pl_element,
        params := pl_params
      }}, pl_sourceCompRef);
    }

    vl_errorCode := 0;
  }
  
  return vl_errorCode;
}

///////////////////////////////////////////////////////////
//  Function: f_EPTF_DataSourceClient_getDataValue
// 
//  Purpose:
//    To get the value of a given data
//
//  Parameters:
//    *out* <EPTF_Var_DirectContent> *pl_dataValue* - this is the value of the data requested
//    *in charstring pl_source* - the name of the dataSource 'feature'
//    *in charstring pl_ptcName* - the name of the PTC
//         (dataSource+ptcName should be a unigue id of the data). Default: "" (i.e. PTC name is ignored)
//    *in charstring pl_element* - the type of data
//    *in* <EPTF_DataSource_Params> *pl_params* - additional parameters (default: {})
//       The parameters are sorted lexicographically according to the paramNames
//    *in <EPTF_DataSource_CT> pl_sourceCompRef* - the DataSource_CT componentRef to get the value from
//       If not specified the data is requested from the only one
//       DataSource component which is connected (= for which the <f_EPTF_DataSourceClient_connectToServer> was called)
//
//  Return Value:
//    integer - 0 if OK, nonzero in case of failure to show that the pl_dataVarName is not valid
//
//  Detailed Comments:
//    This function will make a request for the given data source and return the value of the data.
//
//    How it works:
//    The request is forwarded to the appropriate DataSourceClient which registered
//    the source and ptc name. On the client the handler function registered by
//    <f_EPTF_DataSourceClient_registerData> for the given pl_source and pl_ptcName is called.
//    The pl_params are passed to it as additional arguments.
//    The handler function returns a <EPTF_Var_DirectContent> value which is set in the pl_dataValue
//    argument. The value will be returned by this function
//    together with the error code returned by the handler function.
//
//    In case of error, the pl_dataValue argument may contain a charstring with an error message.
///////////////////////////////////////////////////////////
public function f_EPTF_DataSourceClient_getDataValue(
  out EPTF_Var_DirectContent pl_dataValue,
  in charstring pl_source,
  in charstring pl_ptcName := "",
  in charstring pl_element,
  in EPTF_DataSource_Params pl_params := {},
  in EPTF_DataSource_Filter pl_filter := c_EPTF_DataSource_Filter_empty,
  in EPTF_DataSource_CT pl_sourceCompRef := null
) runs on EPTF_DataSourceClient_CT return integer {
  
  var integer vl_errorCode;

  if(not v_EPTF_DataSourceClient_connected) {
    vl_errorCode := -99;
    var charstring vl_errorMsg := log2str(%definitionId&": Cannot get data value ",
        "for pl_source: ",pl_source," pl_ptcName: ",pl_ptcName, " pl_element: ",pl_element," pl_params: ",pl_params, " from pl_sourceCompRef: ",pl_sourceCompRef,": Not connected to DataSource");
    f_EPTF_DataSourceClient_warning(vl_errorMsg);
    pl_dataValue := {charstringVal :=  vl_errorMsg};
    return vl_errorCode;
  }
    
  f_EPTF_DataSource_sortParams(pl_params);
  
  var integer vl_transactionId := f_EPTF_Semaphore_new();
  f_EPTF_DataSourceClient_sendMsg(EPTF_DataSource_Msg:{getDataValue:={
    transactionId := vl_transactionId,
    dataSource := pl_source,
    ptcName := pl_ptcName,
    dataElement := pl_element,
    params := pl_params,
    filter := pl_filter
  }}, pl_sourceCompRef);

  //wait for the result:
  if (f_EPTF_Semaphore_waitForUnlock(vl_transactionId,tsp_EPTF_DataSourceClient_maxWaitTime)) {
    // max wait time expired before response received:
    f_EPTF_DataSourceClient_warning(log2str(%definitionId&": Communication error: No response received for getDataValue message: ",vl_transactionId));
    pl_dataValue := {charstringVal :=  log2str(%definitionId&": Communication error: No response received for getDataValue message: ",vl_transactionId)};
    return -1;
  }

  // copy the values from the message database because it might be possible that they will be overwritten because
  // the semaphore is released and there is a blocking statement before they are used:
  //vl_ownerCompRef := v_EPTF_DataSourceClient_Msg_List[vl_transactionId].dataValue.ownerCompRef;
  pl_dataValue := v_EPTF_DataSourceClient_Msg_List[vl_transactionId].dataValueResponse.dataValue;
  vl_errorCode := v_EPTF_DataSourceClient_Msg_List[vl_transactionId].dataValueResponse.errorCode;  
  return vl_errorCode;
}


///////////////////////////////////////////////////////////
//  Function: f_EPTF_DataSourceClient_getDataValue_nonBlocking
// 
//  Purpose:
//    To get the value of a given data in non-blocking way.
//    The specified handler is called when the response arrives.
//
//  Parameters:
//    *in charstring pl_source* - the name of the dataSource 'feature'
//    *in charstring pl_ptcName* - the name of the PTC
//         (dataSource+ptcName should be a unigue id of the data). Default: "" (i.e. PTC name is ignored)
//    *in charstring pl_element* - the type of data
//    *in* <EPTF_DataSource_Params> *pl_params* - additional parameters (default: {})
//       The parameters are sorted lexicographically according to the paramNames
//    *in* <EPTF_DataSource_GetDataValueHandler> - pl_getDataValueHandler - the handler function (with user arguments) to call
//       when response is received
//    *in <EPTF_DataSource_CT> pl_sourceCompRef* - the DataSource_CT componentRef to get the value from
//       If not specified the data is requested from the only one
//       DataSource component which is connected (= for which the <f_EPTF_DataSourceClient_connectToServer> was called)
//
//  Return Value:
//    integer - 0 if request is OK, nonzero in case of invalid request
//
//  Detailed Comments:
//    This function will make a request for the given data source and return the value of the data.
//
//    How it works:
//    The request is forwarded to the appropriate DataSourceClient which registered
//    the source and ptc name. On the client the handler function registered by
//    <f_EPTF_DataSourceClient_registerDataValue> for the given pl_source and pl_ptcName is called.
//    The pl_params are passed to it as additional arguments.
//    The handler function returns a value which is set in its pl_dataValue
//    argument and an error code set in the pl_errorCode argument. These parameters are passed to the
//    handler function given in pl_getDataValueHandler.
///////////////////////////////////////////////////////////
public function f_EPTF_DataSourceClient_getDataValue_nonBlocking(
  in charstring pl_source,
  in charstring pl_ptcName := "",
  in charstring pl_element,
  in EPTF_DataSource_Params pl_params := {},
  in EPTF_DataSource_Filter pl_filter := c_EPTF_DataSource_Filter_empty,
  in EPTF_DataSource_GetDataValueHandler pl_getDataValueHandler := cg_EPTF_DataSource_GetDataValueHandler_null,
  in EPTF_DataSource_CT pl_sourceCompRef := null
) runs on EPTF_DataSourceClient_CT return integer {
  
  var integer vl_errorCode;

  if(not v_EPTF_DataSourceClient_connected) {
    vl_errorCode := -99;
    var charstring vl_errorMsg := log2str(%definitionId&": Cannot get data value ",
        "for pl_source: ",pl_source," pl_ptcName: ",pl_ptcName, " pl_element: ",pl_element," pl_params: ",pl_params, " from pl_sourceCompRef: ",pl_sourceCompRef,": Not connected to DataSource");
    f_EPTF_DataSourceClient_warning(vl_errorMsg);

    // call handler:
    if (pl_getDataValueHandler.getDataValueHandler!=null) {
      pl_getDataValueHandler.getDataValueHandler.apply(
        // reponse parameters:
        pl_errorCode := vl_errorCode,               // error code in the response
        pl_dataValue := {charstringVal:=vl_errorMsg},               // the value of the data
        // user data
        pl_userData := pl_getDataValueHandler.userData  // user specific data given at the request
      );
    }
    return vl_errorCode;
  }
  
  
  f_EPTF_DataSource_sortParams(pl_params);

  var integer vl_transactionId := f_EPTF_Semaphore_new();
  v_EPTF_DataSourceClient_GetDataValueHandler_DB[vl_transactionId] := pl_getDataValueHandler;
  f_EPTF_DataSourceClient_sendMsg(EPTF_DataSource_Msg:{getDataValue:={
    transactionId := vl_transactionId,
    dataSource := pl_source,
    ptcName := pl_ptcName,
    dataElement := pl_element,
    params := pl_params,
    filter := pl_filter
  }}, pl_sourceCompRef);

  vl_errorCode := 0;  
  return vl_errorCode;
}


///////////////////////////////////////////////////////////
//  Function: f_EPTF_DataSourceClient_setDataValue
// 
//  Purpose:
//    To set the value of a given data
//
//  Parameters:
//    *inout* <EPTF_Var_DirectContent> *pl_dataValue* - this is the value of the data to be set
//       after call, it will return the changed value that might be different after the function call
//    *in charstring pl_source* - the name of the dataSource 'feature'
//    *in charstring pl_ptcName* - the name of the PTC
//         (dataSource+ptcName should be a unigue id of the data). Default: "" (i.e. PTC name is ignored)
//    *in charstring pl_element* - the type of data
//    *in* <EPTF_DataSource_Params> *pl_params* - additional parameters (default: {})
//       The parameters are sorted lexicographically according to the paramNames
//    *in* <EPTF_CharstringList> *pl_indexList* - in case of list-type values the elements of this parameter
//      are the indexes in the list-type data for which the values should be set
//      For elementary type values this argument is not used
//    *in <EPTF_DataSource_CT> pl_sourceCompRef* - the DataSource_CT componentRef to set the value on.
//       If not specified the data is requested from the only one
//       DataSource component which is connected (= for which the <f_EPTF_DataSourceClient_connectToServer> was called)
//
//  Return Value:
//    integer - 0 if OK, nonzero in case of failure to show that changing of the value was unsuccessful
//
//  Detailed Comments:
//    This function will make a request for the given data source and return the new value of the data.
//
//    How it works:
//    The request is forwarded to the appropriate DataSourceClient which registered
//    the source and ptc name. On the client the handler function registered by
//    <f_EPTF_DataSourceClient_registerSetDataValue> for the given pl_source and pl_ptcName is called.
//    The pl_params are passed to it as additional arguments.
//    The handler function returns a value which is set in the pl_dataValue
//    argument and returns an error code to show if the change was successful or not.
//    This function will return these values in its pl_dataValue argument and the return value.
///////////////////////////////////////////////////////////
public function f_EPTF_DataSourceClient_setDataValue(
  inout EPTF_Var_DirectContent pl_dataValue,
  in charstring pl_source,
  in charstring pl_ptcName := "",
  in charstring pl_element,
  in EPTF_DataSource_Params pl_params := {},
  in EPTF_IntegerList pl_indexList := {},
  in EPTF_DataSource_CT pl_sourceCompRef := null
) runs on EPTF_DataSourceClient_CT return integer {

  var integer vl_errorCode;

  if(not v_EPTF_DataSourceClient_connected) {
    vl_errorCode := -99;
    var charstring vl_errorMsg := log2str(%definitionId&": Cannot set data value to ",pl_dataValue,
        " for pl_source: ",pl_source," pl_ptcName: ",pl_ptcName, " pl_element: ",pl_element," pl_params: ",pl_params, " from pl_sourceCompRef: ",pl_sourceCompRef,": Not connected to DataSource");
    f_EPTF_DataSourceClient_warning(vl_errorMsg);
    pl_dataValue := {charstringVal :=  vl_errorMsg};
    return vl_errorCode;
  }
  
  f_EPTF_DataSource_sortParams(pl_params);

  var integer vl_transactionId := f_EPTF_Semaphore_new();

  f_EPTF_DataSourceClient_sendMsg(EPTF_DataSource_Msg:{setDataValue:={
    transactionId := vl_transactionId,
    dataSource := pl_source,
    ptcName := pl_ptcName,
    dataElement := pl_element,
    params := pl_params,
    dataValue := pl_dataValue,
    indexList := pl_indexList
  }}, pl_sourceCompRef);

  //wait for the result:
  if (f_EPTF_Semaphore_waitForUnlock(vl_transactionId,tsp_EPTF_DataSourceClient_maxWaitTime)) {
    // max wait time expired before response received:
    f_EPTF_DataSourceClient_warning(log2str(%definitionId&": Communication error: No response received for setDataValue message: ",vl_transactionId));
    pl_dataValue := {charstringVal :=  log2str(%definitionId&": Communication error: No response received for setDataValue message: ",vl_transactionId)};
    return -1;
  }

  // copy the values from the message database because it might be possible that they will be overwritten because
  // the semaphore is released and there is a blocking statement before they are used:
  //vl_ownerCompRef := v_EPTF_DataSourceClient_Msg_List[vl_transactionId].dataValue.ownerCompRef;
  pl_dataValue := v_EPTF_DataSourceClient_Msg_List[vl_transactionId].dataValueResponse.dataValue;
  vl_errorCode := v_EPTF_DataSourceClient_Msg_List[vl_transactionId].dataValueResponse.errorCode;  
  return vl_errorCode;
}

///////////////////////////////////////////////////////////
//  Function: f_EPTF_DataSourceClient_setDataValue_nonBlocking
// 
//  Purpose:
//    To set the value of a given data in non-blocking way.
//    The specified handler is called when the response arrives.
//
//  Parameters:
//    *in* <EPTF_Var_DirectContent> *pl_dataValue* - this is the value of the data requested
//       after call, it will return the changed value that might be different
For faster browsing, not all history is shown. View entire blame