const char CB_PROXY_HELPER_METHODS[] =
R"__cpp_cb(
-int $$::Connect() {
- return rpc_port_proxy_connect(proxy_, target_appid_.c_str(), "$$");
+void $$::Connect() {
+ int ret = rpc_port_proxy_connect(proxy_, target_appid_.c_str(), "$$");
+
+ switch (ret) {
+ case RPC_PORT_ERROR_INVALID_PARAMETER:
+ throw InvalidIDException();
+
+ case RPC_PORT_ERROR_IO_ERROR:
+ throw InvalidIOException();
+
+ case RPC_PORT_ERROR_PERMISSION_DENIED:
+ throw PermissionDeniedException();
+ }
}
void $$::ProcessReceivedEvent(rpc_port_parcel_h parcel) {
$$::$$(IEventListener* listener, const std::string& target_appid)
: port_(nullptr), proxy_(nullptr), listener_(listener),
target_appid_(target_appid) {
- rpc_port_proxy_create(&proxy_);
+ int r = rpc_port_proxy_create(&proxy_);
+
+ if (r != RPC_PORT_ERROR_NONE)
+ throw InvalidIOException();
rpc_port_proxy_add_connected_event_cb(proxy_, OnConnectedCB, this);
rpc_port_proxy_add_disconnected_event_cb(proxy_, OnDisconnectedCB, this);
rpc_port_proxy_add_rejected_event_cb(proxy_, OnRejectedCB, this);
class Exception {};
class NotConnectedSocketException : public Exception {};
class InvalidProtocolException : public Exception {};
+class InvalidIOException : public Exception {};
+class PermissionDeniedException : public Exception {};
+class InvalidIDException : public Exception {};
)__cpp_cb";
const char CB_PUBLIC_MEMBERS[] =
R"__cpp_cb( class IEventListener {
public:
+ /// <summary>
+ /// This method will be invoked when the client app is connected to the servicece app.
+ /// </summary>
virtual void OnConnected() = 0;
+
+ /// <summary>
+ /// This method will be invoked after the client app was disconnected from the servicece app.
+ /// </summary>
virtual void OnDisconnected() = 0;
+
+ /// <summary>
+ /// This method will be invoked when the service app rejects the client app.
+ /// </summary>
virtual void OnRejected() = 0;
};
+ /// <summary>
+ /// Constructor for this class
+ /// </summary>
+ /// <param name="listener">The listener for events</param>
+ /// <param name="target_appid">The service app ID to connect</param>
$$(IEventListener* listener, const std::string& target_appid);
+
+ /// <summary>
+ /// Destructor for this class
+ /// </summary>
virtual ~$$();
- int Connect();
+ /// <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>
+ void Connect();
+
)__cpp_cb";
const char CB_PRIVATE_MEMBERS[] =
const char CB_CTOR_FRONT[] =
R"__cpp_cb(
$$::$$() {
- rpc_port_stub_create(&stub_, "$$");
+ int r = rpc_port_stub_create(&stub_, "$$");
+ if (r != RPC_PORT_ERROR_NONE)
+ throw InvalidIOException();
rpc_port_stub_add_connected_event_cb(stub_, OnConnectedCB, this);
rpc_port_stub_add_disconnected_event_cb(stub_, OnDisconnectedCB, this);
rpc_port_stub_add_received_event_cb(stub_, OnReceivedCB, this);
void $$::Listen(
std::shared_ptr<$$::ServiceBase::Factory> service_factory) {
service_factory_ = std::move(service_factory);
- rpc_port_stub_listen(stub_);
+ int r = rpc_port_stub_listen(stub_);
+
+ switch (r) {
+ case RPC_PORT_ERROR_INVALID_PARAMETER:
+ case RPC_PORT_ERROR_IO_ERROR:
+ throw InvalidIOException();
+ }
}
void $$::OnConnectedCB(const char* sender, const char* instance, void *data) {
class Exception {};
class NotConnectedSocketException : public Exception {};
class InvalidProtocolException : public Exception {};
+class InvalidIOException : public Exception {};
)__cpp_cb";
const char CB_PRIVATE_MEMBERS[] =
public:
class Factory {
public:
+ /// <summary>
+ /// The method for making service instances
+ /// </summary>
+ /// <param name="sender">The client app ID</param>
+ /// <param name="instance">The client instance ID</param>
virtual std::unique_ptr<ServiceBase> CreateService(std::string sender, std::string instance) = 0;
};
virtual ~ServiceBase() = default;
+ /// <summary>
+ /// Gets client app ID
+ /// </summary>
const std::string& GetSender() const {
return sender_;
}
+ /// <summary>
+ /// Gets client instance ID
+ /// </summary>
const std::string& GetInstance() const {
return instance_;
}
+ /// <summary>
+ /// This method will be called when the client is connected
+ /// </summary>
virtual void OnCreate() = 0;
+
+ /// <summary>
+ /// This method will be called when the client is disconnected
+ /// </summary>
virtual void OnTerminate() = 0;
+
)__cpp_cb";
const char CB_SERVICE_BASE_BACK[] =
R"__cpp_cb( $$();
~$$();
+ /// <summary>
+ /// Listens to client apps
+ /// </summary>
+ /// <param name="service_factory">The factory object for making service instances</param>
+ /// <exception cref="InvalidIOException">
+ /// Thrown when internal I/O error happen.
+ /// </exception>
void Listen(std::shared_ptr<ServiceBase::Factory> service_factory);
+
+ /// <summary>
+ /// Gets service objects which are connected
+ /// </summary>
+ /// <returns>The list of service objects which are connected</returns>
const std::list<std::shared_ptr<ServiceBase>>& GetServices() const {
return services_;
}