pkg_check_modules(pkgs REQUIRED
glib-2.0
dlog
+ libsystemd-daemon
)
FOREACH(flag ${pkgs_CFLAGS})
CONNECTOR_DISCONNECTED
};
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] addr
+ * \param[in] is_sync
+ * \param[in] service_cb
+ * \param[in] data
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_server_create(const char *addr, int is_sync, int (*service_cb)(int fd, void *data), void *data);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] addr
+ * \param[in] is_sync
+ * \param[in] service_cb
+ * \param[in] data
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_client_create(const char *addr, int is_sync, int (*service_cb)(int fd, void *data), void *data);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] handle
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_server_destroy(int handle);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] handle
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_client_destroy(int handle);
/*!
* \brief Used to handling the changing event of connection status.
* These two functions can be work with com_core_thread series functions.
+ * \details N/A
+ * \remarks N/A
+ * \param[in] type
+ * \param[in] service_cb
+ * \param[in] data
+ * \return int
+ * \retval
+ * \sa
*/
extern int com_core_add_event_callback(enum com_core_event_type type, int (*service_cb)(int handle, void *data), void *data);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] type
+ * \param[in] service_cb
+ * \param[in] data
+ * \return void *
+ * \retval
+ * \sa
+ */
extern void *com_core_del_event_callback(enum com_core_event_type type, int (*service_cb)(int handle, void *data), void *data);
/*!
* \brief If the connection is lost, this recv function will call the disconnected callback.
+ * \details N/A
+ * \remarks N/A
+ * \param[in] handle
+ * \param[in] buffer
+ * \param[in] size
+ * \param[in] sender_pid
+ * \param[in] timeout
+ * \return int
+ * \retval
+ * \sa
*/
extern int com_core_recv(int handle, char *buffer, int size, int *sender_pid, double timeout);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] handle
+ * \param[in] buffer
+ * \param[in] size
+ * \param[in] timeout
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_send(int handle, const char *buffer, int size, double timeout);
#ifdef __cplusplus
COM_CORE_ROUTE_ERROR
};
+/*!
+ * \brief Add permanent path to route a packet
+ * \details N/A
+ * \remarks N/A
+ * \param[in] handle
+ * \param[in] address
+ * \param[in] to
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_packet_router_add_route(int handle, unsigned long address, int to);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] handle
+ * \param[in] address
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_packet_router_del_route(int handle, unsigned long address);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] handle
+ * \param[in] address
+ * \param[in] to
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_packet_router_update_route(int handle, unsigned long address, int to);
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] type
+ * \param[in] evt_cb
+ * \param[in] data
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_packet_router_add_event_callback(enum com_core_route_event_type type, int (*evt_cb)(int handle, void *data), void *data);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] type
+ * \param[in] evt_cb
+ * \param[in] data
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_packet_router_del_event_callback(enum com_core_route_event_type type, int (*evt_cb)(int handle, void *data), void *data);
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] sock
+ * \param[in] timeout
+ * \param[in] table
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_packet_router_server_init(const char *sock, double timeout, struct method *table);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] handle
+ * \return void *
+ * \retval
+ * \sa
+ */
extern void *com_core_packet_router_server_fini(int handle);
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] sock
+ * \param[in] timeout
+ * \param[in] table
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_packet_router_client_init(const char *sock, double timeout, struct method *table);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] handle
+ * \return void *
+ * \retval
+ * \sa
+ */
extern void *com_core_packet_router_client_fini(int handle);
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] handle
+ * \param[in] packet
+ * \param[in] timeout
+ * \param[in] recv_cb
+ * \param[in] data
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_packet_router_async_send(int handle, struct packet *packet, double timeout, int (*recv_cb)(pid_t pid, int handle, const struct packet *packet, void *data), void *data);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] handle
+ * \param[in] packet
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_packet_router_send_only(int handle, struct packet *packet);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] addr
+ * \param[in] packet
+ * \param[in] timeout
+ * \return struct packet *
+ * \retval
+ * \sa
+ */
extern struct packet *com_core_packet_router_oneshot_send(const char *addr, struct packet *packet, double timeout);
#ifdef __cplusplus
struct packet *(*handler)(pid_t pid, int handle, const struct packet *packet);
};
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] handle
+ * \param[in] packet
+ * \param[in] timeout
+ * \param[in] recv_cb
+ * \param[in] data
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_packet_async_send(int handle, struct packet *packet, double timeout, int (*recv_cb)(pid_t pid, int handle, const struct packet *packet, void *data), void *data);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] handle
+ * \param[in] packet
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_packet_send_only(int handle, struct packet *packet);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] addr
+ * \param[in] packet
+ * \param[in] timeout
+ * \return struct packet *
+ * \retval
+ * \sa
+ */
extern struct packet *com_core_packet_oneshot_send(const char *addr, struct packet *packet, double timeout);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] addr
+ * \param[in] is_sync
+ * \param[in] table
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_packet_client_init(const char *addr, int is_sync, struct method *table);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] handle
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_packet_client_fini(int handle);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] addr
+ * \param[in] table
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_packet_server_init(const char *addr, struct method *table);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] handle
+ * \return int
+ * \retval
+ * \sa
+ */
extern int com_core_packet_server_fini(int handle);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] flag
+ * \return void
+ * \sa
+ */
extern void com_core_packet_use_thread(int flag);
#ifdef __cplusplus
#define SECURE_LOGE LOGE
#endif
+#if !defined(SECURE_LOGW)
+#define SECURE_LOGW LOGW
+#endif
+
#if !defined(FLOG)
#define DbgPrint(format, arg...) SECURE_LOGD(format, ##arg)
#define ErrPrint(format, arg...) SECURE_LOGE(format, ##arg)
PACKET_FLAG_ERROR = 0xFF /*!< Invalid flag */
};
+/*!
+ * \brief Version of current protocol (packet)
+ */
#define PACKET_VERSION 2
+
+/*!
+ * \brief Maximum length of a command string
+ */
#define PACKET_MAX_CMD 24
+/*!
+ * \brief Create a packet
+ * \details N/A
+ * \remarks N/A
+ * \param[in] command
+ * \param[in] fmt
+ * \param[in] ...
+ * \return struct packet *
+ * \retval
+ * \sa packet_create_noack
+ * \sa packet_create_reply
+ * \sa packet_destroy
+ * \sa packet_type
+ */
extern struct packet *packet_create(const char *command, const char *fmt, ...);
+
+/*!
+ * \brief Create a packet which doesn't need reply
+ * \details N/A
+ * \remarks N/A
+ * \param[in] command
+ * \param[in] fmt
+ * \param[in] ...
+ * \return struct packet *
+ * \retval
+ * \sa packet_create
+ * \sa packet_create_reply
+ * \sa packet_destroy
+ * \sa packet_type
+ */
extern struct packet *packet_create_noack(const char *command, const char *fmt, ...);
+
+/*!
+ * \brief Create a reply packet
+ * \details
+ * This API related with packet_create function
+ * If the packet is created using packet_create_noack, this function will returns ERROR
+ * \remarks N/A
+ * \param[in] packet
+ * \param[in] fmt
+ * \param[in] ...
+ * \return struct packet *
+ * \retval
+ * \sa packet_create
+ * \sa packet_create_reply
+ * \sa packet_destroy
+ */
extern struct packet *packet_create_reply(const struct packet *packet, const char *fmt, ...);
+
+/*!
+ * \brief Parse the data from a packet
+ * \details
+ * parsed data will be destroyed if the packet is destroyed.
+ * \remarks N/A
+ * \param[in] packet
+ * \param[in] fmt Format string: s - string, i - integer, d - double
+ * \param[out] ... Lists of variables to get the address of each data.
+ * \return int
+ * \retval
+ * \sa packet_create
+ * \sa packet_create_reply
+ * \sa pcaket_create_noack
+ */
extern int packet_get(const struct packet *packet, const char *fmt, ...);
+
+/*!
+ * \brief Destroy a packet
+ * \details N/A
+ * \remarks N/A
+ * \param[in] packet
+ * \return int
+ * \retval
+ * \sa packet_create
+ * \sa packet_create_reply
+ * \sa packet_create_noack
+ */
extern int packet_destroy(struct packet *packet);
+
+/*!
+ * \brief Increase the reference count
+ * \details
+ * com_core_packet_send series functions will destroy the packet after it sends them
+ * If you want reuse the sent packet again, increase the reference count of a packet
+ * Then the packet will not be destroyed even though returns from the com_core_packet_send series functions
+ * \remarks N/A
+ * \param[in] packet
+ * \return struct packet *
+ * \retval
+ * \sa packet_unref
+ */
extern struct packet *packet_ref(struct packet *packet);
+
+/*!
+ * \brief Decrease the reference count
+ * \details
+ * If the reference count reaches to ZERO, the packet will be destroyed automatically.
+ * \remarks N/A
+ * \param[in] packet
+ * \return struct packet *
+ * \retval
+ * \sa packet_ref
+ */
extern struct packet *packet_unref(struct packet *packet);
+
+/*!
+ * \brief Get the payload.
+ * \details N/A
+ * \remarks N/A
+ * \param[in] packet
+ * \return void *
+ * \retval
+ */
extern const void * const packet_data(const struct packet *packet);
+
+/*!
+ * \brief Get the sequence number
+ * \details
+ * Sequence number is based on current clock time.
+ * Its uniq attribute will be kept if your system supports clock_get_time.
+ * \remarks N/A
+ * \param[in] packet
+ * \return double
+ * \retval 0 Invalid argument
+ * \retval sequence number
+ */
extern const double const packet_seq(const struct packet *packet);
+
+/*!
+ * \brief Get the type of packet
+ * \details N/A
+ * \remarks N/A
+ * \param[in] packet
+ * \return enum packet_type
+ * \retval PACKET_REQ Request packet
+ * \retval PACKET_ACK Reply packet
+ * \retval PACKET_REQ_NOACK Request packet but it doesn't requires reply packet
+ * \retval PACKET_ERROR Error, invalid argument.
+ * \sa packet_create
+ * \sa packet_create_noack
+ * \sa packet_create_reply
+ */
extern const enum packet_type const packet_type(const struct packet *packet);
+
+/*!
+ * \brief Get the packet flag
+ * \details
+ * Packet router process should concerns flag.
+ * If the packet flag'd _ROUTE, the server must has to route it by its address.
+ * So the router process should have routing table.
+ * And the router process should manage all address which are assigned to each procecss.
+ * \remarks
+ * Address and PID are different.
+ * \param[in] packet
+ * \return enum packet_flag
+ * \retval PACKET_FLAG_NOROUTE Default packet.
+ * \retval PACKET_FLAG_ROUTE Server process must has to route this packet before reach to its client.
+ * \sa packet_set_flag
+ */
extern const enum packet_flag const packet_flag(const struct packet *packet);
+
+/*!
+ * \brief Set the packet flag
+ * \details N/A
+ * \remarks N/A
+ * \param[in] packet
+ * \param[in] flag
+ * \return int
+ * \retval -EINVAL Invalid argument
+ * \retval 0 Successfully set new flag
+ * \sa packet_flag
+ */
extern int packet_set_flag(struct packet *packet, enum packet_flag flag);
+
+/*!
+ * \brief Get the source address of a packet
+ * \details N/A
+ * \remarks
+ * Address must has not to be ZERO it will be delat as an error case.
+ * \param[in] packet
+ * \return unsigned long
+ * \retval 0 Invalid argument
+ * \retval Address
+ * \sa packet_set_source
+ */
extern const unsigned long const packet_source(const struct packet *packet);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks
+ * Address must has not to be ZERO it will be delat as an error case.
+ * \param[in] packet
+ * \param[in] source
+ * \return int
+ * \retval
+ * \sa packet_source
+ */
extern int packet_set_source(struct packet *packet, unsigned long source);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks
+ * Address must has not to be ZERO it will be delat as an error case.
+ * \param[in] packet
+ * \return unsigned long
+ * \retval
+ * \sa packet_set_destination
+ */
extern const unsigned long const packet_destination(const struct packet *packet);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks
+ * Address must has not to be ZERO it will be delat as an error case.
+ * \param[in] packet
+ * \param[in] destination
+ * \return int
+ * \retval
+ * \sa packet_destination
+ */
extern int packet_set_destination(struct packet *packet, unsigned long destination);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] packet
+ * \param[in] mask
+ * \return int
+ * \retval
+ * \sa packet_mask
+ */
extern int packet_set_mask(struct packet *packet, unsigned long mask);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] packet
+ * \return unsigned long
+ * \retval
+ * \sa packet_set_mask
+ */
extern unsigned long packet_mask(const struct packet *packet);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] packet
+ * \return int
+ * \retval
+ * \sa packet_set_source
+ * \sa packet_set_destination
+ */
extern int packet_swap_address(struct packet *packet);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] packet
+ * \return int
+ * \retval
+ * \sa PACKET_VERSION
+ */
extern const int const packet_version(const struct packet *packet);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] packet
+ * \return int
+ * \retval
+ */
extern const int const packet_payload_size(const struct packet *packet);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] packet
+ * \return char *
+ * \retval
+ * \sa packet_create
+ * \sa packet_create_noack
+ */
extern const char * const packet_command(const const struct packet *packet);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \return int
+ * \retval
+ */
extern const int const packet_header_size(void);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] packet
+ * \return int
+ * \retval
+ */
extern const int const packet_size(const struct packet *packet);
+
+/*!
+ * \brief
+ * \details N/A
+ * \remarks N/A
+ * \param[in] packet
+ * \param[in] offset
+ * \param[in] data
+ * \param[in] size
+ * \return struct packet *
+ * \retval
+ */
extern struct packet *packet_build(struct packet *packet, int offset, void *data, int size);
#ifdef __cplusplus
#define COM_CORE_REMOTE_SCHEME_LEN (9)
/*
- * Create client connection
+ * sdlocal:///tmp/.socket.file => /tmp/.socket.file
+ */
+#define COM_CORE_SD_LOCAL_SCHEME "sdlocal://"
+#define COM_CORE_SD_LOCAL_SCHEME_LEN (10)
+
+/*!
+ * \brief Create client connection
+ * \details N/A
+ * \remarks N/A
+ * \param[in] peer
+ * \return int
+ * \retval
+ * \sa
*/
extern int secure_socket_create_client(const char *peer);
-/*
- * Create server connection
+/*!
+ * \brief Create server connection
+ * \details N/A
+ * \remarks N/A
+ * \param[in] peer
+ * \return int
+ * \retval
+ * \sa
*/
extern int secure_socket_create_server(const char *peer);
-/*
- * Get the raw handle to use it for non-blocking mode.
+/*!
+ * \brief Get the raw handle to use it for non-blocking mode.
+ * \details N/A
+ * \remarks N/A
+ * \param[in] server_handle
+ * \return int
+ * \retval
+ * \sa
*/
extern int secure_socket_get_connection_handle(int server_handle);
-/*
- * Send data to the connected peer.
+/*!
+ * \brief Send data to the connected peer.
+ * \details N/A
+ * \remarks N/A
+ * \param[in] conn
+ * \param[in] buffer
+ * \param[in] size
+ * \return int
+ * \retval
+ * \sa
*/
extern int secure_socket_send(int conn, const char *buffer, int size);
-/*
- * Recv data from the connected peer. and its PID value
+/*!
+ * \brief Recv data from the connected peer. and its PID value
+ * \details N/A
+ * \remarks N/A
+ * \param[in] connn
+ * \param[in] buffer
+ * \param[in] size
+ * \param[in] sender_pid
+ * \return int
+ * \retval
+ * \sa
*/
extern int secure_socket_recv(int conn, char *buffer, int size, int *sender_pid);
-/*
- * Destroy a connection
+/*!
+ * \brief Destroy a connection
+ * \details N/A
+ * \remarks N/A
+ * \param[in] conn
+ * \return int
+ * \retval
+ * \sa
*/
extern int secure_socket_destroy_handle(int conn);
<manifest>
- <request>
- <domain name="_" />
- </request>
+ <request>
+ <domain name="_"/>
+ </request>
</manifest>
Group: Base/IPC
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
-Source1001: libcom-core.manifest
+Source1001: %{name}.manifest
BuildRequires: cmake, gettext-tools, coreutils
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(libsystemd-daemon)
%description
Light-weight IPC supporting library for Tizen
#include <netinet/tcp.h>
#include <errno.h>
#include <stdlib.h>
+#include <systemd/sd-daemon.h>
#include <dlog.h>
return handle;
}
+static inline int create_systemd_socket(const char *peer, int port, struct sockaddr *addr)
+{
+ int handle = -1;
+ int cnt;
+
+ cnt = sd_listen_fds(0);
+ if (cnt > 1) {
+ ErrPrint("To many file descriptors are received on socket activation: %d\n", cnt);
+ } else if (cnt == 1) {
+ handle = SD_LISTEN_FDS_START + 0;
+ } else {
+ handle = create_inet_socket(peer, port, addr);
+ }
+
+ return handle;
+}
+
static inline int setup_unix_handle(int handle)
{
int on = 1;
vtable->create_socket = create_unix_socket;
vtable->setup_handle = setup_unix_handle;
+ } else if (!strncasecmp(peer, COM_CORE_SD_LOCAL_SCHEME, COM_CORE_SD_LOCAL_SCHEME_LEN)) {
+ vtable->type = (int)SCHEME_LOCAL;
+ peer += COM_CORE_SD_LOCAL_SCHEME_LEN;
+
+ addr = strdup(peer);
+ if (!addr) {
+ ErrPrint("Heap: %s\n", strerror(errno));
+ }
+
+ vtable->create_socket = create_systemd_socket;
+ vtable->setup_handle = setup_unix_handle;
} else if (!strncasecmp(peer, COM_CORE_REMOTE_SCHEME, COM_CORE_REMOTE_SCHEME_LEN)) {
register int len;
char *endptr;