summaryrefslogtreecommitdiff
path: root/README.md
blob: b1f4bfb2c7218f99c6f1dca67abdceb704c498b4 (plain)
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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
<a name="welcome-to-tidl"></a>
# Welcome to TIDL!
TIDL  is programming language to define interfaces for communicating among apps in Tizen. It provides methods to make a RPC(Remote Procedure Call) or RMI (Remote Method Invocation)  in Tizen.

<a name="contents"></a>
## Contents
- [Welcome to TIDL!](#welcome-to-tidl)
  - [Contents](#contents)
  - [TIDLC](#tidlc)
    - [Usage](#usage)
  - [TIDL Syntax](#tidl-syntax)
    - ['interface'](#interface)
    - [Attributes](#attributes)
    - ['async'](#async)
    - ['delegate'](#delegate)
    - ['struct'](#struct)
  - [TIDL Type System](#tidl-type-system)
  - [TIDL Generated Code](#tidl-generated-code)
    - [Struct](#struct-1)
    - [Proxy Interface](#proxy-interface)
    - [Stub Interface](#stub-interface)
  - [Protocol Version 2](#protocol-version-2)
    - [Enum Type](#enum-type)
    - [Import Another TIDL File](#import-another-tidl-file)
    - [Method Privilege](#method-privilege)
    - [Map and Set Container Type](#map-and-set-container-type)
    - [Marshalling Type Info](#marshalling-type-info)
    - [Struct Inheritance](#struct-inheritance)
    - [Remote Exception](#remote-exception)
    - [Local Execution Mode](#local-execution-mode)
    - [Private Sharing](#private-sharing)
    - [TIDL Generated Code for Protocol Version 2](#tidl-generated-code-for-protocol-version-2)
      - [Proxy Interface](#proxy-interface-1)
      - [Stub Interface](#stub-interface-1)

<a name="tidlc"></a>
## TIDLC
**TIDLC** is a compiler for making stub or proxy code block from **TIDL** file.

<a name="usage"></a>
### Usage
```
Usage:
  tidlc [OPTION...]

Help Options:
  -h, --help                  Show help options
  --help-all                  Show all help options
  --help-option               Additional options

Additional Options:
  -l, --language=LANGUAGE     Select generating language (C, C++, C#, Dart).
  -i, --input=INPUT           A tidl interface file.
  -o, --output=OUTPUT         The generated interface file.
  -n, --namespace             Add the prefix in the funtion name as output file name (C language only).
  -r, --rpclib                Generate C# library for rpc-port (C# language only).
  -b, --beta                  Use beta version (Support private file sharing).
  -t, --thread                Generate thread code (Stub only).

Application Options:
  -p, --proxy                 Generate proxy code
  -s, --stub                  Generate stub code
  -v, --version               Show version information

```
<a name="tidlc-syntax"></a>
## TIDL Syntax

<a name="interface"></a>
### 'interface'
It makes an interface to communicate between proxy and stub.

**Syntax**
```csharp
[<attributes>]
interface <interface_id> {
<return_type> <method_name>(
[<empty> | ‘in’ | ‘out’ | ‘ref’]
<type> <parameter_id>, …) [<empty> | ‘async’ | ‘delegate’\];
…
}
```
**Example**
```csharp
[privilege=“http://tizen.org/privilege/appmanager.launch”]
interface ITest {
	// by default, ‘in’ is used as direction keyword
	int SetVal(in  int val1, char val2);
	char GetVal(out  int val1, out  char val2);
}
```

<a name="attributes"></a>
### Attributes
It indicates required privileges and trusted signature.
By default, ‘trusted” is ‘false’.

**Syntax**
```
[ <key> = <value>, …]
interface <interface_id> { … }
<key> :=  privilege | trusted
<value> := <string> | “true” | “false”
```

**Example**
```csharp
// Requere launch privilege
[privilege=“http://tizen.org/privilege/appmanager.launch”]
interface ITest {}

// Requere privilege A , privilege B AND trusted signature
[privilege=“http://samsung.com/appdefined/A”,
 privilege=“http://samsung.com/appdefined/B” , trusted  = “true”]
interface ITest2 {}
```

<a name="async"></a>
### 'async'
It denotes one-way-call.

>**Note**
Returned type should be ‘void’
Keyword ‘out’ is not allowed

**Example**
```csharp
interface ITest {
	void  SetValAsync(int val1, char val2) async;
}
```

### 'delegate'
It denotes one-way-call from service.

>**Note**
Returned type should be ‘void’
Keyword ‘out’ is not allowed
Regarded as a type in methods (Can’t be used in ‘struct’ type)

**Example**
```csharp
interface ITest {
	void OnReceivedEvent(string msg, bundle b) delegate;
	void RegisterEvent(OnReceivedEvent cb);
	void UnregisterEvent(OnReceivedEvent cb);
}
```

<a name="struct"></a>
### 'struct'
It allows developers to define user-defined types.
It is also possible to be used in other user-defined types or method syntax.

**Syntax**
```csharp
struct <struct_id> {
    <type> <id>;
    …
}
```

**Example**
```csharp
struct Student  {
    string name;
    int num;
    bundle data;
}
```

<a name="tidl-type-system"></a>
## TIDL Type System
 - Built-in type (‘in’ direction case)

	| TIDL type | Size     | C# type | C++ type    | C type       | Dart Type     |
	|-----------|----------|---------|-------------|--------------|---------------|
	| void      | 0        | void    | void        | void         | void          |
	| char      | 1        | byte    | char        | char         | int           |
	| short     | 2        | short   | short int   | short int    | int           |
	| int       | 4        | int     | int         | int          | int           |
	| long      | 8        | long    | long long   | long long    | int           |
	| float     | 4        | float   | float       | float        | Not supported |
	| double    | 8        | double  | double      | double       | double        |
	| bundle    | variable | Bundle  | Bundle      | bundle *     | Bundle        |
	| string    | variable | string  | std::string | const char * | String        |
	| bool      | 1        | bool    | bool        | bool         | bool          |

 - Container type
	 - **list< [type] >**  Or  **array<[type]>**
		- Used when sending list/ array of some types
		- Similar to c++ std::list / std::vector
		- Can be nested

	| TIDL type  | C# type      | C++ type      | C type           | Dart type |
	|------------|--------------|---------------|------------------|-----------|
	| list<>     | LinkedList<> | std::list<>   | Handle (pointer) | List<>    |
	| array<>    | List<>       | std::vector<> | Handle (pointer) | List<>    |

  - User-defined type
	- Name defined by ‘struct’ syntax

<a name="tidl-generated-code"></a>
## TIDL Generated Code

<a name="struct-1"></a>
### Struct
**TIDL**
```csharp
struct Foo {
  int Age;
  string Name;
}
```

**C++**
```cpp
class Foo final { // Copyable and movable class
  Foo(); // Constructor
  Foo(int age, std::string name); // Constructor
  int GetAge() const; // Getter for property ‘Age’
  void SetAge(int age); // Setter for property ‘Age’
  const std::string& GetName() const; // Getter for property ‘Name’
  void SetName(std::string name); // Setter for property ‘Name’
};
```

**C#**
```csharp
public selaed class Foo  { // Class for Foo
	public  int Age { get; set; }  // Property for ‘Age’
	public  string Name { get; set; } // Property for ‘Name’
};
```

**C**
```c
typedef struct Foo_s *rpc_port_Foo_h; // Handle for Foo
int rpc_port_create_Foo(rpc_port_Foo_h* h); // Constructor for Foo
int rpc_port_destroy_Foo(rpc_port_Foo_h h); // Destructor for Foo
int rpc_port_clone_Foo(rpc_port_Foo_h h, rpc_port_Foo_h* clone); // Copy constructor for Foo
int rpc_port_set_Foo_Age(rpc_port_Foo_h h, int Age); // Setter for property ‘Age’
int rpc_port_set_Foo_Name(rpc_port_Foo_h h, const char* Name); // Setter for property ‘Name’
int rpc_port_get_Foo_Age(rpc_port_Foo_h h, int* Age); // Getter for property ‘Age’
int rpc_port_get_Foo_Name(rpc_port_Foo_h h, char** Name); // Getter for property ‘Name’

// Proxy (Since TIDLC version 1.5.0)
typedef struct rpc_port_proxy_Foo_s *rpc_port_proxy_Foo_h; // Handle for Foo
int rpc_port_proxy_create_Foo(rpc_port_proxy_Foo_h* h); // Constructor for Foo
int rpc_port_proxy_destroy_Foo(rpc_port_proxy_Foo_h h); // Destructor for Foo
int rpc_port_proxy_clone_Foo(rpc_port_proxy_Foo_h h, rpc_port_proxy_Foo_h* clone); // Copy constructor for Foo
int rpc_port_proxy_set_Foo_Age(rpc_port_proxy_Foo_h h, int Age); // Setter for property ‘Age’
int rpc_port_proxy_set_Foo_Name(rpc_port_proxy_Foo_h h, const char* Name); // Setter for property ‘Name’
int rpc_port_proxy_get_Foo_Age(rpc_port_proxy_Foo_h h, int* Age); // Getter for property ‘Age’
int rpc_port_proxy_get_Foo_Name(rpc_port_proxy_Foo_h h, char** Name); // Getter for property ‘Name’

// Stub (Since TIDLC version 1.5.0)
typedef struct rpc_port_stub_Foo_s *rpc_port_stub_Foo_h; // Handle for Foo
int rpc_port_stub_create_Foo(rpc_port_stub_Foo_h* h); // Constructor for Foo
int rpc_port_stub_destroy_Foo(rpc_port_stub_Foo_h h); // Destructor for Foo
int rpc_port_stub_clone_Foo(rpc_port_stub_Foo_h h, rpc_port_stub_Foo_h* clone); // Copy constructor for Foo
int rpc_port_stub_set_Foo_Age(rpc_port_stub_Foo_h h, int Age); // Setter for property ‘Age’
int rpc_port_stub_set_Foo_Name(rpc_port_stub_Foo_h h, const char* Name); // Setter for property ‘Name’
int rpc_port_stub_get_Foo_Age(rpc_port_stub_Foo_h h, int* Age); // Getter for property ‘Age’
int rpc_port_stub_get_Foo_Name(rpc_port_stub_Foo_h h, char** Name); // Getter for property ‘Name’
```

**Dart**
```dart
class Foo {
  Foo(this.age, this.name);

  int age;
  String name;
}
```

<a name="proxy-interface"></a>
### Proxy Interface

**TIDL**
```csharp
interface Runnable {
	int Run(Foo foo);
}
```

**C++**
```cpp
class Runnable  {
	class IEventListener { // Events about connection
		virtual  void OnConnected() = 0;
		virtual  void OnDisconnected() = 0;
		virtual  void OnRejected() = 0;
	};

	Runnable(IEventListener* listener, const std::string& target_appid); // Constructor
	virtual ~Runnable(); // Destructor
	int Connect(); // Method for connecting to the stub
	int Run(Foo foo); //Method  from TIDL
	void Disconnect(); // Method for disconnecting from the stub (Since TIDLC version 1.6.1)
};
```

**C#**
```csharp
public class Runnable : IDisposable  {
	public event EventHandler Connected; // Event handler
	public event EventHandler Disconnected; // Event handler
	public event EventHandler Rejected; // Event handler
	public Runnable(string appId); // Constructor
	public void Connect(); // Method for connecting to the stub
	public int Run(Foo foo); //Method  from TIDL
	public void Disconnect(); // Method for disconnecting from the stub (Since TIDLC version 1.6.1)
	…
};
```

**C**
```c
// Previous version
typedef struct Runnable_s* rpc_port_proxy_Runnable_h; // Handle for ‘Runnable’

typedef struct {
  void (*connected)(rpc_port_proxy_Runnable_h h, void* user_data); // Connected event callback
  void (*disconnected)(rpc_port_proxy_Runnable_h h, void* user_data); // Disconnected event callback
  void (*rejected)(rpc_port_proxy_Runnable_h h, void* user_data); // Rejected event callback
} rpc_port_proxy_Runnable_callback_s;

//  Function for creating Runnable proxy handle
int rpc_port_proxy_Runnable_create(const char* stub_appid,rpc_port_proxy_Runnable_callback_s* callback, void* user_data, rpc_port_proxy_Runnable_h* h);

//  Function for connecting to service app
int rpc_port_proxy_Runnable_connect(rpc_port_proxy_Runnable_h h);

//  Function for destroying Runnable proxy handle
int rpc_port_proxy_Runnable_destroy(rpc_port_proxy_Runnable_h h);

// Function from TIDL
int rpc_port_proxy_Runnable_invoke_Run(rpc_port_proxy_Runnable_h h, rpc_port_Foo_h foo);
```

```c
// Since TIDLC version 1.5.0
typedef struct rpc_port_proxy_Runnable_s* rpc_port_proxy_Runnable_h; // Handle for ‘Runnable’

// Called when the port is connected
typedef void (*rpc_port_proxy_Runnable_connected_cb)(rpc_port_proxy_Runnable_h h, void *user_data);

// Called when the port is disconnected
typedef void (*rpc_port_proxy_Runnable_disconnected_cb)(rpc_port_proxy_Runnable_h h, void *user_data);

// Called when the connection request is rejected
typedef void (*rpc_port_proxy_Runnable_rejected_cb)(rpc_port_proxy_Runnable_h h, void *user_data);

// The structure type containing the set of callback functions for handling proxy events
typedef struct {
  rpc_port_proxy_Runnable_connected_cb connected;
  rpc_port_proxy_Runnable_disconnected_cb disconnected;
  rpc_port_proxy_Runnable_rejected_cb rejected;
} rpc_port_proxy_Runnable_callback_s;

//  Function for creating Runnable proxy handle
int rpc_port_proxy_Runnable_create(const char* stub_appid, rpc_port_proxy_Runnable_callback_s* callback, void* user_data, rpc_port_proxy_Runnable_h* h);

//  Function for connecting to the stub
int rpc_port_proxy_Runnable_connect(rpc_port_proxy_Runnable_h h);

//  Function for destroying Runnable proxy handle
int rpc_port_proxy_Runnable_destroy(rpc_port_proxy_Runnable_h h);

// Function from TIDL
int rpc_port_proxy_Runnable_invoke_Run(rpc_port_proxy_Runnable_h h, rpc_port_Foo_h foo);

// Function for disconnection from the stub (Since TIDLC version 1.6.1)
int rpc_port_proxy_Runnable_disconnect(rpc_port_proxy_Runnable_h h);
```

**Dart**
```dart
class Runnable extends ProxyBase {
  Runnable(String appid) : super(appid, 'Runnable');

  Future<int> Run(Foo foo);

  /// Connects with the stub.
  ///
  /// The following privileges are required to use this API.
  /// - `http://tizen.org/privilege/appmanager.launch`
  /// - `http://tizen.org/privilege/datasharing`
  Future<void> connect({OnDisconnected? onDisconnected});

  /// Disconnects with the stub.
  Future<void> disconnect();

  // Disposes of registered delegate interface.
  void disposeCallback(Function callback);
}
```

<a name="stub-interface"></a>
### Stub Interface

**TIDL**
```csharp
interface Runnable {
	int Run(Foo foo);
}
```

**C++**
```cpp
class Runnable  {
	class ServiceBase { // Abstract class for RPC service
		class Factory { // Factory class to make real service object
		    virtual std::unique_ptr<ServiceBase> CreateService(std::string sender) = 0;
		};

		virtual void OnCreate() = 0; // Called when service object is created
		virtual void OnTerminate() = 0; // Called when service object is terminated
		virtual int Run(Foo foo) = 0; // Method to implement

        ...
		void Disconnect(); // Method for disconnecting from the RPC service (Since TIDLC version 1.6.1)
	};

	Runnable(); // Constructor
	~Runnable(); // Destructor
	void Listen(std::shared\_ptr<ServiceBase::Factory> service_factory); // Method for listening
};
```

**C#**
```csharp
public sealed class Runnable : IDisposable {
	public abstract class ServiceBase { // Abstract class for RPC service
		public abstract void OnCreate(); // Called when service object is created
		public abstract void OnTerminate(); // Called when service object is terminated
		public abstract int Run(Foo foo); // Method to implement
        …
		public void Disconnect(); // Method for disconnecting from the RPC service (Since TIDLC version 1.6.1)
	};
	public Runnable(); // Constructor
	public void Listen(Type serviceType); // Method for listening
    …
};
```

**C**
```c
// Previous version
// Handle for ‘Runnable’
typedef struct Runnable_context_s* rpc_port_stub_Runnable_context_h;

// Set extra data into the context
int rpc_port_stub_Runnable_context_set_tag(rpc_port_stub_Runnable_context_h ctx, void* tag);

// Get extra data from the context
int rpc_port_stub_Runnable_context_get_tag(rpc_port_stub_Runnable_context_h ctx, void** tag);

typedef struct {
	// Called when service object is created
	void (*create)(rpc_port_stub_Runnable_context_h context, void* user_data);

	// Called when service object is terminated
	void (*terminate)(rpc_port_stub_Runnable_context_h context, void* user_data);

	// Called when proxy app send the request for ‘Run’
	int (*Run)(rpc_port_stub_Runnable_context_h context, rpc_port_Foo_h foo, void *user_data);
} rpc_port_stub_Runnable_callback_s;

// Initialize interface ‘Runnable’
int rpc_port_stub_Runnable_register(rpc_port_stub_Runnable_callback_s* callback, void* user_data);

// Deinitialize interface ‘Runnable’
int rpc_port_stub_Runnable_unregister(void);
```

```c
// Since TIDLC version 1.5.0
// Handle for ‘Runnable’
typedef struct rpc_port_stub_Runnable_context_s* rpc_port_stub_Runnable_context_h;

// Set extra data into the context
int rpc_port_stub_Runnable_context_set_tag(rpc_port_stub_Runnable_context_h context, void* tag);

// Get extra data from the context
int rpc_port_stub_Runnable_context_get_tag(rpc_port_stub_Runnable_context_h context, void** tag);

// Disconnect from the proxy
int rpc_port_stub_Runnable_context_disconnect(rpc_port_stub_Runnable_context_h context);

// Called when the service object is created
typedef void (*rpc_port_stub_Runnable_create_cb)(rpc_port_stub_Runnable_context_h context, void *user_data);

// Called when the service object is terminated
typedef void (*rpc_port_stub_Runnable_terminate_cb)(rpc_port_stub_Runnable_context_h context, void *user_data);

// Called when the proxy sends the request for 'Run'
typedef void (*rpc_port_stub_Runnable_Run_cb)(rpc-port_stub_Runnable_context_h context, rpc_port_stub_Foo_h foo, void *user_data);

// The structure type containing the set of callback functions for handling stub events
typedef struct {
  rpc_port_stub_Runnable_create_cb create;
  rpc_port_stub_Runnable_terminate_cb terminate;
  rpc_port_stub_Runnable_Run_cb Run;
} rpc_port_stub_Runnable_callback_s;

// Initialize interface ‘Runnable’
int rpc_port_stub_Runnable_register(rpc_port_stub_Runnable_callback_s* callback, void* user_data);

// Deinitialize interface ‘Runnable’
int rpc_port_stub_Runnable_unregister(void);

// Gets the number of connected clients
int rpc_port_stub_Runnable_get_client_number(unsigned int *client_number);
```

**Dart**
```dart
abstract class ServiceBase {
  ServiceBase(this.sender, this.instance);

  final String sender;
  final String instance;
  Port? _port;

  void disconnect() {
    _port?.disconnect();
    _port = null;
  }

  Future<void> onCreate();
  Future<void> onTerminate();
  Future<int> onRun(Foo foo);
}

typedef ServiceBuilder = ServiceBase Function(String sender, String instance);

class Runnable extends StubBase {
  Runnable({required ServiceBuilder serviceBuilder})
      : _serviceBuilder = serviceBuilder,
      super('Runnable');

  final List<ServiceBase> services = <ServiceBase>[];
  final Map<int, dynamic> _methodHandlers = <int, dynamic>{};
  final ServiceBuilder _serviceBuilder;
}
```

<a name="protocol-version-2"></a>
## Protocol Version 2
**TIDLC** supports 'protocol version 2' since Tizen 8.0.
To use 'protocol version 2', you must fill **'protocol 2'** in the .tidl file.
'protocol version 2' of **TIDL** supports the following features:

<a name="enum-type"></a>
### Enum Type
 - **'enum'** type is added.
 - You can declare an **enum** type inside a 'struct' or 'interface' and use it as a member variable or parameter.
   ```tidl
    struct Message {
      enum Type {
        T1 = 0,
        T2,
        T3
      }

      Type t;
      int id;
      string str;
    }

    interface Hello {
      enum Version {
        V1,
        V2,
        V3
      }

      string SayHello(Version ver, string str, Message.Type msg);
    }
  ```
- When using a struct's enum type as a method parameter, it must be specified as **"<struct_name>.<enum_type>"**.

<a name="import-another-tidl-file"></a>
### Import Another TIDL File
- **'import'** keyword is added.
- You can add and use other TIDL files in the same directory as the current TIDL file using the **'import'** keyword.
- During the compilation process, the contents of other TIDL files are integrated and generated as one code.
- The following example shows how to use the **'import'** keyword:
  ```tidl
    import <another.tidl>

    interface Message {
      int Send(string name, string msg);
    }
  ```

<a name="method-privilege"></a>
### Method Privilege
- The protocol version 2 of TIDL supports the method privilege feature.
- You can set privileges for each method of an interface by writing them as below:
  ```tidl
    interface PackageManager {
      [privilege = "http://tizen.org/privilege/packagemanager.info"]
      int GetPackages(out list<string> packages);

      [privilege = "http://tizen.org/privilege/packagemanager.admin"]
      int Install(file path);

      [privilege = "http://tizen.org/privilege/packagemanager.admin"]
      int Uninstall(string package);
    }
  ```
- To use the GetPackages method in the example, the client application needs to have the privilege that is "http://tizen.org/privilege/packagemanager.info".

<a name="map-and-set-container-type"></a>
### Map and Set Container Type
- You can use map and set container types in TIDL.
- The map type is **'map\<K, V\>'**. The set type is **'set\<K\>'**.
  ```tidl
    struct Message {
      string name;
      map<string, string> envelope;
      set<string> keys;
    }
  ```
  > **Note**
  >
  > The key type of map and set container must be TIDL's builtin types.

<a name="marshalling-type-info"></a>
### Marshalling Type Info
- From protocol version 2, the type information and variable names of method parameters are also transmitted.
- Even if variable names are changed, added, or deleted due to interface modifications, it does not affect communication.
- If there are no variables to be passed, they are passed as initial values.
  - Example 1. Original tidl code

    ```tidl
      interface Hello {
        int GetPackages(out list<string> packages);
      }
    ```
  - Example 2. Revised tidl code
    ```tidl
      interface Hello {
        int GetPackages(out list<string> packages, out int size);
      }
    ``````
- In the example, the GetPackages() method has an added size parameter.
- Even if the stub only returns the existing packages parameter, there is no problem with communication.

<a name="struct-inheritance"></a>
### Struct Inheritance
- **'struct'** inheritance is supported.
- Here is an example that supports **'struct'** inheritance:
  ```tidl
    struct MessageBase {
      int id;
      string name;
    }

    struct MessageDerived : MessageBase {
      string msg;
    }
  ```
- In this example, **MessageDerived** inherits **MessageBase**.
  > **Note**
  >
  > The inherited struct MUST not have elements of the base struct."

- If the method of the interface is a base struct, communication can be performed using the derived struct that is inherited. (Polymophism)
  ```tidl
    struct MessageBase {
      int id;
      string name;
    }

    struct MessageDerived : MessageBase {
      string msg;
    }

    struct Envelope : MessageBase {
      string address;
      string msg;
    }

    interface Message {
      int SendMessage(MessageBase msg);
    }
  ```
- When using the **Message** interface, you can use **Envelope** or **MessageDerived** to call the **SendMessage()** method.

<a name="remote-exception"></a>
### Remote Exception
- The stub can use **RemoteException** to throw an exception to the proxy.
- This feature is available when the method operates synchronously.
- When the proxy sends a request and waits for a result, if the stub throws an exception, it is passed to the proxy.

<a name="local-execution-mode"></a>
### Local Execution Mode
- If the stub that the proxy sends a request to is in the same application, a function call occurs instead of RPC.

<a name="private-sharing"></a>
### Private Sharing
- Since protocol version 2, the file keyword can be used without the '-b' option.
- The proxy or the stub can use this to share a specific file in the data directory with the intended recipient for communication.
- The recipient who receives the shared file can access it with read-only permission.

<a name="tidl-generated-code-for-protocol-version-2"></a>
### TIDL Generated Code for Protocol Version 2

**TIDL**
```tidl
protocol 2

struct MessageBase {
  int id;
  string name;
  string msg;
}

struct MessageDerived : MessageBase {
  string address;
}

interface Message {
  void OnReceived(string sender, MessageBase message) delegate;

  int Register(string sender, OnReceived callback);
  void Unregister() async;
  int Send(MessageBase message);
}
```
- In the example, the MessageDerived structure inherits from MessageBase.
- When calling the Send method of the Message interface, you can use a MessageDerived instance.

<a name="proxy-interface-1"></a>
#### Proxy Interface

**C**
```c
// Handle for 'MessageBase' structure.
typedef void *rpc_port_proxy_MessageBase_h;

// Handle for 'MessageDerived' structure.
typedef void *rpc_port_proxy_MessageDerived_h;

// Handle for Remote Exception.
typedef struct rpc_port_proxy_remote_exception_s *rpc_port_proxy_remote_exception_h;

// Handle for 'Message' interface.
typedef struct rpc_port_proxy_Message_s *rpc_port_proxy_Message_h;

// Handle for 'OnReceived' delegate of 'Message' interface.
typedef struct rpc_port_proxy_Message_OnReceived_s *rpc_port_proxy_Message_OnReceived_h;

// Function for creating MessageBase handle.
int rpc_port_proxy_MessageBase_create(rpc_port_proxy_MessageBase_h *h);

// Function for destroying MessageBase handle.
int rpc_port_proxy_MessageBase_destroy(rpc_port_proxy_MessageBase_h h);

// Function for cloning MessageBase handle.
int rpc_port_proxy_MessageBase_clone(rpc_port_proxy_MessageBase_h h, rpc_port_proxy_MessageBase_h *clone);

// Function for setting id to MessageBase handle.
int rpc_port_proxy_MessageBase_set_id(rpc_port_proxy_MessageBase_h h, int value);

// Function for getting id from MessageBase handle.
int rpc_port_proxy_MessageBase_get_id(rpc_port_proxy_MessageBase_h h, int *value);

// Function for setting name to MessageBase handle.
int rpc_port_proxy_MessageBase_set_name(rpc_port_proxy_MessageBase_h h, const char *value);

// Function for getting name from MessageBase handle.
int rpc_port_proxy_MessageBase_get_name(rpc_port_proxy_MessageBase_h h, char **value);

// Function for setting msg to MessageBase handle.
int rpc_port_proxy_MessageBase_set_msg(rpc_port_proxy_MessageBase_h h, const char *value);

// Function for getting msg from MessageBase handle.
int rpc_port_proxy_MessageBase_get_msg(rpc_port_proxy_MessageBase_h h, char **value);

// Function for creating MessageDerived handle.
int rpc_port_proxy_MessageDerived_create(rpc_port_proxy_MessageDerived_h *h);

// Function for destroying MessageDerived handle.
int rpc_port_proxy_MessageDerived_destroy(rpc_port_proxy_MessageDerived_h h);

// Function for cloning MessageDerived handle.
int rpc_port_proxy_MessageDerived_clone(rpc_port_proxy_MessageDerived_h h, rpc_port_proxy_MessageDerived_h *clone);

// Function for setting id to MessageDerived handle.
int rpc_port_proxy_MessageDerived_set_id(rpc_port_proxy_MessageDerived_h h, int value);

// Function for getting id from MessageDerived handle.
int rpc_port_proxy_MessageDerived_get_id(rpc_port_proxy_MessageDerived_h h, int *value);

// Function for setting id to MessageDerived handle.
int rpc_port_proxy_MessageDerived_set_name(rpc_port_proxy_MessageDerived_h h, const char *value);

// Function for getting name from MessageDerived handle.
int rpc_port_proxy_MessageDerived_get_name(rpc_port_proxy_MessageDerived_h h, char **value);

// Function for setting msg to MessageDerived handle.
int rpc_port_proxy_MessageDerived_set_msg(rpc_port_proxy_MessageDerived_h h, const char *value);

// Function for getting msg from MessageDerived handle.
int rpc_port_proxy_MessageDerived_get_msg(rpc_port_proxy_MessageDerived_h h, char **value);

// Function for setting address to MessageDerived handle.
int rpc_port_proxy_MessageDerived_set_address(rpc_port_proxy_MessageDerived_h h, const char *value);

// Function for getting address from MessageDerived handle.
int rpc_port_proxy_MessageDerived_get_address(rpc_port_proxy_MessageDerived_h h, char **value);

// Function for creating Remote Exception handle.
int rpc_port_proxy_remote_exception_create(rpc_port_proxy_remote_exception_h *h);

// Function for setting cause to Remote Exception handle.
int rpc_port_proxy_remote_exception_set_cause(rpc_port_proxy_remote_exception_h h, int cause);

// Function for setting msessage to Remote Exception handle.
int rpc_port_proxy_remote_exception_set_message(rpc_port_proxy_remote_exception_h h, const char *message);

// Function for getting cause from Remote Exception handle.
int rpc_port_proxy_remote_exception_get_cause(rpc_port_proxy_remote_exception_h h, int *cause);

// Function for getting message from Remote Exception handle.
int rpc_port_proxy_remote_exception_get_message(rpc_port_proxy_remote_exception_h, char **message);

// Function for destroying Remote Exception handle.
int rpc_port_proxy_remote_exception_destroy(rpc_port_proxy_remote_exception_h h);

// Function for getting Remote Exception handle.
int rpc_port_proxy_get_remote_exception(rpc_port_proxy_remote_exception_h *h);

// Callback function for OnReceived of Message interface.
typedef void (*rpc_port_proxy_Message_OnReceived_cb)(void *user_data, const char *sender, rpc_port_proxy_MessageBase_h message);

// Function for creating OnReceived handle.
int rpc_port_proxy_Message_OnReceived_create(rpc_port_proxy_Message_OnReceived_h *h);

// Function for destroying OnReceived handle.
int rpc_port_proxy_Message_OnReceived_destroy(rpc_port_proxy_Message_OnReceived_h h);

// Function for cloning OnReceived handle.
int rpc_port_proxy_Message_OnReceived_clone(rpc_port_proxy_Message_OnReceived_h h, rpc_port_proxy_Message_OnReceived_h *clone);

// Function for setting callback to OnReceived handle.
int rpc_port_proxy_Message_OnReceived_set_callback(rpc_port_proxy_Message_OnReceived_h h, rpc_port_proxy_Message_OnReceived_cb callback, void *user_data);

// Function for setting once flag to OnReceived handle.
int rpc_port_proxy_Message_OnReceived_set_once(rpc_port_proxy_Message_OnReceived_h h, bool once);

// Function for getting id from OnReceived handle.
int rpc_port_proxy_Message_OnReceived_get_id(rpc_port_proxy_Message_OnReceived_h h, int *id);

// Function for getting seq_id from OnReceived handle.
int rpc_port_proxy_Message_OnReceived_get_seq_id(rpc_port_proxy_Message_OnReceived_h h, int *seq_id);

// Function for checking once flag from OnReceived handle.
int rpc_port_proxy_Message_OnReceived_is_once(rpc_port_proxy_Message_OnReceived_h h, bool *once);

// Function for getting tag from OnReceived handle.
int rpc_port_proxy_Message_OnReceived_get_tag(rpc_port_proxy_Message_OnReceived_h h, char **tag);

// Function for dispoing OnReceived handle.
int rpc_port_proxy_Message_OnReceived_dispose(rpc_port_proxy_Message_h proxy, rpc_port_proxy_Message_OnReceived_h h);

// Called when receiving connected event.
typedef void (*rpc_port_proxy_Message_connected_cb)(rpc_port_proxy_Message_h h, void *user_data);

// Called when receiving disconnected event.
typedef void (*rpc_port_proxy_Message_disconnected_cb)(rpc_port_proxy_Message_h h, void *user_data);

// Called when receiving rejected event.
typedef void (*rpc_port_proxy_Message_rejected_cb)(rpc_port_proxy_Message_h h, void *user_data);

// Structure for receiving events of Message interface.
typedef struct {
        rpc_port_proxy_Message_connected_cb connected;
        rpc_port_proxy_Message_disconnected_cb disconnected;
        rpc_port_proxy_Message_rejected_cb rejected;
} rpc_port_proxy_Message_callback_s;

// Function for creating Message handle.
int rpc_port_proxy_Message_create(const char *stub_appid, rpc_port_proxy_Message_callback_s *callback, void *user_data, rpc_port_proxy_Message_h *h);

// Function for destroying Message handle.
int rpc_port_proxy_Message_destroy(rpc_port_proxy_Message_h h);

// Function for connecting to Message server.
int rpc_port_proxy_Message_connect(rpc_port_proxy_Message_h h);

// Function for connecting to Message server synchronously.
int rpc_port_proxy_Message_connect_sync(rpc_port_proxy_Message_h h);

// Function for disconnecting from Message server.
int rpc_port_proxy_Message_disconnect(rpc_port_proxy_Message_h h);

// Function for Register method of Message interface.
int rpc_port_proxy_Message_invoke_Register(rpc_port_proxy_Message_h h, const char *sender, rpc_port_proxy_Message_OnReceived_h callback);

// Function for Unregister method of Message interface.
void rpc_port_proxy_Message_invoke_Unregister(rpc_port_proxy_Message_h h);

// Function for Send method of Message interface.
int rpc_port_proxy_Message_invoke_Send(rpc_port_proxy_Message_h h, rpc_port_proxy_MessageBase_h message);
```

**C++**
```cpp
// Class for Bundle.
class Bundle final {
 public:
  Bundle();
  explicit Bundle(bundle* handle, bool copy = true, bool own = true);
  Bundle(std::string raw);
  ~Bundle();

  Bundle(const Bundle& b);
  Bundle& operator = (const Bundle& b);
  Bundle(Bundle&& b) noexcept;
  Bundle& operator = (Bundle&&) noexcept;

  bundle* GetHandle() const;
  bundle* Detach();
};

// class for File.
class File final {
 public:
  File(std::string filename = "");

  const std::string& GetFileName() const;
  int Share(rpc_port_h port);
};

// class for 'MessageBase' structure.
class MessageBase {
 public:
  MessageBase();
  MessageBase(int id, std::string name, std::string msg);

  int Getid() const;
  void Setid(int id);

  const std::string& Getname() const;
  void Setname(std::string name);

  const std::string& Getmsg() const;
  void Setmsg(std::string msg);
};

// class for 'MessageDerived' structure.
class MessageDerived : public MessageBase {
 public:
  MessageDerived();
  MessageDerived(int id, std::string name, std::string msg, std::string address);

  const std::string& Getaddress() const;
  void Setaddress(std::string address);
};

namespace proxy {
class Exception {};
class NotConnectedSocketException : public Exception {};
class InvalidProtocolException : public Exception {};
class InvalidIOException : public Exception {};
class PermissionDeniedException : public Exception {};
class InvalidIDException : public Exception {};
class InvalidArgumentException : public Exception {};
class OutOfMemoryException : public Exception {};

// class for RemoteException.
class RemoteException : public Exception {
 public:
  RemoteException();
  RemoteException(std::string message);
  RemoteException(int cause, std::string message);

  int GetCause() const;
  const std::string& GetMessage() const;
};

// class for 'Message' interface.
class Message : public LocalExecution::IEvent {
 public:

  class CallbackBase {
   public:
    CallbackBase() = default;
    CallbackBase(int delegate_id, bool once);
    virtual ~CallbackBase() = default;

    virtual void OnReceivedEvent(const UnitMap& unit_map);
    int GetId() const;
    void SetId(int id);
    int GetSeqId() const;
    void SetSeqId(int seq_id);
    bool IsOnce() const;
    void SetOnce(bool once);
    std::string GetTag() const;
  };

  class OnReceived : public CallbackBase {
   public:
    OnReceived(bool once = false);
    virtual void OnReceived(std::string sender, MessageBase message);
  };

  class IEventListener {
   public:
    virtual ~IEventListener() = 0;
    // Called when connected event is delivered.
    virtual void OnConnected() = 0;

    // Called when disconnected event is delivered.
    virtual void OnDisconnected() = 0;

    // Called when rejected event is delivered.
    virtual void OnRejected() = 0;
  };

  // Constructor.
  Message(IEventListener* listener, std::string target_appid);

  // Desctructor.
  virtual ~Message();

  // Method for connecting to 'Message' server.
  void Connect(bool sync = false);

  // Method for disconnecting from 'Message' server.
  void Disconnect();

  // Method for disposing delegate from Message intstance.
  void DisposeCallback(const std::string& tag);

  // Method for 'Register' method of 'Message' interface.
  int Register(std::string sender, std::unique_ptr<OnReceived> callback);

  // Method for 'Unregister' method of 'Message' interface.
  void Unregister();

  // Method for 'Send' method of 'Message' interface.
  int Send(MessageBase message);
};
}  // namespace proxy
```

**C#**
```csharp
// class for 'MessageBase' structure.
public class MessageBase
{
  public int id;
  public string name;
  public string msg;

  public MessageBase();
}

// class for 'MessageDerived' structure.
public class MessageDerived : MessageBase
{
  public string address;

  public MessageDerived();
}

// class for RemoteException.
public class RemoteException : Exception
{
  public RemoteException();
  public RemoteException(string message);
  public RemoteException(string message, int cause);
  public new string Message;
  public int Cause;
}

namespace Proxy
{
  // class for 'Message' interface.
  public class Message : ProxyBase
  {
    public event EventHandler Connected;
    public event EventHandler Disconnected;
    public event EventHandler Rejected;

    public class CallbackBase
    {
      public string Tag;
      public CallbackBase(int delegateId, bool once)
    }

    public sealed class OnReceived : CallbackBase
    {
      public OnReceived(bool once = false) : base((int)DelegateId.OnReceived, once);
      public delegate void Callback(string sender, MessageBase message);
      public event Callback Received;
    }

  // Called when connected event is delivered.
  protected override void OnConnectedEvent(string endPoint, string portName, Port port);

  // Called when disconnected event is delivered.
  protected override void OnDisconnectedEvent(string endPoint, string portName);

  // Called when rejected event is delivered.
  protected override void OnRejectedEvent(string endPoint, string portName);

  // Called when received event is delivered.
  protected override void OnReceivedEvent(string endPoint, string portName);

  // Constructor.
  public Message(string appId);

  // Method for connecting to 'Message' server.
  public void Connect();

  // Method for disconnecting from 'Message' server.
  public void Disconnect();

  // Method for connecting to 'Message' server sychronously.
  public void ConnectSync();

  // Method for disposing delegate from Message instance.
  void DisposeCallback(string tag);

  // Method for 'Register' method of 'Message' interface.
  public int Register(string sender, OnReceived callback);

  // Method for 'Unregister' method of 'Message' interface.
  public void Unregister();

  // Method for 'Send' method of 'Message' interface.
  public int Send(MessageBase message);
  }
}
```


<a name="stub-interface-1"></a>
#### Stub Interface

**C**
```c
// Handle for 'MessageBase' structure.
typedef void *rpc_port_stub_MessageBase_h;

// Handle for 'MessageDerived' structure.
typedef void *rpc_port_stub_MessageDerived_h;

// Handle for Remote Exception.
typedef struct rpc_port_stub_remote_exception_s *rpc_port_stub_remote_exception_h;

// Handle for context of 'Message' interface.
typedef struct rpc_port_stub_Message_context_s *rpc_port_stub_Message_context_h;

// Handle for 'OnReceived' delegate of 'Message' interface.
typedef struct rpc_port_stub_Message_OnReceived_s *rpc_port_stub_Message_OnReceived_h;

// Function for creating MessageBase handle.
int rpc_port_stub_MessageBase_create(rpc_port_stub_MessageBase_h *h);

// Function for destroying MessageBase handle.
int rpc_port_stub_MessageBase_destroy(rpc_port_stub_MessageBase_h h);

// Function for cloning MessageBase handle.
int rpc_port_stub_MessageBase_clone(rpc_port_stub_MessageBase_h h, rpc_port_stub_MessageBase_h *clone);

// Function for setting id to MessageBase handle.
int rpc_port_stub_MessageBase_set_id(rpc_port_stub_MessageBase_h h, int value);

// Function for getting id from MessageBase handle.
int rpc_port_stub_MessageBase_get_id(rpc_port_stub_MessageBase_h h, int *value);

// Function for setting name to MessageBase handle.
int rpc_port_stub_MessageBase_set_name(rpc_port_stub_MessageBase_h h, const char *value);

// Function for getting name from MessageBase handle.
int rpc_port_stub_MessageBase_get_name(rpc_port_stub_MessageBase_h h, char **value);

// Function for setting msg to MessageBase handle.
int rpc_port_stub_MessageBase_set_msg(rpc_port_stub_MessageBase_h h, const char *value);

// Function for getting msg to MessageBase handle.
int rpc_port_stub_MessageBase_get_msg(rpc_port_stub_MessageBase_h h, char **value);

// Function for creating MessageDerived handle.
int rpc_port_stub_MessageDerived_create(rpc_port_stub_MessageDerived_h *h);

// Function for destroying MessageDerived handle.
int rpc_port_stub_MessageDerived_destroy(rpc_port_stub_MessageDerived_h h);

// Function for cloning MessageDerived handle.
int rpc_port_stub_MessageDerived_clone(rpc_port_stub_MessageDerived_h h, rpc_port_stub_MessageDerived_h *clone);

// Function for setting id to MessageDerived handle.
int rpc_port_stub_MessageDerived_set_id(rpc_port_stub_MessageDerived_h h, int value);

// Function for getting id from MessageDerived handle.
int rpc_port_stub_MessageDerived_get_id(rpc_port_stub_MessageDerived_h h, int *value);

// Function for setting name to MessageDerived handle.
int rpc_port_stub_MessageDerived_set_name(rpc_port_stub_MessageDerived_h h, const char *value);

// Function for getting name from MessageDerived handle.
int rpc_port_stub_MessageDerived_get_name(rpc_port_stub_MessageDerived_h h, char **value);

// Function for setting msg to MessageDerived handle.
int rpc_port_stub_MessageDerived_set_msg(rpc_port_stub_MessageDerived_h h, const char *value);

// Function for getting msg to MessageDerived handle.
int rpc_port_stub_MessageDerived_get_msg(rpc_port_stub_MessageDerived_h h, char **value);

// Function for setting address to MessageDerived handle.
int rpc_port_stub_MessageDerived_set_address(rpc_port_stub_MessageDerived_h h, const char *value);

// Function for getting address from MessageDerived handle.
int rpc_port_stub_MessageDerived_get_address(rpc_port_stub_MessageDerived_h h, char **value);

// Function for creating Remote Exception handle.
int rpc_port_stub_remote_exception_create(rpc_port_stub_remote_exception_h *h);

// Function for setting cause to Remote Exception handle.
int rpc_port_stub_remote_exception_set_cause(rpc_port_stub_remote_exception_h h, int cause);

// Function for setting message to Remote Exception handle.
int rpc_port_stub_remote_exception_set_message(rpc_port_stub_remote_exception_h h, const char *message);

// Function for getting cause from Remote Exception handle.
int rpc_port_stub_remote_exception_get_cause(rpc_port_stub_remote_exception_h h, int *cause);

// Function for getting message from Remote Exception handle.
int rpc_port_stub_remote_exception_get_message(rpc_port_stub_remote_exception_h, char **message);

// Function for destroying Remote Exception handle.
int rpc_port_stub_remote_exception_destroy(rpc_port_stub_remote_exception_h h);

// Function for throwing Remote Exception handle.
int rpc_port_stub_remote_exception_throw(rpc_port_stub_remote_exception_h h);

// Called when client is connected.
typedef void (*rpc_port_stub_Message_create_cb)(rpc_port_stub_Message_context_h context, void *user_data);

// Called when client is disconnected.
typedef void (*rpc_port_stub_Message_terminate_cb)(rpc_port_stub_Message_context_h context, void *user_data);

// Called when retreiving contexts of Message handle.
typedef bool (*rpc_port_stub_Message_context_cb)(rpc_port_stub_Message_context_h context, void *user_data);

// Called when receiving 'Register' event from client.
typedef int  (*rpc_port_stub_Message_Register_cb)(rpc_port_stub_Message_context_h context, const char *sender, rpc_port_stub_Message_OnReceived_h callback, void *user_data);

// Called when receiving 'Unregister' event from client.
typedef void  (*rpc_port_stub_Message_Unregister_cb)(rpc_port_stub_Message_context_h context, void *user_data);

// Called when receiving 'Send' event from client.
typedef int  (*rpc_port_stub_Message_Send_cb)(rpc_port_stub_Message_context_h context, rpc_port_stub_MessageBase_h message, void *user_data);

// Function for setting tag to Message context handle.
int rpc_port_stub_Message_context_set_tag(rpc_port_stub_Message_context_h context, void *tag);

// Function for getting tag from Message context handle.
int rpc_port_stub_Message_context_get_tag(rpc_port_stub_Message_context_h context, void **tag);

// Function for getting sender from Message context handle.
int rpc_port_stub_Message_context_get_sender(rpc_port_stub_Message_context_h context, char **sender);

// Function for getting instance from Message context handle.
int rpc_port_stub_Message_context_get_instance(rpc_port_stub_Message_context_h context, char **instance);

// Function for disconnecting from client.
int rpc_port_stub_Message_context_disconnect(rpc_port_stub_Message_context_h context);

// Function for creating OnReceived handle.
int rpc_port_stub_Message_OnReceived_create(rpc_port_stub_Message_OnReceived_h *h);

// Function for destroying OnReceived handle.
int rpc_port_stub_Message_OnReceived_destroy(rpc_port_stub_Message_OnReceived_h h);

// Function for cloning OnReceived handle.
int rpc_port_stub_Message_OnReceived_clone(rpc_port_stub_Message_OnReceived_h h, rpc_port_stub_Message_OnReceived_h *clone);

// Function for getting id from OnReceived handle.
int rpc_port_stub_Message_OnReceived_get_id(rpc_port_stub_Message_OnReceived_h h, int *id);

// Function for getting seq_id from OnReceived handle.
int rpc_port_stub_Message_OnReceived_get_seq_id(rpc_port_stub_Message_OnReceived_h h, int *seq_id);

// Function for checking once flag from OnReceived handle.
int rpc_port_stub_Message_OnReceived_is_once(rpc_port_stub_Message_OnReceived_h h, bool *once);

// Function for getting tag from OnReceived handle.
int rpc_port_stub_Message_OnReceived_get_tag(rpc_port_stub_Message_OnReceived_h h, char **tag);

// Function for invoking OnReceived callback function of 'Message' client.
int rpc_port_stub_Message_OnReceived_invoke(rpc_port_stub_Message_OnReceived_h h, const char *sender, rpc_port_stub_MessageBase_h message);

// Structure for receiving events of Message interface.
typedef struct {
        rpc_port_stub_Message_create_cb create;
        rpc_port_stub_Message_terminate_cb terminate;
        rpc_port_stub_Message_Register_cb Register;
        rpc_port_stub_Message_Unregister_cb Unregister;
        rpc_port_stub_Message_Send_cb Send;
} rpc_port_stub_Message_callback_s;

// Function for registering callback functions of Message interface to be invoked when events are received.
int rpc_port_stub_Message_register(rpc_port_stub_Message_callback_s *callback, void *user_data);

// Function for unregistering callback functions of Message interface.
int rpc_port_stub_Message_unregister(void);

// Function for retreving connected context of clients of Message interface.
int rpc_port_stub_Message_foreach_context(rpc_port_stub_Message_context_cb callback, void *user_data);

// Function for getting client number from Message interface.
int rpc_port_stub_Message_get_client_number(unsigned int *client_number);
```

**C++**
```cpp
// class for Bundle.
class Bundle final {
 public:
  Bundle();
  explicit Bundle(bundle* handle, bool copy = true, bool own = true);
  Bundle(std::string raw);
  ~Bundle();

  Bundle(const Bundle& b);
  Bundle& operator = (const Bundle& b);
  Bundle(Bundle&& b) noexcept;
  Bundle& operator = (Bundle&&) noexcept;

  bundle* GetHandle() const;
  bundle* Detach();
};


// class for File.
class File final {
 public:
  File(std::string filename = "");

  const std::string& GetFileName() const;
  int Share(rpc_port_h port);
};

// class for 'MessageBase' structure.
class MessageBase {
 public:
  MessageBase();
  MessageBase(int id, std::string name, std::string msg);

  int Getid() const;
  void Setid(int id);
  const std::string& Getname() const;
  void Setname(std::string name);
  const std::string& Getmsg() const;
  void Setmsg(std::string msg);
};

// class for 'MessageDerived' structure.
class MessageDerived : public MessageBase {
 public:
  MessageDerived();
  MessageDerived(int id, std::string name, std::string msg, std::string address);

  const std::string& Getaddress() const;
  void Setaddress(std::string address);
};

namespace stub {

class Exception {};
class NotConnectedSocketException : public Exception {};
class InvalidProtocolException : public Exception {};
class InvalidIOException : public Exception {};
class PermissionDeniedException : public Exception {};
class InvalidIDException : public Exception {};
class InvalidArgumentException : public Exception {};
class OutOfMemoryException : public Exception {};

// class for Remote Exception.
class RemoteException : public Exception {
 public:
  RemoteException();
  RemoteException(std::string message);
  RemoteException(int cause, std::string message);

  int GetCause() const;
  const std::string& GetMessage() const;
};

// class for 'Message' interface.
class Message : public LocalExecution::IEvent {
 public:
  class ServiceBase;
  class CallbackBase {
   public:
    CallbackBase(int delegate_id, bool once);
    CallbackBase() = default;
    virtual ~CallbackBase() = default;

    int GetId() const;
    void SetId(int id);
    int GetSeqId() const;
    void SetSeqId(int seq_id);
    bool IsOnce() const;
    void SetOnce(bool once);

    std::string GetTag() const;

    void SetContext(void* context);
    void* GetContext() const;
  };

  class OnReceived : public CallbackBase {
   public:
    OnReceived(rpc_port_h callback_port, std::weak_ptr<ServiceBase> service) : CallbackBase(static_cast<int>(DelegateId::OnReceived), false), callback_port_(callback_port), service_(std::move(service)) {}

    void Invoke(std::string sender, MessageBase message);
  };

  class ServiceBase : public std::enable_shared_from_this<ServiceBase> {
   public:
    class Factory {
     public:
      virtual ~Factory() = default;
      virtual std::unique_ptr<ServiceBase> CreateService(std::string sender, std::string instance) = 0;
    };

    virtual ~ServiceBase() = default;
    const std::string& GetSender() const {
      return sender_;
    }
    const std::string& GetInstance() const {
      return instance_;
    }

    void SetPort(rpc_port_h port);
    void Disconnect();
    virtual void OnCreate() = 0;
    virtual void OnTerminate() = 0;
    void SetContext(void* context);
    void* GetContext() const;
    void Dispatch(rpc_port_h port, rpc_port_h callback_port, rpc_port_parcel_h parcel, std::shared_ptr<ServiceBase> service);
    void Dispatch(rpc_port_h port, rpc_port_h callback_port, rpc_port_parcel_h parcel);

    virtual int Register(std::string sender, std::unique_ptr<OnReceived> callback) = 0;
    virtual void Unregister() = 0;
    virtual int Send(MessageBase message) = 0;

   protected:
    ServiceBase(std::string sender, std::string instance);
  };

  // Constructor.
  Message();

  // Destructor.
  ~Message();

  // Method for listening Message events.
  void Listen(std::shared_ptr<ServiceBase::Factory> service_factory);

  // Method for getting instance of ServiceBase of clients.
  const std::list<std::shared_ptr<ServiceBase>>& GetServices() const {
    return services_;
  }
};

}  // namespace stub
```

**C#**
```csharp
// class for 'MessageBase' structure.
public class MessageBase
{
  public int id;
  public string name;
  public string msg;

  public MessageBase();
}

// class for 'MessageDerived' structure.
public class MessageDerived : MessageBase
{
  public string address;

  public MessageDerived();
}

// class for Remote Exception.
public class RemoteException : Exception
{
  public RemoteException();
  public RemoteException(string message);
  public RemoteException(string message, int cause);
  public new string Message;
  public int Cause;
}

namespace Stub
{
  public sealed class Message : StubBase
  {
    public abstract class ServiceBase
    {
      public string Sender;
      public string Instance;
      public Port Port;
      protected ServiceBase();
      public void Disconnect();
      public abstract void OnCreate();
      public abstract void OnTerminate();
      public abstract int Register(string sender, OnReceived callback);
      public abstract void Unregister();
      public abstract int Send(MessageBase message);
    }

    public class CallbackBase
    {
      public string Tag;
      public CallbackBase(int delegateId, bool once);
    }

    public sealed class OnReceived : CallbackBase
    {
      public void Invoke(string sender, MessageBase message);
    }

    // Called when client sends a request.
    protected override bool OnReceivedEvent(string sender, string instance, Port port);

    // Called when client is connected.
    protected override void OnConnectedEvent(string sender, string instance);

    // Called when client is disconnected.
    protected override void OnDisconnectedEvent(string sender, string instance);

    // Constructor.
    public Message();

    // Method for listening events of Message interface.
    public void Listen(Type serviceType);

    // Method for getting instance of connected clients.
    public IEnumerable<ServiceBase> GetServices();

    ...
  }
}
```