From d9a174b95ac9e2d374883ec1bca7171289c1a607 Mon Sep 17 00:00:00 2001 From: YoungHun Kim Date: Thu, 13 Jul 2017 11:31:08 +0900 Subject: Split mused to muse-server, muse-core (common) and muse-client part * The files are only installed, which are mused rpm likewise before. - rpm2cpio mused-0.2.3-1.armv7l.rpm | cpio -ivdm ./opt/data/mused ./usr/bin/muse-server +./usr/lib/libmuse-client.so.0 +./usr/lib/libmuse-client.so.0.2.3 +./usr/lib/libmuse-core.so.0 +./usr/lib/libmuse-core.so.0.2.3 +./usr/lib/libmuse-server.so.0 +./usr/lib/libmuse-server.so.0.2.3 ./usr/lib/systemd/system/multi-user.target.wants/muse-server.service ./usr/lib/systemd/system/muse-server.path ./usr/lib/systemd/system/muse-server.service ./usr/lib/systemd/system/muse-server.socket ./usr/lib/systemd/system/sockets.target.wants/muse-server.socket ./usr/share/licenses/mused ./usr/share/licenses/mused/LICENSE.APLv2 ./var/log/mused - rpm2cpio mused-devel-0.2.3-1.armv7l.rpm | cpio -ivdm +./usr/include/media/muse_client.h ./usr/include/media/muse_core.h +./usr/include/media/muse_server.h +./usr/lib/libmuse-client.so +./usr/lib/libmuse-core.so +./usr/lib/libmuse-server.so +./usr/lib/pkgconfig/muse-client.pc +./usr/lib/pkgconfig/muse-core.pc +./usr/lib/pkgconfig/muse-server.pc * muse module (server side) can depend on the muse_server.h * The dlog macro is 'MUSED' Change-Id: I73ca889fe418468012799352a567a9fda3175158 --- client/CMakeLists.txt | 65 +++++++++++++++++ client/include/muse_client.h | 40 +++++++++++ client/muse-client.pc.in | 14 ++++ client/src/muse_client.c | 164 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 283 insertions(+) create mode 100644 client/CMakeLists.txt create mode 100644 client/include/muse_client.h create mode 100644 client/muse-client.pc.in create mode 100644 client/src/muse_client.c (limited to 'client') diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt new file mode 100644 index 0000000..0d35c24 --- /dev/null +++ b/client/CMakeLists.txt @@ -0,0 +1,65 @@ + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(fw_name "muse-client") + +PROJECT(${fw_name}) + +SET(CMAKE_INSTALL_PREFIX /usr) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +SET(INC_DIR include) +INCLUDE_DIRECTORIES(${INC_DIR}) + +SET(dependents "dlog glib-2.0 mm-common") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_name} REQUIRED ${dependents}) +FOREACH(flag ${${fw_name}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIE -fno-strict-aliasing -Werror -Wformat -Wextra") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-bounds -Wno-empty-body -Wno-ignored-qualifiers") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter -Wshadow -Wwrite-strings -Wswitch-default") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-but-set-parameter -Wno-unused-but-set-variable -Wno-unused-result") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DTIZEN_DEBUG") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") + +aux_source_directory(src CLI_SOURCES) +ADD_LIBRARY(${fw_name} SHARED ${CLI_SOURCES}) + +TARGET_LINK_LIBRARIES(${fw_name} muse-core ${${fw_name}_LDFLAGS}) + +SET_TARGET_PROPERTIES(${fw_name} + PROPERTIES + VERSION ${FULLVER} + SOVERSION ${MAJORVER} + CLEAN_DIRECT_OUTPUT 1 +) + +INSTALL(TARGETS ${fw_name} DESTINATION ${LIBDIR}) +INSTALL( + DIRECTORY ${INC_DIR}/ DESTINATION include/media + FILES_MATCHING + PATTERN "*_private.h" EXCLUDE + PATTERN "${INC_DIR}/*.h" + ) + +SET(PC_NAME ${fw_name}) +SET(PC_LDFLAGS -l${fw_name}) +SET(PC_CFLAGS -I\${includedir}/media) + +CONFIGURE_FILE( + ${fw_name}.pc.in + ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc + @ONLY +) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig) diff --git a/client/include/muse_client.h b/client/include/muse_client.h new file mode 100644 index 0000000..0471e1c --- /dev/null +++ b/client/include/muse_client.h @@ -0,0 +1,40 @@ +/* + * muse-client + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: YoungHun Kim + * + * 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 __MUSE_CLIENT_H__ +#define __MUSE_CLIENT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "muse_core.h" + +int muse_client_new(void); +int muse_client_new_data_ch(void); +int muse_client_ipc_push_data(int sock_fd, const char *data, int size, uint64_t data_id); +int muse_client_get_fd_id_value(int sock_fd); +bool muse_client_check_fd_id_value(int sock_fd, int sock_id); + +#ifdef __cplusplus +} +#endif +#endif /*__MUSE_CLIENT_H__*/ diff --git a/client/muse-client.pc.in b/client/muse-client.pc.in new file mode 100644 index 0000000..126920c --- /dev/null +++ b/client/muse-client.pc.in @@ -0,0 +1,14 @@ + +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=/usr +libdir=@LIBDIR@ +includedir=/usr/include/media + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} diff --git a/client/src/muse_client.c b/client/src/muse_client.c new file mode 100644 index 0000000..fba9b0c --- /dev/null +++ b/client/src/muse_client.c @@ -0,0 +1,164 @@ +/* + * muse-client + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: YoungHun Kim + * + * 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. + * + */ + +#include "muse_client.h" +#include "muse_core_internal.h" + +GMutex g_mutex; +GHashTable *g_table; +int g_table_id; + +const char *UDS_files[MUSE_CHANNEL_MAX] = {MUSE_SOCK_FILE0, MUSE_SOCK_FILE1}; + +static int _muse_client_new(muse_channel_e channel); +static void _muse_client_table_new(void); +static gpointer _muse_client_get_fd_ptr(int sock_fd); + +static int _muse_client_new(muse_channel_e channel) +{ + struct sockaddr_un address; + int len, ret = MUSE_ERR; + int sockfd; + char err_msg[MUSE_MAX_MSG_LEN] = {'\0',}; + + LOGI("Enter"); + g_return_val_if_fail(channel < MUSE_CHANNEL_MAX, MM_ERROR_INVALID_ARGUMENT); + + /*Create socket*/ + if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { + strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN); + LOGE("[socket failure] sock: %s", err_msg); + return ret; + } + LOGI("sockfd: %d", sockfd); + + if (fcntl(sockfd, F_SETFD, FD_CLOEXEC) < 0) { + strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN); + LOGE("unable to set on ctrls socket fd %d: %s", sockfd, err_msg); + close(sockfd); + return ret; + } + LOGD("fcntl"); + + memset(&address, 0, sizeof(address)); + address.sun_family = AF_UNIX; + strncpy(address.sun_path, UDS_files[channel], sizeof(address.sun_path)); + len = sizeof(address); + + if (muse_core_set_nonblocking(sockfd, false) != MM_ERROR_NONE) + LOGE("Error - fd (%d) set blocking", sockfd); + + if ((ret = connect(sockfd, (struct sockaddr *)&address, len)) < 0) { + strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN); + LOGE("[Critical Error] connect failure : %s", err_msg); + close(sockfd); + return ret; + } + + g_mutex_lock(&g_mutex); + + g_hash_table_insert(g_table, GINT_TO_POINTER(sockfd), GINT_TO_POINTER(g_table_id++)); + + g_mutex_unlock(&g_mutex); + + LOGI("Leave"); + return sockfd; +} + +static void _muse_client_table_new(void) +{ + g_mutex_lock(&g_mutex); + + if (!g_table) { + g_table_id = 1; + g_table = g_hash_table_new(g_direct_hash, g_direct_equal); + LOGD("client table : %p", g_table); + } + + g_mutex_unlock(&g_mutex); +} + +static gpointer _muse_client_get_fd_ptr(int sock_fd) +{ + g_return_val_if_fail(g_table, NULL); + + return g_hash_table_lookup(g_table, GINT_TO_POINTER(sock_fd)); +} + +int muse_client_new(void) +{ + _muse_client_table_new(); + return _muse_client_new(MUSE_CHANNEL_MSG); +} + +int muse_client_new_data_ch(void) +{ + return _muse_client_new(MUSE_CHANNEL_DATA); +} + +int muse_client_ipc_push_data(int sock_fd, const char *data, int size, uint64_t data_id) +{ + char err_msg[MUSE_MAX_MSG_LEN] = {'\0',}; + muse_recv_data_head_t header; + int sended_len = 0; + + g_return_val_if_fail(data, MM_ERROR_INVALID_ARGUMENT); + + header.marker = MUSE_DATA_HEAD; + header.size = size; + header.id = data_id; + + LOGD("[%d] header.marker : %x header.size : %d header.id : %"G_GUINT64_FORMAT"", + sock_fd, header.marker, header.size, header.id); + + if ((sended_len = send(sock_fd, &header, sizeof(muse_recv_data_head_t), 0)) < 0) { + strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN); + LOGE("[%d] fail to send msg (%s) %d", sock_fd, err_msg, errno); + } + + if ((sended_len += send(sock_fd, data, size, 0)) < 0) { + strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN); + LOGE("[%d] fail to send msg (%s) %d", sock_fd, err_msg, errno); + } + + return sended_len; +} + +int muse_client_get_fd_id_value(int sock_fd) +{ + gpointer sock_id_ptr = _muse_client_get_fd_ptr(sock_fd); + + g_return_val_if_fail(sock_id_ptr, MUSE_ERR); + + return GPOINTER_TO_INT(sock_id_ptr); +} + +bool muse_client_check_fd_id_value(int sock_fd, int sock_id) +{ + gpointer sock_id_ptr = _muse_client_get_fd_ptr(sock_fd); + + g_return_val_if_fail(sock_id_ptr, false); + + if (sock_id == GPOINTER_TO_INT(sock_id_ptr)) + return true; + else + return false; +} -- cgit v1.2.3