Add null check when allocating memory
[platform/core/appfw/message-port.git] / include / message-port.h
old mode 100755 (executable)
new mode 100644 (file)
index 6b194f9..1014655
@@ -1,54 +1,32 @@
-//
-// Open Service Platform
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// 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.
-//
+/*
+ * Open Service Platform
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
 
 
 #ifndef __APPFW_MESSAGE_PORT_H__
 #define __APPFW_MESSAGE_PORT_H__
 
-#ifdef __GNUC__
-#      ifndef EXPORT_API
-#              define EXPORT_API __attribute__((visibility("default")))
-#      endif
-#else
-#      define EXPORT_API
-#endif
-
 #include <bundle.h>
+#include <message_port_error.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /**
- * @brief Enumerations of error code for Application.
- */
-typedef enum
-{
-       MESSAGEPORT_ERROR_NONE = 0, /**< Successful */
-       MESSAGEPORT_ERROR_IO_ERROR = -1,                /**< Internal I/O error */
-       MESSAGEPORT_ERROR_OUT_OF_MEMORY = -2,           /**< Out of memory */
-       MESSAGEPORT_ERROR_INVALID_PARAMETER = -3,       /**< Invalid parameter */
-       MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND = -4,           /**< The message port of the remote application is not found */
-       MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH = -5,   /**< The remote application is not signed with the same certificate */
-       MESSAGEPORT_ERROR_MAX_EXCEEDED = -6,    /**< The size of message has exceeded the maximum limit */
-} messageport_error_e;
-
-
-/**
  * @brief   Called when a message is received from the remote application.
  *
  * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
@@ -59,8 +37,20 @@ typedef enum
  * @remarks @a data must be released with bundle_free() by you
  * @remark @a remote_app_id and @a remote_port will be set if the remote application sends a bidirectional message, otherwise they are NULL.
  */
-typedef void (*messageport_message_cb)(int id, const char* remote_app_id, const char* remote_port, bool trusted_message, bundle* data);
+typedef void (*messageport_message_cb)(int id, const char *remote_app_id, const char *remote_port, bool trusted_message, bundle *data, void *user_data);
 
+/**
+ * @brief Unregisters the local message port. @n
+ *
+ * @param [in] local_port_id the id of the local message port
+ * @param [in] trusted_port true if target port is trusted port
+ * @return Return positive on success, otherwise a negative error value.
+ * @retval #MESSAGEPORT_ERROR_NONE Successful
+ * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The message port of the remote application is not found
+ */
+ int messageport_unregister_local_port(int local_port_id, bool trusted_port);
 
 /**
  * @brief Registers the local message port. @n
@@ -73,8 +63,9 @@ typedef void (*messageport_message_cb)(int id, const char* remote_app_id, const
  * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
  * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
+ * @retval #MESSAGEPORT_ERROR_RESOURCE_UNAVAILABLE Resource temporarily unavailable
  */
-EXPORT_API int messageport_register_local_port(const char* local_port, messageport_message_cb callback);
+ int messageport_register_local_port(const char *local_port, messageport_message_cb callback);
 
 /**
  * @brief Registers the trusted local message port. @n
@@ -88,8 +79,9 @@ EXPORT_API int messageport_register_local_port(const char* local_port, messagepo
  * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
  * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
+ * @retval #MESSAGEPORT_ERROR_RESOURCE_UNAVAILABLE Resource temporarily unavailable
  */
-EXPORT_API int messageport_register_trusted_local_port(const char* local_port, messageport_message_cb callback);
+ int messageport_register_trusted_local_port(const char *local_port, messageport_message_cb callback);
 
 /**
  * @brief Checks if the message port of a remote application is registered.
@@ -102,8 +94,9 @@ EXPORT_API int messageport_register_trusted_local_port(const char* local_port, m
  * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
  * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
+ * @retval #MESSAGEPORT_ERROR_RESOURCE_UNAVAILABLE Resource temporarily unavailable
  */
-EXPORT_API int messageport_check_remote_port(const char* remote_app_id, const char *remote_port, bool* exist);
+ int messageport_check_remote_port(const char *remote_app_id, const char *remote_port, bool *exist);
 
 /**
  * @brief Checks if the trusted message port of a remote application is registered.
@@ -117,8 +110,9 @@ EXPORT_API int messageport_check_remote_port(const char* remote_app_id, const ch
  * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
  * @retval #MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH The remote application is not signed with the same certificate
  * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
+ * @retval #MESSAGEPORT_ERROR_RESOURCE_UNAVAILABLE Resource temporarily unavailable
  */
