[Appfw] Add APIs for RPC (#330)
authorpjh9216 <jh9216.park@samsung.com>
Tue, 17 Jul 2018 07:56:28 +0000 (16:56 +0900)
committerGitHub <noreply@github.com>
Tue, 17 Jul 2018 07:56:28 +0000 (16:56 +0900)
* [AppFw] Add classes for RPC port

Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
* [AppFw] Add additional APIs for RPC port

Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
* [AppFw] Add event handlers

Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
* [AppFw][RpcPort] Modify description for privileges

Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
* [AppFw][RpcPort] Add description for return value

Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
src/Tizen.Applications.Common/Interop/Interop.Libraries.cs [changed mode: 0644->0755]
src/Tizen.Applications.Common/Interop/Interop.RPCPort.cs [new file with mode: 0755]
src/Tizen.Applications.Common/Tizen.Applications.RPCPort/Exceptions.cs [new file with mode: 0755]
src/Tizen.Applications.Common/Tizen.Applications.RPCPort/Parcel.cs [new file with mode: 0755]
src/Tizen.Applications.Common/Tizen.Applications.RPCPort/Port.cs [new file with mode: 0755]
src/Tizen.Applications.Common/Tizen.Applications.RPCPort/ProxyBase.cs [new file with mode: 0755]
src/Tizen.Applications.Common/Tizen.Applications.RPCPort/StubBase.cs [new file with mode: 0755]

old mode 100644 (file)
new mode 100755 (executable)
index 227d014..b1a7e53
@@ -28,5 +28,6 @@ internal static partial class Interop
         public const string Libc = "libc.so.6";
         public const string Application = "libcapi-appfw-application.so.0";
         public const string Icuuc = "libicuuc.so";
+        public const string RpcPort = "librpc-port.so.1";
     }
 }
