diff options
author | Krzysztof Wieclaw <k.wieclaw@samsung.com> | 2018-10-09 14:32:11 +0200 |
---|---|---|
committer | Krzysztof Wieclaw <k.wieclaw@samsung.com> | 2018-10-23 13:36:31 +0200 |
commit | a26e3b199ba0b8aef41c353e810d0191f1c0cb3b (patch) | |
tree | 5cfdbd0741e87e067b0e9b5bf2ee6e815d1ff5a7 | |
parent | eebc52020e469868ecd0a3360ae4fe81aa8e9c0c (diff) | |
download | gear-racing-car-a26e3b199ba0b8aef41c353e810d0191f1c0cb3b.tar.gz gear-racing-car-a26e3b199ba0b8aef41c353e810d0191f1c0cb3b.tar.bz2 gear-racing-car-a26e3b199ba0b8aef41c353e810d0191f1c0cb3b.zip |
Ported user name message
Change-Id: I5dd7462bcb6ca9f6dab2fd6b314903520f7c23d3
Signed-off-by: Krzysztof Wieclaw <k.wieclaw@samsung.com>
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | inc/messages/message.h | 3 | ||||
-rw-r--r-- | inc/messages/message_config_user_name.h | 81 | ||||
-rw-r--r-- | src/messages/message_config_user_name.c | 94 | ||||
-rw-r--r-- | src/messages/message_factory.c | 5 |
5 files changed, 183 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index dd6c623..b8d3eb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") INCLUDE_DIRECTORIES(${PROJECT_ROOT_DIR}/inc) ADD_EXECUTABLE(${PROJECT_NAME} + ${PROJECT_ROOT_DIR}/src/messages/message_config_user_name.c ${PROJECT_ROOT_DIR}/src/messages/clock.c ${PROJECT_ROOT_DIR}/src/messages/message_command.c ${PROJECT_ROOT_DIR}/src/messages/message_factory.c diff --git a/inc/messages/message.h b/inc/messages/message.h index d4a2d96..2cf653e 100644 --- a/inc/messages/message.h +++ b/inc/messages/message.h @@ -31,7 +31,8 @@ typedef enum message_type { MESSAGE_KEEP_ALIVE, /** Keep alive request */ MESSAGE_ACK, /** Message delivery confirmation */ MESSAGE_COMMAND, /** Message with command data */ - MESSAGE_BYE /** Connection end request */ + MESSAGE_BYE, /** Connection end request */ + MESSAGE_CONFIG_USER_NAME /** User name to be set */ } message_type_e; #define IP_ADDRESS_LEN 15 diff --git a/inc/messages/message_config_user_name.h b/inc/messages/message_config_user_name.h new file mode 100644 index 0000000..d8ddd93 --- /dev/null +++ b/inc/messages/message_config_user_name.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * 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 MESSAGE_CONFIG_USER_NAME_H +#define MESSAGE_CONFIG_USER_NAME_H + +#include "messages/message.h" + +/** + * @brief Config user name message data + */ +typedef struct message_config_user_name { + message_t base; /** Base class */ + char *user_name; /** User name */ +} message_config_user_name_t; + +/** + * @brief Initializes message_config_user_name_t object. + * + * @param[in] message config user name message. + */ +void message_config_user_name_init(message_config_user_name_t *message); + +/** + * @brief Get name from mesage. + * + * @param[in] message config user name message. + * + * @return Const pointer to name. + */ +const char *message_config_user_name_get_name(message_config_user_name_t *message); + +/** + * @brief Set name for message. + * + * @param[in] message config user name message. + * @param[in] name name to be set. + */ +void message_config_user_name_set_name(message_config_user_name_t *message, const char *name); + +/** + * @brief Destroys message_config_user_name_t object. + * + * @param[in] message message. + */ +void message_config_user_name_destroy(message_config_user_name_t *message); + +/** + * @brief Deserializes message_config_user_name_t from reader's buffer. + * + * @param[in] message config user name message. + * @param[in] reader reader object. + * + * @return 0 on success, other value on failure. + */ +int message_config_user_name_deserialize(message_config_user_name_t *message, reader_t *reader); + +/** + * @brief Serializes message_config_user_name_t into writer's buffer. + * + * @param[in] message config user name message. + * @param[in] writer writer object. + * + * @return 0 on success, other value on failure. + */ +int message_config_user_name_serialize(message_config_user_name_t *message, writer_t *writer); + +#endif /* end of include guard: MESSAGE_CONFIG_USER_NAME_H */ diff --git a/src/messages/message_config_user_name.c b/src/messages/message_config_user_name.c new file mode 100644 index 0000000..49b2728 --- /dev/null +++ b/src/messages/message_config_user_name.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * 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 MESSAGE_CONFIG_USER_NAME_C +#define MESSAGE_CONFIG_USER_NAME_C + +#include "messages/message_config_user_name.h" + +#include <string.h> +#include "messages/macros.h" + +static int _message_config_user_name_serialze_vcall(message_t *msg, writer_t *writer) +{ + message_config_user_name_t *command_msg = container_of(msg, message_config_user_name_t, base); + return message_config_user_name_serialize(command_msg, writer); +} + +static int _message_config_user_name_deserialize_vcall(message_t *msg, reader_t *reader) +{ + message_config_user_name_t *command_msg = container_of(msg, message_config_user_name_t, base); + return message_config_user_name_deserialize(command_msg, reader); +} + +static void _message_config_user_name_destroy_vcall(message_t *msg) +{ + message_config_user_name_t *command_msg = container_of(msg, message_config_user_name_t, base); + message_config_user_name_destroy(command_msg); +} + +void message_config_user_name_init(message_config_user_name_t *message) +{ + message_base_init(&message->base); + + message_set_type(&message->base, MESSAGE_CONFIG_USER_NAME); + + message->base.vtable.serialize = _message_config_user_name_serialze_vcall; + message->base.vtable.deserialize = _message_config_user_name_deserialize_vcall; + message->base.vtable.destroy = _message_config_user_name_destroy_vcall; + + message->user_name = NULL; +} + +void message_config_user_name_destroy(message_config_user_name_t *message) +{ + free((void*)message->user_name); + message->user_name = NULL; + message_base_destroy(&message->base); +} + +int message_config_user_name_deserialize(message_config_user_name_t *message, reader_t *reader) +{ + int err = 0; + + err |= message_base_deserialize(&message->base, reader); + err |= reader_read_string(reader, &message->user_name); + + return err; +} + +int message_config_user_name_serialize(message_config_user_name_t *message, writer_t *writer) +{ + int err = 0; + + err |= message_base_serialize(&message->base, writer); + err |= writer_write_string(writer, message->user_name); + + return err; +} + +const char *message_config_user_name_get_name(message_config_user_name_t *message) +{ + return message->user_name; +} + +void message_config_user_name_set_name(message_config_user_name_t *message, const char *name) +{ + free((void*)message->user_name); + message->user_name = strdup(name); +} + +#endif /* end of include guard: MESSAGE_CONFIG_USER_NAME_C */ diff --git a/src/messages/message_factory.c b/src/messages/message_factory.c index 03ec278..0ca2638 100644 --- a/src/messages/message_factory.c +++ b/src/messages/message_factory.c @@ -25,6 +25,7 @@ #include "messages/message_connect_accepted.h" #include "messages/message_connect_refused.h" #include "messages/message_keep_alive.h" +#include "messages/message_config_user_name.h" struct _message_factory { union { @@ -35,6 +36,7 @@ struct _message_factory { message_connect_accepted_t connect_accepted; message_connect_refused_t connect_refused; message_keep_alive_t keep_alive; + message_config_user_name_t config_user_name; } messages; }; @@ -62,6 +64,9 @@ message_t *message_factory_create_message(message_factory_t *factory, message_ty case MESSAGE_BYE: message_bye_init(&factory->messages.bye); return &factory->messages.bye.base; + case MESSAGE_CONFIG_USER_NAME: + message_config_user_name_init(&factory->messages.config_user_name); + return &factory->messages.config_user_name.base; default: return NULL; } |