Add exception handlers and comments 60/173160/3
authorJunghoon Park <jh9216.park@samsung.com>
Tue, 20 Mar 2018 01:46:35 +0000 (10:46 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Tue, 20 Mar 2018 05:22:41 +0000 (14:22 +0900)
Change-Id: Ib678d14b9cf54147c1aa83e8ab1ba078061aa1f9
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
idlc/cpp_gen/cpp_proxy_body_gen_cb.h
idlc/cpp_gen/cpp_proxy_header_gen_cb.h
idlc/cpp_gen/cpp_stub_body_gen_cb.h
idlc/cpp_gen/cpp_stub_header_gen_cb.h

index e19bdc6..9009a3b 100644 (file)
@@ -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);
index 202b072..ee2f6d4 100644 (file)
@@ -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:
+    /// <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[] =
index 6476ae7..09953eb 100644 (file)
@@ -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) {
index 195667a..1c60306 100644 (file)
@@ -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:
+      /// <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[] =
@@ -66,7 +86,19 @@ const char CB_PUBLIC_METHODS[] =
 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_;
   }