public const string RpcPort = "librpc-port.so.1";
}
+ 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 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 int Create(out IntPtr handle);
+ 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 int CreateFromPort(out IntPtr parcelHandle, IntPtr portHandle);
+ 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 int Send(IntPtr parcelHandle, IntPtr portHandle);
+ 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 int Destroy(IntPtr handle);
+ 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 int WriteByte(IntPtr parcelHandle, byte b);
+ 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 int WriteInt16(IntPtr parcelHandle, short i);
+ 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 int WriteInt32(IntPtr parcelHandle, int i);
+ 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 int WriteInt64(IntPtr parcelHandle, long i);
+ 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 int WriteFloat(IntPtr parcelHandle, float f);
+ 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 int WriteDouble(IntPtr parcelHandle, double d);
+ 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 int WriteString(IntPtr parcelHandle, string str);
+ 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 int WriteBool(IntPtr parcelHandle, bool b);
+ 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 int WriteBundle(IntPtr parcelHandle, IntPtr b);
+ 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 int WriteArrayCount(IntPtr parcelHandle, int 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 int ReadByte(IntPtr parcelHandle, out byte b);
+ 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 int ReadInt16(IntPtr parcelHandle, out short i);
+ 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 int ReadInt32(IntPtr parcelHandle, out int i);
+ 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 int ReadInt64(IntPtr parcelHandle, out long i);
+ 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 int ReadFloat(IntPtr parcelHandle, out float f);
+ 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 int ReadDouble(IntPtr parcelHandle, out double f);
+ 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 int ReadString(IntPtr parcelHandle, out string str);
+ 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 int ReadBool(IntPtr parcelHandle, out bool b);
+ 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 int ReadBundle(IntPtr parcelHandle, out IntPtr b);
+ 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 int ReadArrayCount(IntPtr parcelHandle, out int count);
+ internal static extern ErrorCode ReadArrayCount(IntPtr parcelHandle, out int count);
}
$$
}
//int rpc_port_proxy_create(rpc_port_proxy_h *h);
[DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_create")]
- internal static extern int Create(out IntPtr handle);
+ 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 int Destroy(IntPtr handle);
+ 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 int Connect(IntPtr handle, string appId, string port);
+ 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 int AddConnectedEventCb(IntPtr handle, ConnectedEventCallback cb, IntPtr data);
+ 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 int AddDisconnectedEventCb(IntPtr handle, DisconnectedEventCallback cb, IntPtr data);
+ 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 int AddRejectedEventCb(IntPtr handle, RejectedEventCallback cb, IntPtr data);
+ 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 int AddReceivedEventCb(IntPtr handle, ReceivedEventCallback cb, IntPtr data);
+ internal static extern ErrorCode AddReceivedEventCb(IntPtr handle, ReceivedEventCallback cb, IntPtr data);
}
)__cs_cb";
//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 int Create(out IntPtr handle, string portName);
+ 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 int Destroy(IntPtr handle);
+ 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 int Listen(IntPtr handle);
+ 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 int AddConnectedEventCb(IntPtr handle, ConnectedEventCallback cb, IntPtr data);
+ 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 int AddDisconnectedEventCb(IntPtr handle, DisconnectedEventCallback cb, IntPtr data);
+ 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 int AddReceivedEventCb(IntPtr handle, ReceivedEventCallback cb, IntPtr data);
+ 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 int AddPrivilege(IntPtr handle, string 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 int SetTrusted(IntPtr handle, bool trusted);
+ internal static extern ErrorCode SetTrusted(IntPtr handle, bool trusted);
}
)__cs_cb";
};
}
+void CsGeneratorBase::GenExceptions(std::ofstream& stream) {
+ stream << CB_EXCEPTIONS;
+}
+
void CsGeneratorBase::GenStructures(std::ofstream& stream) {
for (auto& i : GetDocument().GetBlocks()) {
if (i->GetType() != Block::TYPE_STRUCTURE)
void GenParameters(std::ofstream& stream, const Parameters& ps);
void GenCallbacks(std::ofstream& stream, const Interface& iface,
bool is_proxy);
+ void GenExceptions(std::ofstream& stream);
std::string ConvertTypeToString(const BaseType& type);
std::string ConvertTypeToDeserializer(const BaseType& type,
* limitations under the License.
*/
+const char CB_EXCEPTIONS[] =
+R"__cs_cb( public class InvalidIOException : InvalidOperationException {}
+ public class InvalidIDException : InvalidOperationException {}
+ public class PermissionDeniedException : InvalidOperationException {}
+ public class InvalidProtocolException : InvalidOperationException {}
+ public class NotConnectedSocketException : InvalidOperationException {}
+
+)__cs_cb";
+
const char CB_CALLBACK_BASE[] =
R"__cs_cb(
public abstract class CallbackBase
public void Invoke($$)
{
if (_port == IntPtr.Zero || _service == null)
- throw new InvalidOperationException("Not connected!");
+ throw new NotConnectedSocketException();
if (!_service.IsAlive)
- throw new InvalidOperationException("Invalid delegate object!");
+ throw new InvalidProtocolException();
Interop.LibRPCPort.Parcel.Create(out IntPtr p);
Interop.LibRPCPort.Parcel.WriteInt32(p, (int)MethodId.__Callback);
GenBrace(stream, 0, [&]() {
stream << "namespace " << GetFileNamespace() << NLine(1);
GenBrace(stream, 0, [&]() {
+ GenExceptions(stream);
GenStructures(stream);
stream << Tab(1) << "namespace Proxy" << NLine(1);
GenBrace(stream, TAB_SIZE, [&]() {
const char* receive_block =
"if (parcel_received == IntPtr.Zero)\n" \
"{\n" \
- " throw new InvalidOperationException(\"Can't receive data\");\n" \
+ " throw new InvalidProtocolException();\n" \
"}\n";
stream << AddIndent(TAB_SIZE * 4, receive_block) << NLine(1);
if (cmd != (int)MethodId.__Callback)
{
Interop.LibRPCPort.Parcel.Destroy(parcel_received);
- throw new InvalidOperationException("Invalid protocol");
+ throw new InvalidProtocolException();
}
ProcessReceivedEvent(parcel_received);
{
do
{
- int ret = Interop.LibRPCPort.Parcel.CreateFromPort(out IntPtr p, port);
+ var ret = Interop.LibRPCPort.Parcel.CreateFromPort(out IntPtr p, port);
- if (ret != 0)
+ if (ret != Interop.LibRPCPort.ErrorCode.None)
break;
Interop.LibRPCPort.Parcel.ReadInt32(p, out int cmd);
if (cmd == (int)MethodId.__Result)
const char CB_CONNECT_METHOD[] =
R"__cs_cb(
+ /// <summary>
+ /// Connects to the service app.
+ /// </summary>
+ /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+ /// <privilege>http://tizen.org/privilege/datasharing</privilege>
+ /// <exception cref="InvalidIDException">
+ /// Thrown when the appid to connect is invalid.
+ /// </exception>
+ /// <exception cref="InvalidIOException">
+ /// Thrown when internal I/O error happen.
+ /// </exception>
+ /// <exception cref="PermissionDeniedException">
+ /// Thrown when the permission is denied.
+ /// </exception>
+ /// <remark> If you want to use this method, you must add privileges.</remark>
public void Connect()
{
- Interop.LibRPCPort.Proxy.Create(out _proxy);
+ 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);
Interop.LibRPCPort.Proxy.AddDisconnectedEventCb(_proxy, _disconnectedEventCallback, IntPtr.Zero);
Interop.LibRPCPort.Proxy.AddRejectedEventCb(_proxy, _rejectedEventCallback, IntPtr.Zero);
Interop.LibRPCPort.Proxy.AddReceivedEventCb(_proxy, _receivedEventCallback, IntPtr.Zero);
- if (Interop.LibRPCPort.Proxy.Connect(_proxy, _appId, "$$") != 0)
- throw new InvalidOperationException("Connection failed");
+
+ var err = Interop.LibRPCPort.Proxy.Connect(_proxy, _appId, "$$");
+ 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();
+ }
}
)__cs_cb";
const char CB_INVOCATION_PRE[] =
R"__cs_cb( if (!_online)
- throw new InvalidOperationException("Not connected!");
+ throw new NotConnectedSocketException();
Interop.LibRPCPort.Parcel.Create(out IntPtr p);
)__cs_cb";
GenBrace(stream, 0, [&]() {
stream << "namespace " << GetFileNamespace() << NLine(1);
GenBrace(stream, 0, [&]() {
+ GenExceptions(stream);
GenStructures(stream);
stream << Tab(1) << "namespace Stub" << NLine(1);
GenBrace(stream, TAB_SIZE, [&]() {
R"__cs_cb(
public abstract class ServiceBase
{
+ /// <summary>
+ /// The client app ID
+ /// </summary>
public string Sender
{
get; internal set;
}
+ /// <summary>
+ /// The client instance ID
+ /// </summary>
public string Instance
{
get; internal set;
{
}
+ /// <summary>
+ /// This method will be called when the client is connected
+ /// </summary>
public abstract void OnCreate();
+
+ /// <summary>
+ /// This method will be called when the client is disconnected
+ /// </summary>
public abstract void OnTerminate();
)__cs_cb";
R"__cs_cb(
private int OnReceivedEvent(string sender, string instance, IntPtr port, IntPtr data)
{
- int ret = Interop.LibRPCPort.Parcel.CreateFromPort(out IntPtr p, port);
+ var ret = Interop.LibRPCPort.Parcel.CreateFromPort(out IntPtr p, port);
- if (ret != 0)
- return ret;
+ if (ret != Interop.LibRPCPort.ErrorCode.None)
+ return -1;
Interop.LibRPCPort.Parcel.Create(out IntPtr result);
Interop.LibRPCPort.Parcel.ReadInt32(p, out int cmd);
R"__cs_cb(
public $$()
{
- Interop.LibRPCPort.Stub.Create(out _stub, "$$");
+ if (Interop.LibRPCPort.Stub.Create(out _stub, "$$") != Interop.LibRPCPort.ErrorCode.None)
+ throw new InvalidIOException();
_connectedEventCallback = new Interop.LibRPCPort.Stub.ConnectedEventCallback(OnConnectedEvent);
_disconnectedEventCallback = new Interop.LibRPCPort.Stub.DisconnectedEventCallback(OnDisconnectedEvent);
_receivedEventCallback = new Interop.LibRPCPort.Stub.ReceivedEventCallback(OnReceivedEvent);
const char CB_COMMON_METHODS[] =
R"__cs_cb(
+ /// <summary>
+ /// Listens to client apps
+ /// </summary>
+ /// <param name="serviceType">The type object for making service instances</param>
+ /// <exception cref="InvalidIOException">
+ /// Thrown when internal I/O error happen.
+ /// </exception>
+ /// <exception cref="ArgumentException">
+ /// Thrown when serviceType is invalid.
+ /// </exception>
public void Listen(Type serviceType)
{
if (!typeof(ServiceBase).IsAssignableFrom(serviceType))
- throw new InvalidOperationException("Invalid type");
+ throw new ArgumentException("Invalid type");
_serviceType = serviceType;
- Interop.LibRPCPort.Stub.Listen(_stub);
+ var err = Interop.LibRPCPort.Stub.Listen(_stub);
+ switch (err)
+ {
+ case Interop.LibRPCPort.ErrorCode.InvalidParameter:
+ case Interop.LibRPCPort.ErrorCode.IoError:
+ throw new InvalidIOException();
+ }
}
+ /// <summary>
+ /// Gets service objects which are connected
+ /// </summary>
+ /// <returns>The enumerable service objects which are connected</returns>
public IEnumerable<ServiceBase> GetServices()
{
return _services;