From: Junghoon Park Date: Tue, 20 Mar 2018 01:46:35 +0000 (+0900) Subject: Add exception handlers and comments X-Git-Tag: accepted/tizen/unified/20180322.145033~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F60%2F173160%2F3;p=platform%2Fcore%2Fappfw%2Ftidl.git Add exception handlers and comments Change-Id: Ib678d14b9cf54147c1aa83e8ab1ba078061aa1f9 Signed-off-by: Junghoon Park --- diff --git a/idlc/cpp_gen/cpp_proxy_body_gen_cb.h b/idlc/cpp_gen/cpp_proxy_body_gen_cb.h index e19bdc6..9009a3b 100644 --- a/idlc/cpp_gen/cpp_proxy_body_gen_cb.h +++ b/idlc/cpp_gen/cpp_proxy_body_gen_cb.h @@ -53,8 +53,19 @@ R"__cpp_cb( 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) { @@ -136,7 +147,10 @@ R"__cpp_cb( $$::$$(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); diff --git a/idlc/cpp_gen/cpp_proxy_header_gen_cb.h b/idlc/cpp_gen/cpp_proxy_header_gen_cb.h index 202b072..ee2f6d4 100644 --- a/idlc/cpp_gen/cpp_proxy_header_gen_cb.h +++ b/idlc/cpp_gen/cpp_proxy_header_gen_cb.h @@ -19,20 +19,59 @@ R"__cpp_cb( 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: + /// + /// This method will be invoked when the client app is connected to the servicece app. + /// virtual void OnConnected() = 0; + + /// + /// This method will be invoked after the client app was disconnected from the servicece app. + /// virtual void OnDisconnected() = 0; + + /// + /// This method will be invoked when the service app rejects the client app. + /// virtual void OnRejected() = 0; }; + /// + /// Constructor for this class + /// + /// The listener for events + /// The service app ID to connect $$(IEventListener* listener, const std::string& target_appid); + + /// + /// Destructor for this class + /// virtual ~$$(); - int Connect(); + /// + /// Connects to the service app. + /// + /// http://tizen.org/privilege/appmanager.launch + /// http://tizen.org/privilege/datasharing + /// + /// Thrown when the appid to connect is invalid. + /// + /// + /// Thrown when internal I/O error happen. + /// + /// + /// Thrown when the permission is denied. + /// + /// If you want to use this method, you must add privileges. + void Connect(); + )__cpp_cb"; const char CB_PRIVATE_MEMBERS[] = diff --git a/idlc/cpp_gen/cpp_stub_body_gen_cb.h b/idlc/cpp_gen/cpp_stub_body_gen_cb.h index 6476ae7..09953eb 100644 --- a/idlc/cpp_gen/cpp_stub_body_gen_cb.h +++ b/idlc/cpp_gen/cpp_stub_body_gen_cb.h @@ -17,7 +17,9 @@ 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); @@ -34,7 +36,13 @@ $$::~$$() { 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) { diff --git a/idlc/cpp_gen/cpp_stub_header_gen_cb.h b/idlc/cpp_gen/cpp_stub_header_gen_cb.h index 195667a..1c60306 100644 --- a/idlc/cpp_gen/cpp_stub_header_gen_cb.h +++ b/idlc/cpp_gen/cpp_stub_header_gen_cb.h @@ -19,6 +19,7 @@ R"__cpp_cb( class Exception {}; class NotConnectedSocketException : public Exception {}; class InvalidProtocolException : public Exception {}; +class InvalidIOException : public Exception {}; )__cpp_cb"; const char CB_PRIVATE_MEMBERS[] = @@ -35,21 +36,40 @@ const char CB_SERVICE_BASE_FRONT[] = R"__cpp_cb( class ServiceBase { public: class Factory { public: + /// + /// The method for making service instances + /// + /// The client app ID + /// The client instance ID virtual std::unique_ptr CreateService(std::string sender, std::string instance) = 0; }; virtual ~ServiceBase() = default; + /// + /// Gets client app ID + /// const std::string& GetSender() const { return sender_; } + /// + /// Gets client instance ID + /// const std::string& GetInstance() const { return instance_; } + /// + /// This method will be called when the client is connected + /// virtual void OnCreate() = 0; + + /// + /// This method will be called when the client is disconnected + /// virtual void OnTerminate() = 0; + )__cpp_cb"; const char CB_SERVICE_BASE_BACK[] = @@ -66,7 +86,19 @@ const char CB_PUBLIC_METHODS[] = R"__cpp_cb( $$(); ~$$(); + /// + /// Listens to client apps + /// + /// The factory object for making service instances + /// + /// Thrown when internal I/O error happen. + /// void Listen(std::shared_ptr service_factory); + + /// + /// Gets service objects which are connected + /// + /// The list of service objects which are connected const std::list>& GetServices() const { return services_; }