-EXPORT_API int messageport_check_trusted_remote_port(const char* remote_app_id, const char *remote_port, bool* exist);
+ int messageport_check_trusted_remote_port(const char *remote_app_id, const char *remote_port, bool *exist);
 
 /**
  * @brief Sends a message to the message port of a remote application.
@@ -133,6 +127,7 @@ EXPORT_API int messageport_check_trusted_remote_port(const char* remote_app_id,
  * @retval #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The message port of the remote application is not found
  * @retval #MESSAGEPORT_ERROR_MAX_EXCEEDED The size of message has exceeded the maximum limit
  * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
+ * @retval #MESSAGEPORT_ERROR_RESOURCE_UNAVAILABLE Resource temporarily unavailable
  *
  * @code
  * #include <message-port.h>
@@ -146,7 +141,7 @@ EXPORT_API int messageport_check_trusted_remote_port(const char* remote_app_id,
  * bundle_free(b);
  * @endcode
  */
-EXPORT_API int messageport_send_message(const char* remote_app_id, const char* remote_port, bundle* message);
+ int messageport_send_message(const char *remote_app_id, const char *remote_port, bundle *message);
 
 /**
  * @brief Sends a trusted message to the message port of a remote application. @n
@@ -163,8 +158,9 @@ EXPORT_API int messageport_send_message(const char* remote_app_id, const char* r
  * @retval #MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH The remote application is not signed with the same certificate
  * @retval #MESSAGEPORT_ERROR_MAX_EXCEEDED The size of message has exceeded the maximum limit
  * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
+ * @retval #MESSAGEPORT_ERROR_RESOURCE_UNAVAILABLE Resource temporarily unavailable
  */
-EXPORT_API int messageport_send_trusted_message(const char* remote_app_id, const char* remote_port, bundle* message);
+ int messageport_send_trusted_message(const char *remote_app_id, const char *remote_port, bundle *message);
 
 /**
  * @brief Sends a message to the message port of a remote application. This method is used for the bidirectional communication.
@@ -180,6 +176,7 @@ EXPORT_API int messageport_send_trusted_message(const char* remote_app_id, const
  * @retval #MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND The message port of the remote application is not found
  * @retval #MESSAGEPORT_ERROR_MAX_EXCEEDED The size of message has exceeded the maximum limit
  * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
+ * @retval #MESSAGEPORT_ERROR_RESOURCE_UNAVAILABLE Resource temporarily unavailable
  *
  * @code
  * #include <message-port.h>
@@ -202,7 +199,7 @@ EXPORT_API int messageport_send_trusted_message(const char* remote_app_id, const
  *   bundle_free(b);
  * }
  */
-EXPORT_API int messageport_send_bidirectional_message(int id, const char* remote_app_id, const char* remote_port, bundle* data);
+ int messageport_send_bidirectional_message(int id, const char *remote_app_id, const char *remote_port, bundle *data);
 
 /**
  * @brief Sends a trusted message to the message port of a remote application. This method is used for the bidirectional communication.
@@ -220,34 +217,9 @@ EXPORT_API int messageport_send_bidirectional_message(int id, const char* remote
  * @retval #MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH The remote application is not signed with the same certificate
  * @retval #MESSAGEPORT_ERROR_MAX_EXCEEDED The size of message has exceeded the maximum limit
  * @retval #MESSAGEPORT_ERROR_IO_ERROR Internal I/O error
+ * @retval #MESSAGEPORT_ERROR_RESOURCE_UNAVAILABLE Resource temporarily unavailable
  */
-EXPORT_API int messageport_send_bidirectional_trusted_message(int id, const char* remote_app_id, const char* remote_port, bundle* data);
-
-
-/**
- * @brief Gets the name of the local message port.
- *
- * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
- * @param [out] name The name of the local message port
- * @return 0 on success, otherwise a negative error value.
- * @retval #MESSAGEPORT_ERROR_NONE Successful
- * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
- * @remarks @a name must be released with free() by you
- */
-EXPORT_API int messageport_get_local_port_name(int id, char **name);
-
-/**
- * @brief Checks if the local message port is trusted.
- *
- * @param [in] id The message port id returned by messageport_register_local_port() or messageport_register_trusted_local_port()
- * @param [out] @c true if the local message port is trusted
- * @return 0 on success, otherwise a negative error value.
- * @retval #MESSAGEPORT_ERROR_NONE Successful
- * @retval #MESSAGEPORT_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #MESSAGEPORT_ERROR_OUT_OF_MEMORY Out of memory
- */
-EXPORT_API int messageport_check_trusted_local_port(int id, bool *trusted);
+ int messageport_send_bidirectional_trusted_message(int id, const char *remote_app_id, const char *remote_port, bundle *data);
 
 /**
  * @}