diff --git a/src/Tizen.Applications.Common/Interop/Interop.RPCPort.cs b/src/Tizen.Applications.Common/Interop/Interop.RPCPort.cs
new file mode 100755 (executable)
index 0000000..bef6586
--- /dev/null
@@ -0,0 +1,251 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+using Tizen.Internals.Errors;
+using Tizen.Applications;
+
+internal static partial class Interop
+{
+    internal static partial class LibRPCPort
+    {
+        internal enum ErrorCode
+        {
+            None = Tizen.Internals.Errors.ErrorCode.None,
+            InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
+            OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
+            PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
+            IoError = Tizen.Internals.Errors.ErrorCode.IoError,
+        }
+
+        internal enum PortType
+        {
+            Main,
+            Callback
+        }
+
+        internal static partial class Parcel
+        {
+            //int rpc_port_parcel_create(rpc_port_parcel_h *h);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_create")]
+            internal static extern ErrorCode Create(out IntPtr handle);
+
+            //int rpc_port_parcel_create_from_port(rpc_port_parcel_h *h, rpc_port_h port);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_create_from_port")]
+            internal static extern ErrorCode CreateFromPort(out IntPtr parcelHandle, IntPtr portHandle);
+
+            //int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_send")]
+            internal static extern ErrorCode Send(IntPtr parcelHandle, IntPtr portHandle);
+
+            //int rpc_port_parcel_destroy(rpc_port_parcel_h h);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_destroy")]
+            internal static extern ErrorCode Destroy(IntPtr handle);
+
+            //int rpc_port_parcel_write_byte(rpc_port_parcel_h h, char b);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_byte")]
+            internal static extern ErrorCode WriteByte(IntPtr parcelHandle, byte b);
+
+            //int rpc_port_parcel_write_int16(rpc_port_parcel_h h, short i);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_int16")]
+            internal static extern ErrorCode WriteInt16(IntPtr parcelHandle, short i);
+
+            //int rpc_port_parcel_write_int32(rpc_port_parcel_h h, int i);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_int32")]
+            internal static extern ErrorCode WriteInt32(IntPtr parcelHandle, int i);
+
+            //int rpc_port_parcel_write_int64(rpc_port_parcel_h h, int i);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_int64")]
+            internal static extern ErrorCode WriteInt64(IntPtr parcelHandle, long i);
+
+            //int rpc_port_parcel_write_float(rpc_port_parcel_h h, float f);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_float")]
+            internal static extern ErrorCode WriteFloat(IntPtr parcelHandle, float f);
+
+            //int rpc_port_parcel_write_double(rpc_port_parcel_h h, double d);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_double")]
+            internal static extern ErrorCode WriteDouble(IntPtr parcelHandle, double d);
+
+            //int rpc_port_parcel_write_string(rpc_port_parcel_h h, const char* str);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_string")]
+            internal static extern ErrorCode WriteString(IntPtr parcelHandle, string str);
+
+            //int rpc_port_parcel_write_bool(rpc_port_parcel_h h, bool b);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_bool")]
+            internal static extern ErrorCode WriteBool(IntPtr parcelHandle, bool b);
+
+            //int rpc_port_parcel_write_bundle(rpc_port_parcel_h h, bundle* b);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_bundle")]
+            internal static extern ErrorCode WriteBundle(IntPtr parcelHandle, IntPtr b);
+
+            //int rpc_port_parcel_write_array_count(rpc_port_parcel_h h, int count);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_write_array_count")]
+            internal static extern ErrorCode WriteArrayCount(IntPtr parcelHandle, int count);
+
+            //int rpc_port_parcel_read_byte(rpc_port_parcel_h h, char* b);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_byte")]
+            internal static extern ErrorCode ReadByte(IntPtr parcelHandle, out byte b);
+
+            //int rpc_port_parcel_read_int16(rpc_port_parcel_h h, short *i);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_int16")]
+            internal static extern ErrorCode ReadInt16(IntPtr parcelHandle, out short i);
+
+            //int rpc_port_parcel_read_int32(rpc_port_parcel_h h, int* i);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_int32")]
+            internal static extern ErrorCode ReadInt32(IntPtr parcelHandle, out int i);
+
+            //int rpc_port_parcel_read_int64(rpc_port_parcel_h h, long long* i);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_int64")]
+            internal static extern ErrorCode ReadInt64(IntPtr parcelHandle, out long i);
+
+            //int rpc_port_parcel_read_float(rpc_port_parcel_h h, float *f);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_float")]
+            internal static extern ErrorCode ReadFloat(IntPtr parcelHandle, out float f);
+
+            //int rpc_port_parcel_read_double(rpc_port_parcel_h h, double *d);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_double")]
+            internal static extern ErrorCode ReadDouble(IntPtr parcelHandle, out double f);
+
+            //int rpc_port_parcel_read_string(rpc_port_parcel_h h, char** str);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_string")]
+            internal static extern ErrorCode ReadString(IntPtr parcelHandle, out string str);
+
+            //int rpc_port_parcel_read_bool(rpc_port_parcel_h h, bool *b);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_bool")]
+            internal static extern ErrorCode ReadBool(IntPtr parcelHandle, out bool b);
+
+            //int rpc_port_parcel_read_bundle(rpc_port_parcel_h h, bundle** b);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_bundle")]
+            internal static extern ErrorCode ReadBundle(IntPtr parcelHandle, out IntPtr b);
+
+            //int rpc_port_parcel_read_array_count(rpc_port_parcel_h h, int *count);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_read_array_count")]
+            internal static extern ErrorCode ReadArrayCount(IntPtr parcelHandle, out int count);
+
+            //int rpc_port_parcel_burst_read(rpc_port_parcel_h h, unsigned char *buf, unsigned int size);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_burst_read")]
+            internal static extern ErrorCode Read(IntPtr parcelHandle, [In, Out] byte[] buf, int size);
+
+            //int rpc_port_parcel_burst_write(rpc_port_parcel_h h, const unsigned char *buf, unsigned int size);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_burst_write")]
+            internal static extern ErrorCode Write(IntPtr parcelHandle, byte[] buf, int size);
+        }
+
+        internal static partial class Proxy
+        {
+            //typedef void (*rpc_port_proxy_connected_event_cb)(const char *ep, const char* port_name, rpc_port_h port, void* data);
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+            internal delegate void ConnectedEventCallback(string endPoint, string port_name, IntPtr port, IntPtr data);
+
+            //typedef void (*rpc_port_proxy_disconnected_event_cb)(const char *ep, const char* port_name, void* data);
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+            internal delegate void DisconnectedEventCallback(string endPoint, string port_name, IntPtr data);
+
+            //typedef void (*rpc_port_proxy_rejected_event_cb) (const char* ep, const char* port_name, void* data);
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+            internal delegate void RejectedEventCallback(string endPoint, string port_name, IntPtr data);
+
+            //typedef void (*rpc_port_proxy_received_event_cb) (const char* ep, const char* port_name, void* data);
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+            internal delegate void ReceivedEventCallback(string endPoint, string port_name, IntPtr data);
+
+            //int rpc_port_proxy_create(rpc_port_proxy_h *h);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_create")]
+            internal static extern ErrorCode Create(out IntPtr handle);
+
+            //int rpc_port_proxy_destroy(rpc_port_proxy_h h);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_destroy")]
+            internal static extern ErrorCode Destroy(IntPtr handle);
+
+            //int rpc_port_proxy_connect(rpc_port_proxy_h h, const char *appid, const char* port);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_connect")]
+            internal static extern ErrorCode Connect(IntPtr handle, string appId, string port);
+
+            //int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h, rpc_port_proxy_connected_event_cb cb, void* data);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_add_connected_event_cb")]
+            internal static extern ErrorCode AddConnectedEventCb(IntPtr handle, ConnectedEventCallback cb, IntPtr data);
+
+            //int rpc_port_proxy_add_disconnected_event_cb(rpc_port_proxy_h h, rpc_port_proxy_disconnected_event_cb cb, void* data);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_add_disconnected_event_cb")]
+            internal static extern ErrorCode AddDisconnectedEventCb(IntPtr handle, DisconnectedEventCallback cb, IntPtr data);
+
+            //int rpc_port_proxy_add_rejected_event_cb(rpc_port_proxy_h h, rpc_port_proxy_rejected_event_cb cb, void* data);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_add_rejected_event_cb")]
+            internal static extern ErrorCode AddRejectedEventCb(IntPtr handle, RejectedEventCallback cb, IntPtr data);
+
+            //int rpc_port_proxy_add_received_event_cb(rpc_port_proxy_h h, rpc_port_proxy_received_event_cb cb, void* data);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_add_received_event_cb")]
+            internal static extern ErrorCode AddReceivedEventCb(IntPtr handle, ReceivedEventCallback cb, IntPtr data);
+
+            //int rpc_port_proxy_get_port(rpc_port_proxy_h h, rpc_port_port_type_e type, rpc_port_h* port);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_get_port")]
+            internal static extern ErrorCode GetPort(IntPtr handle, PortType t, out IntPtr port);
+        }
+
+        internal static partial class Stub
+        {
+            //typedef void (*rpc_port_stub_connected_event_cb)(const char *sender, const char *instance, void* data);
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+            internal delegate void ConnectedEventCallback(string sender, string instance, IntPtr data);
+
+            //typedef void (* rpc_port_stub_disconnected_event_cb) (const char* sender, const char *instance, void* data);
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+            internal delegate void DisconnectedEventCallback(string sender, string instance, IntPtr data);
+
+            //typedef void (* rpc_port_stub_received_event_cb) (const char* sender, const char *instance, rpc_port_h port, void* data);
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+            internal delegate int ReceivedEventCallback(string sender, string instance, IntPtr port, IntPtr data);
+
+            //int rpc_port_stub_create(rpc_port_stub_h* h, const char* port_name);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_create")]
+            internal static extern ErrorCode Create(out IntPtr handle, string portName);
+
+            //int rpc_port_stub_destroy(rpc_port_stub_h h);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_destroy")]
+            internal static extern ErrorCode Destroy(IntPtr handle);
+
+            //int rpc_port_stub_listen(rpc_port_stub_h h);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_listen")]
+            internal static extern ErrorCode Listen(IntPtr handle);
+
+            //int rpc_port_stub_add_connected_event_cb(rpc_port_stub_h h, rpc_port_stub_connected_event_cb cb, void* data);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_add_connected_event_cb")]
+            internal static extern ErrorCode AddConnectedEventCb(IntPtr handle, ConnectedEventCallback cb, IntPtr data);
+
+            //int rpc_port_stub_add_disconnected_event_cb(rpc_port_stub_h h, rpc_port_stub_disconnected_event_cb cb, void* data);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_add_disconnected_event_cb")]
+            internal static extern ErrorCode AddDisconnectedEventCb(IntPtr handle, DisconnectedEventCallback cb, IntPtr data);
+
+            //int rpc_port_stub_add_received_event_cb(rpc_port_stub_h h, rpc_port_stub_received_event_cb cb, void* data);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_add_received_event_cb")]
+            internal static extern ErrorCode AddReceivedEventCb(IntPtr handle, ReceivedEventCallback cb, IntPtr data);
+
+            //int rpc_port_stub_add_privilege(rpc_port_stub_h h, const char *privilege);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_add_privilege")]
+            internal static extern ErrorCode AddPrivilege(IntPtr handle, string privilege);
+
+            //int rpc_port_stub_set_trusted(rpc_port_stub_h h, const bool trusted);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_set_trusted")]
+            internal static extern ErrorCode SetTrusted(IntPtr handle, bool trusted);
+
+            //int rpc_port_stub_get_port(rpc_port_stub_h h, rpc_port_port_type_e type, const char* instance, rpc_port_h *port);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_get_port")]
+            internal static extern ErrorCode GetPort(IntPtr handle, PortType t, string instance, out IntPtr port);
+        }
+    }
+}
diff --git a/src/Tizen.Applications.Common/Tizen.Applications.RPCPort/Exceptions.cs b/src/Tizen.Applications.Common/Tizen.Applications.RPCPort/Exceptions.cs
new file mode 100755 (executable)
index 0000000..4ff403b
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Tizen.Applications.RPCPort
+{
+    /// <summary>
+    /// Exception class for invalid IO
+    /// </summary>
+    /// <since_tizen> 5 </since_tizen>
+    public class InvalidIOException : InvalidOperationException { }
+
+    /// <summary>
+    /// Exception class for invalid ID
+    /// </summary>
+    /// <since_tizen> 5 </since_tizen>
+    public class InvalidIDException : InvalidOperationException { }
+
+    /// <summary>
+    /// Exception class for permission denied
+    /// </summary>
+    /// <since_tizen> 5 </since_tizen>
+    public class PermissionDeniedException : InvalidOperationException { }
+
+    /// <summary>
+    /// Exception class for invalid protocol
+    /// </summary>
+    /// <since_tizen> 5 </since_tizen>
+    public class InvalidProtocolException : InvalidOperationException { }
+
+    /// <summary>
+    /// Exception class which will be thrown when not connected socket is used
+    /// </summary>
+    /// <since_tizen> 5 </since_tizen>
+    public class NotConnectedSocketException : InvalidOperationException { }
+
+    /// <summary>
+    /// Exception class which will be thrown when invalid callback object is used
+    /// </summary>
+    /// <since_tizen> 5 </since_tizen>
+    public class InvalidCallbackException : InvalidOperationException { }
+}
diff --git a/src/Tizen.Applications.Common/Tizen.Applications.RPCPort/Parcel.cs b/src/Tizen.Applications.Common/Tizen.Applications.RPCPort/Parcel.cs
new file mode 100755 (executable)
index 0000000..de8bc1c
--- /dev/null
@@ -0,0 +1,341 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Tizen.Applications.RPCPort
+{
+    /// <summary>
+    /// The class for helping marshalling and unmarshalling for RPC
+    /// </summary>
+    /// <since_tizen> 5 </since_tizen>
+    public class Parcel : IDisposable
+    {
+        private IntPtr _handle;
+
+        /// <summary>
+        /// Constructor for this class
+        /// </summary>
+        /// <exception cref="InvalidIOException">Thrown when internal IO error happens</exception>
+        /// <since_tizen> 5 </since_tizen>
+        public Parcel()
+        {
+            var r = Interop.LibRPCPort.Parcel.Create(out _handle);
+            if (r != Interop.LibRPCPort.ErrorCode.None)
+                throw new InvalidIOException();
+        }
+
+        /// <summary>
+        /// Constructor with Port object
+        /// </summary>
+        /// <param name="port">Port object</param>
+        /// <exception cref="InvalidIOException">Thrown when internal IO error happens</exception>
+        /// <since_tizen> 5 </since_tizen>
+        public Parcel(Port port)
+        {
+            var r = Interop.LibRPCPort.Parcel.CreateFromPort(out _handle, port.Handle);
+            if (r != Interop.LibRPCPort.ErrorCode.None)
+                throw new InvalidIOException();
+        }
+
+        /// <summary>
+        /// Sends parcel data through the port
+        /// </summary>
+        /// <param name="p">The RPC port object for writing data</param>
+        /// <exception cref="InvalidIOException">Thrown when internal IO error happens</exception>
+        /// <since_tizen> 5 </since_tizen>
+        public void Send(Port p)
+        {
+            var r = Interop.LibRPCPort.Parcel.Send(_handle, p.Handle);
+            if (r != Interop.LibRPCPort.ErrorCode.None)
+                throw new InvalidIOException();
+        }
+
+        /// <summary>
+        /// Writes 'byte' type value into Parcel object
+        /// </summary>
+        /// <param name="b">'byte' type data</param>
+        /// <since_tizen> 5 </since_tizen>
+        public void WriteByte(byte b)
+        {
+            Interop.LibRPCPort.Parcel.WriteByte(_handle, b);
+        }
+
+        /// <summary>
+        /// Writes 'short' type value into Parcel object
+        /// </summary>
+        /// <param name="b">'short' type data</param>
+        /// <since_tizen> 5 </since_tizen>
+        public void WriteShort(short b)
+        {
+            Interop.LibRPCPort.Parcel.WriteInt16(_handle, b);
+        }
+
+        /// <summary>
+        /// Writes 'int' type value into Parcel object
+        /// </summary>
+        /// <param name="b">'int' type data</param>
+        /// <since_tizen> 5 </since_tizen>
+        public void WriteInt(int b)
+        {
+            Interop.LibRPCPort.Parcel.WriteInt32(_handle, b);
+        }
+
+        /// <summary>
+        /// Writes a Long type value into Parcel handle
+        /// </summary>
+        /// <param name="b">'long' type data</param>
+        /// <since_tizen> 5 </since_tizen>
+        public void WriteLong(long b)
+        {
+            Interop.LibRPCPort.Parcel.WriteInt64(_handle, b);
+        }
+
+        /// <summary>
+        /// Writes a 'float' type value into Parcel handle
+        /// </summary>
+        /// <param name="b">'float' type data</param>
+        /// <since_tizen> 5 </since_tizen>
+        public void WriteFloat(float b)
+        {
+            Interop.LibRPCPort.Parcel.WriteFloat(_handle, b);
+        }
+
+        /// <summary>
+        /// Writes a 'double' type value into Parcel handle
+        /// </summary>
+        /// <param name="b">'double' type data</param>
+        /// <since_tizen> 5 </since_tizen>
+        public void WriteDouble(double b)
+        {
+            Interop.LibRPCPort.Parcel.WriteDouble(_handle, b);
+        }
+
+        /// <summary>
+        /// Writes a 'string' type value into Parcel handle
+        /// </summary>
+        /// <param name="b">'string' type data</param>
+        /// <since_tizen> 5 </since_tizen>
+        public void WriteString(string b)
+        {
+            Interop.LibRPCPort.Parcel.WriteString(_handle, b);
+        }
+
+        /// <summary>
+        /// Writes a 'bool' type value into Parcel handle
+        /// </summary>
+        /// <param name="b">'bool' type data</param>
+        /// <since_tizen> 5 </since_tizen>
+        public void WriteBool(bool b)
+        {
+            Interop.LibRPCPort.Parcel.WriteBool(_handle, b);
+        }
+
+        /// <summary>
+        /// Writes a 'Bundle' type value into Parcel handle
+        /// </summary>
+        /// <param name="b">'Bundle' type data</param>
+        /// <since_tizen> 5 </since_tizen>
+        public void WriteBundle(Bundle b)
+        {
+            Interop.LibRPCPort.Parcel.WriteBundle(_handle, b.SafeBundleHandle.DangerousGetHandle());
+        }
+
+        /// <summary>
+        /// Writes a count for array into Parcel object
+        /// </summary>
+        /// <param name="cnt">Array count</param>
+        /// <since_tizen> 5 </since_tizen>
+        public void WriteArrayCount(int cnt)
+        {
+            Interop.LibRPCPort.Parcel.WriteArrayCount(_handle, cnt);
+        }
+
+        /// <summary>
+        /// Reads 'byte' type value from Parcel object
+        /// </summary>
+        /// <returns>'byte' type data</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public byte ReadByte()
+        {
+            Interop.LibRPCPort.Parcel.ReadByte(_handle, out byte b);
+            return b;
+        }
+
+        /// <summary>
+        /// Reads 'short' type value from Parcel object
+        /// </summary>
+        /// <returns>'short' type data</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public short ReadShort()
+        {
+            Interop.LibRPCPort.Parcel.ReadInt16(_handle, out short b);
+            return b;
+        }
+
+        /// <summary>
+        /// Reads 'int' type value from Parcel object
+        /// </summary>
+        /// <returns>'int' type data</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public int ReadInt()
+        {
+            Interop.LibRPCPort.Parcel.ReadInt32(_handle, out int b);
+            return b;
+        }
+
+        /// <summary>
+        /// Reads 'long' type value from Parcel object
+        /// </summary>
+        /// <returns>'long' type data</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public long ReadLong()
+        {
+            Interop.LibRPCPort.Parcel.ReadInt64(_handle, out long b);
+            return b;
+        }
+
+        /// <summary>
+        /// Reads 'float' type value from Parcel object
+        /// </summary>
+        /// <returns>'float' type data</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public float ReadFloat()
+        {
+            Interop.LibRPCPort.Parcel.ReadFloat(_handle, out float b);
+            return b;
+        }
+
+        /// <summary>
+        /// Reads 'double' type value from Parcel object
+        /// </summary>
+        /// <returns>'double' type data</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public double ReadDouble()
+        {
+            Interop.LibRPCPort.Parcel.ReadDouble(_handle, out double b);
+            return b;
+        }
+
+        /// <summary>
+        /// Reads 'string' type value from Parcel object
+        /// </summary>
+        /// <returns>'string' type data</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public string ReadString()
+        {
+            Interop.LibRPCPort.Parcel.ReadString(_handle, out string b);
+            return b;
+        }
+
+        /// <summary>
+        /// Reads 'bool' type value from Parcel object
+        /// </summary>
+        /// <returns>'bool' type data</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public bool ReadBool()
+        {
+            Interop.LibRPCPort.Parcel.ReadBool(_handle, out bool b);
+            return b;
+        }
+
+        /// <summary>
+        /// Reads 'Bundle' type value from Parcel object
+        /// </summary>
+        /// <returns>'Bundle' type data</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public Bundle ReadBundle()
+        {
+            Interop.LibRPCPort.Parcel.ReadBundle(_handle, out IntPtr b);
+
+            return new Bundle(new SafeBundleHandle(b, true));
+        }
+
+        /// <summary>
+        /// Reads a count for array from Parcel object
+        /// </summary>
+        /// <returns>Array count</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public int ReadArrayCount()
+        {
+            Interop.LibRPCPort.Parcel.ReadArrayCount(_handle, out int b);
+            return b;
+        }
+
+        /// <summary>
+        /// Writes bytes into Parcel object
+        /// </summary>
+        /// <param name="bytes">Array of bytes</param>
+        /// <since_tizen> 5 </since_tizen>
+        public void Write(byte[] bytes)
+        {
+            Interop.LibRPCPort.Parcel.Write(_handle, bytes, bytes.Length);
+        }
+
+        /// <summary>
+        /// Reads bytes from Parcel object
+        /// </summary>
+        /// <param name="size">Bytes to read</param>
+        /// <returns>Array of bytes</returns>
+        /// <since_tizen> 5 </since_tizen>
+        public byte[] Read(int size)
+        {
+            var ret = new byte[size];
+            Interop.LibRPCPort.Parcel.Read(_handle, ret, size);
+            return ret;
+        }
+
+        #region IDisposable Support
+        private bool disposedValue = false;
+
+        private void Dispose(bool disposing)
+        {
+            if (!disposedValue)
+            {
+                if (disposing)
+                {
+                }
+
+                if (_handle != IntPtr.Zero)
+                {
+                    Interop.LibRPCPort.Parcel.Destroy(_handle);
+                    _handle = IntPtr.Zero;
+                }
+
+                disposedValue = true;
+            }
+        }
+
+        /// <summary>
+        /// Finalizer of the class Parcel
+        /// </summary>
+        ~Parcel()
+        {
+            Dispose(false);
+        }
+
+        /// <summary>
+        /// Release all resources used by the class Parcel
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+        #endregion
+    }
+}
diff --git a/src/Tizen.Applications.Common/Tizen.Applications.RPCPort/Port.cs b/src/Tizen.Applications.Common/Tizen.Applications.RPCPort/Port.cs
new file mode 100755 (executable)
index 0000000..c33e2c4
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Tizen.Applications.RPCPort
+{
+    /// <summary>
+    /// The class for communicating each other between proxy and stub
+    /// </summary>
+    /// <since_tizen> 5 </since_tizen>
+    public class Port
+    {
+        /// <summary>
+        /// Enumeration for RPC port types
+        /// </summary>
+        public enum Type
+        {
+            /// <summary>
+            /// Main channel to communicate
+            /// </summary>
+            Main,
+
+            /// <summary>
+            /// Sub channel for callbacks
+            /// </summary>
+            Callback
+        }
+
+        internal IntPtr Handle { get; set; }
+        internal Port() { }
+    }
+}
diff --git a/src/Tizen.Applications.Common/Tizen.Applications.RPCPort/ProxyBase.cs b/src/Tizen.Applications.Common/Tizen.Applications.RPCPort/ProxyBase.cs
new file mode 100755 (executable)
index 0000000..e904444
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Tizen.Applications.RPCPort
+{
+    /// <summary>
+    /// Abstract class for making a proxy class for RPC
+    /// </summary>
+    /// <since_tizen> 5 </since_tizen>
+    public abstract class ProxyBase : IDisposable
+    {
+        private Interop.LibRPCPort.Proxy.ConnectedEventCallback _connectedEventCallback;
+        private Interop.LibRPCPort.Proxy.DisconnectedEventCallback _disconnectedEventCallback;
+        private Interop.LibRPCPort.Proxy.RejectedEventCallback _rejectedEventCallback;
+        private Interop.LibRPCPort.Proxy.ReceivedEventCallback _receivedEventCallback;
+        private IntPtr _proxy;
+
+        /// <summary>
+        /// Gets Port object
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        protected Port Port { get; private set; }
+
+        /// <summary>
+        /// Gets Port object for asynchronous events
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        protected Port CallbackPort { get; private set; }
+
+        /// <summary>
+        /// Constructor for this class
+        /// </summary>
+        /// <exception cref="InvalidIOException">Thrown when internal IO error happens</exception>
+        /// <since_tizen> 5 </since_tizen>
+        public ProxyBase()
+        {
+            if (Interop.LibRPCPort.Proxy.Create(out _proxy) != Interop.LibRPCPort.ErrorCode.None)
+                throw new InvalidIOException();
+            _connectedEventCallback = new Interop.LibRPCPort.Proxy.ConnectedEventCallback(OnConnectedEvent);
+            _disconnectedEventCallback = new Interop.LibRPCPort.Proxy.DisconnectedEventCallback(OnDisconnectedEvent);
+            _rejectedEventCallback = new Interop.LibRPCPort.Proxy.RejectedEventCallback(OnRejectedEvent);
+            _receivedEventCallback = new Interop.LibRPCPort.Proxy.ReceivedEventCallback(OnReceivedEvent);
+            Interop.LibRPCPort.Proxy.AddConnectedEventCb(_proxy, _connectedEventCallback, IntPtr.Zero);
+            Interop.LibRPCPort.Proxy.AddDisconnectedEventCb(_proxy, _disconnectedEventCallback, IntPtr.Zero);
+            Interop.LibRPCPort.Proxy.AddRejectedEventCb(_proxy, _rejectedEventCallback, IntPtr.Zero);
+            Interop.LibRPCPort.Proxy.AddReceivedEventCb(_proxy, _receivedEventCallback, IntPtr.Zero);
+        }
+
+        /// <summary>
+        /// Connects to port
+        /// </summary>
+        /// <param name="appid">The target stub app ID</param>
+        /// <param name="port">The name of rpc port</param>
+        /// <exception cref="InvalidIDException">Thrown when not available app ID is used</exception>
+        /// <exception cref="InvalidIOException">Thrown when internal IO error happens</exception>
+        /// <exception cref="PermissionDeniedException">Thrown when the permission is denied</exception>
+        /// <privilege>http://tizen.org/privilege/datasharing</privilege>
+        /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+        /// <since_tizen> 5 </since_tizen>
+        protected void Connect(string appid, string port)
+        {
+            var err = Interop.LibRPCPort.Proxy.Connect(_proxy, appid, port);
+            switch (err)
+            {
+                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
+                    throw new InvalidIDException();
+                case Interop.LibRPCPort.ErrorCode.PermissionDenied:
+                    throw new PermissionDeniedException();
+                case Interop.LibRPCPort.ErrorCode.IoError:
+                    throw new InvalidIOException();
+            }
+        }
+
+        /// <summary>
+        /// Gets a port
+        /// </summary>
+        /// <param name="t">The type of port</param>
+        /// <returns>Port object</returns>
+        /// <exception cref="InvalidIOException">Thrown when internal IO error happens</exception>
+        /// <since_tizen> 5 </since_tizen>
+        protected Port GetPort(Port.Type t)
+        {
+            var err = Interop.LibRPCPort.Proxy.GetPort(_proxy,
+                (Interop.LibRPCPort.PortType)t, out IntPtr port);
+            switch (err)
+            {
+                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
+                case Interop.LibRPCPort.ErrorCode.IoError:
+                    throw new InvalidIOException();
+            }
+
+            return new Port() { Handle = port };
+        }
+
+        /// <summary>
+        /// Abstract method for receiving connected event
+        /// </summary>
+        /// <param name="endPoint">The target stub app ID</param>
+        /// <param name="portName">The name of the port</param>
+        /// <param name="port">Port object for reading and writing</param>
+        /// <since_tizen> 5 </since_tizen>
+        protected abstract void OnConnectedEvent(string endPoint, string portName, Port port);
+
+        /// <summary>
+        /// Abstract method for receiving disconnected event
+        /// </summary>
+        /// <param name="endPoint">The target stub app ID</param>
+        /// <param name="portName">The name of the port</param>
+        /// <since_tizen> 5 </since_tizen>
+        protected abstract void OnDisconnectedEvent(string endPoint, string portName);
+
+        /// <summary>
+        /// Abstract method called when the proxy received data from stub
+        /// </summary>
+        /// <param name="endPoint">The target stub app ID</param>
+        /// <param name="portName">The name of the port</param>
+        /// <since_tizen> 5 </since_tizen>
+        protected abstract void OnReceivedEvent(string endPoint, string portName);
+
+        /// <summary>
+        /// Abstract method for receiving rejected event
+        /// </summary>
+        /// <param name="endPoint">The target stub app ID</param>
+        /// <param name="portName">The name of the port</param>
+        /// <since_tizen> 5 </since_tizen>
+        protected abstract void OnRejectedEvent(string endPoint, string portName);
+
+        private void OnConnectedEvent(string endPoint, string portName, IntPtr port, IntPtr data)
+        {
+            Port = new Port() { Handle = port };
+            CallbackPort = GetPort(Port.Type.Callback);
+            OnConnectedEvent(endPoint, portName, Port);
+        }
+
+        private void OnDisconnectedEvent(string endPoint, string portName, IntPtr data)
+        {
+            Port = null;
+            CallbackPort = null;
+            OnDisconnectedEvent(endPoint, portName);
+        }
+
+        private void OnReceivedEvent(string endPoint, string portName, IntPtr data)
+        {
+            OnReceivedEvent(endPoint, portName);
+        }
+
+        private void OnRejectedEvent(string endPoint, string portName, IntPtr data)
+        {
+            OnRejectedEvent(endPoint, portName);
+        }
+
+        #region IDisposable Support
+        private bool disposedValue = false;
+
+        private void Dispose(bool disposing)
+        {
+            if (!disposedValue)
+            {
+                if (disposing)
+                {
+                }
+                if (_proxy != IntPtr.Zero)
+                    Interop.LibRPCPort.Proxy.Destroy(_proxy);
+                _proxy = IntPtr.Zero;
+
+                disposedValue = true;
+            }
+        }
+
+        /// <summary>
+        /// Finalizer of the class ProxyBase
+        /// </summary>
+        ~ProxyBase()
+        {
+            Dispose(false);
+        }
+
+        /// <summary>
+        /// Release all resources used by the class ProxyBase
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+        #endregion
+    }
+}
diff --git a/src/Tizen.Applications.Common/Tizen.Applications.RPCPort/StubBase.cs b/src/Tizen.Applications.Common/Tizen.Applications.RPCPort/StubBase.cs
new file mode 100755 (executable)
index 0000000..c9cc668
--- /dev/null
@@ -0,0 +1,209 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Tizen.Applications.RPCPort
+{
+    /// <summary>
+    /// Abstract class for making a stub class for RPC
+    /// </summary>
+    /// <since_tizen> 5 </since_tizen>
+    public abstract class StubBase : IDisposable
+    {
+        private Interop.LibRPCPort.Stub.ConnectedEventCallback _connectedEventCallback;
+        private Interop.LibRPCPort.Stub.DisconnectedEventCallback _disconnectedEventCallback;
+        private Interop.LibRPCPort.Stub.ReceivedEventCallback _receivedEventCallback;
+        private IntPtr _stub;
+
+        /// <summary>
+        /// Gets port name
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        public string PortName { get; }
+
+        /// <summary>
+        /// Constructor for this class
+        /// </summary>
+        /// <param name="portName">The name of the port which want to listen</param>
+        /// <exception cref="InvalidIOException">Thrown when internal IO error happens</exception>
+        /// <since_tizen> 5 </since_tizen>
+        public StubBase(string portName)
+        {
+            if (Interop.LibRPCPort.Stub.Create(out _stub, portName) != Interop.LibRPCPort.ErrorCode.None)
+                throw new InvalidIOException();
+            PortName = portName;
+            _connectedEventCallback = new Interop.LibRPCPort.Stub.ConnectedEventCallback(OnConnectedEvent);
+            _disconnectedEventCallback = new Interop.LibRPCPort.Stub.DisconnectedEventCallback(OnDisconnectedEvent);
+            _receivedEventCallback = new Interop.LibRPCPort.Stub.ReceivedEventCallback(OnReceivedEvent);
+            Interop.LibRPCPort.Stub.AddReceivedEventCb(_stub, _receivedEventCallback, IntPtr.Zero);
+            Interop.LibRPCPort.Stub.AddConnectedEventCb(_stub, _connectedEventCallback, IntPtr.Zero);
+            Interop.LibRPCPort.Stub.AddDisconnectedEventCb(_stub, _disconnectedEventCallback, IntPtr.Zero);
+        }
+
+        /// <summary>
+        /// Listens to the requests for connections
+        /// </summary>
+        /// <exception cref="InvalidIOException">Thrown when internal IO error happens</exception>
+        /// <since_tizen> 5 </since_tizen>
+        protected void Listen()
+        {
+            var err = Interop.LibRPCPort.Stub.Listen(_stub);
+            switch (err)
+            {
+                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
+                case Interop.LibRPCPort.ErrorCode.IoError:
+                    throw new InvalidIOException();
+            }
+        }
+
+        /// <summary>
+        /// Adds a privilege to the stub
+        /// </summary>
+        /// <param name="privilege">The privilege to access this stub</param>
+        /// <exception cref="ArgumentNullException">Thrown when the privilege is null</exception>
+        /// <since_tizen> 5 </since_tizen>
+        protected void AddPrivilege(string privilege)
+        {
+            if (privilege == null)
+                throw new ArgumentNullException();
+            Interop.LibRPCPort.Stub.AddPrivilege(_stub, privilege);
+        }
+
+        /// <summary>
+        /// Sets trusted to the stub
+        /// </summary>
+        /// <param name="trusted">Whether stub allows only trusted proxy or not</param>
+        /// <since_tizen> 5 </since_tizen>
+        protected void SetTrusted(bool trusted)
+        {
+            Interop.LibRPCPort.Stub.SetTrusted(_stub, trusted);
+        }
+
+        /// <summary>
+        /// Gets s port
+        /// </summary>
+        /// <param name="t">The type of port</param>
+        /// <param name="instance">The ID of the instance which is connected</param>
+        /// <returns>Port object</returns>
+        /// <exception cref="InvalidIDException">Thrown when invalid instance was used</exception>
+        /// <exception cref="InvalidIOException">Thrown when internal IO error happens</exception>
+        /// <since_tizen> 5 </since_tizen>
+        protected Port GetPort(Port.Type t, string instance)
+        {
+            var err = Interop.LibRPCPort.Stub.GetPort(_stub,
+                (Interop.LibRPCPort.PortType)t, instance, out IntPtr port);
+            switch (err)
+            {
+                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
+                    throw new InvalidIDException();
+                case Interop.LibRPCPort.ErrorCode.IoError:
+                    throw new InvalidIOException();
+            }
+
+            return new Port() { Handle = port };
+        }
+
+        /// <summary>
+        /// Abstract method for receiving connected event
+        /// </summary>
+        /// <param name="sender">The target proxy app ID</param>
+        /// <param name="instance">The information of the request</param>
+        /// <since_tizen> 5 </since_tizen>
+        protected abstract void OnConnectedEvent(string sender, string instance);
+
+        /// <summary>
+        /// Abstract method for receiving disconnected event
+        /// </summary>
+        /// <param name="sender">The target proxy app ID</param>
+        /// <param name="instance">The information of the request</param>
+        /// <since_tizen> 5 </since_tizen>
+        protected abstract void OnDisconnectedEvent(string sender, string instance);
+
+        /// <summary>
+        /// Abstract method called when the stub received data from proxy
+        /// </summary>
+        /// <param name="sender">The target proxy app ID</param>
+        /// <param name="instance">The information of the request</param>
+        /// <param name="port">Port object for reading and writing</param>
+        /// <returns>'true' to continue receiving data, otherwise 'false' to disconnect from the port</returns>
+        /// <since_tizen> 5 </since_tizen>
+        protected abstract bool OnReceivedEvent(string sender, string instance, Port port);
+
+        /// <summary>
+        /// Abstract method called right before disposing object
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        protected abstract void OnTerminatedEvent();
+
+        private void OnConnectedEvent(string sender, string instance, IntPtr data)
+        {
+            OnConnectedEvent(sender, instance);
+        }
+
+        private void OnDisconnectedEvent(string sender, string instance, IntPtr data)
+        {
+            OnDisconnectedEvent(sender, instance);
+        }
+
+        private int OnReceivedEvent(string sender, string instance, IntPtr port, IntPtr data)
+        {
+            bool b = OnReceivedEvent(sender, instance, new Port() { Handle = port });
+            if (b)
+                return 0;
+            return -1;
+        }
+
+        #region IDisposable Support
+        private bool disposedValue = false;
+
+        private void Dispose(bool disposing)
+        {
+            if (!disposedValue)
+            {
+                if (disposing)
+                {
+                }
+
+                OnTerminatedEvent();
+
+                if (_stub != IntPtr.Zero)
+                    Interop.LibRPCPort.Proxy.Destroy(_stub);
+                _stub = IntPtr.Zero;
+
+                disposedValue = true;
+            }
+        }
+
+        /// <summary>
+        /// Finalizer of the class StubBase
+        /// </summary>
+        ~StubBase()
+        {
+            Dispose(false);
+        }
+
+        /// <summary>
+        /// Release all resources used by the class StubBase
+        /// </summary>
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+        #endregion
+    }
+}