messages: implement protocol messages 67/189867/7
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Fri, 21 Sep 2018 08:32:56 +0000 (10:32 +0200)
committerKrzysztof Wieclaw <k.wieclaw@samsung.com>
Wed, 26 Sep 2018 15:40:24 +0000 (17:40 +0200)
Change-Id: Iacc7d111e8c0eef28271c168cd40af70f55af665

15 files changed:
inc/messages/macros.h [new file with mode: 0644]
inc/messages/message_ack.h [new file with mode: 0644]
inc/messages/message_bye.h [new file with mode: 0644]
inc/messages/message_command.h [new file with mode: 0644]
inc/messages/message_connect.h [new file with mode: 0644]
inc/messages/message_connect_accepted.h [new file with mode: 0644]
inc/messages/message_connect_refused.h [new file with mode: 0644]
inc/messages/message_keep_alive.h [new file with mode: 0644]
src/messages/message_ack.c [new file with mode: 0644]
src/messages/message_bye.c [new file with mode: 0644]
src/messages/message_command.c [new file with mode: 0644]
src/messages/message_connect.c [new file with mode: 0644]
src/messages/message_connect_accepted.c [new file with mode: 0644]
src/messages/message_connect_refused.c [new file with mode: 0644]
src/messages/message_keep_alive.c [new file with mode: 0644]

diff --git a/inc/messages/macros.h b/inc/messages/macros.h
new file mode 100644 (file)
index 0000000..6b5a9a1
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+
+#define container_of(ptr, type, member) ({                      \
+        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
+        (type *)( (char *)__mptr - offsetof(type,member) );})
diff --git a/inc/messages/message_ack.h b/inc/messages/message_ack.h
new file mode 100644 (file)
index 0000000..8d8c074
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+* 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_ACK_H
+#define MESSAGE_ACK_H
+
+#include "messages/message.h"
+
+/**
+ * @brief Ack message data
+ */
+typedef struct message_ack {
+       message_t base;       /** Base class */
+       int64_t ack_serial;   /** The serial of message which reception is confirmed */
+} message_ack_t;
+
+/**
+ * @brief Initializes message_ack_t object.
+ *
+ * @param[in] message ack message.
+ */
+void message_ack_init(message_ack_t *message);
+
+/**
+ * @brief initializes message_ack_t message form other message.
+ * The serial number returned by @message_ack_get_ack_serial will
+ * be set to @request's serial.
+ *
+ * @param[in] message ack message.
+ * @param[in] request the message which reception will be confirmed by
+ * message_ack_t.
+ */
+void message_ack_init_from_request(message_ack_t *message, message_t *request);
+
+/**
+ * @brief Gets serial number of confirmed message.
+ *
+ * @return the serial number.
+ */
+int64_t message_ack_get_ack_serial(message_ack_t *message);
+
+/**
+ * @brief Destroys message_ack_t object.
+ *
+ * @param[in] message ack message.
+ */
+void message_ack_destroy(message_ack_t *message);
+
+/**
+ * @brief Deserializes message_ack_t from reader's buffer.
+ *
+ * @param[in] message ack message.
+ * @param[in] reader reader object.
+ *
+ * @return 0 on success, other value on failure.
+ */
+int message_ack_deserialize(message_ack_t *message, reader_t *reader);
+
+/**
+ * @brief Serializes message_ack_t into writer's buffer.
+ *
+ * @param[in] message message object.
+ * @param[in] writer writer object.
+ *
+ * @return 0 on success, other value on failure.
+ */
+int message_ack_serialize(message_ack_t *message, writer_t *writer);
+
+#endif /* end of include guard: MESSAGE_ACK_H */
diff --git a/inc/messages/message_bye.h b/inc/messages/message_bye.h
new file mode 100644 (file)
index 0000000..1a9b55a
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * 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_BYE_H
+#define MESSAGE_BYE_H
+
+#include "messages/message.h"
+
+/**
+ * @brief Connect message data
+ */
+typedef struct message_bye {
+       message_t base; /** Base class */
+} message_bye_t;
+
+/**
+ * @brief Initializes message_bye_t object.
+ *
+ * @param[in] message ack message.
+ */
+void message_bye_init(message_bye_t *message);
+
+/**
+ * @brief Destroys message_bye_t object.
+ *
+ * @param[in] message ack message.
+ */
+void message_bye_destroy(message_bye_t *message);
+
+/**
+ * @brief Deserializes message_bye_t from reader's buffer.
+ *
+ * @param[in] message ack message.
+ * @param[in] reader reader object.
+ *
+ * @return 0 on success, other value on failure.
+ */
+int message_bye_deserialize(message_bye_t *message, reader_t *reader);
+
+/**
+ * @brief Serializes message_bye_t into writer's buffer.
+ *
+ * @param[in] message message object.
+ * @param[in] writer writer object.
+ *
+ * @return 0 on success, other value on failure.
+ */
+int message_bye_serialize(message_bye_t *message, writer_t *writer);
+
+#endif /* end of include guard: MESSAGE_BYE_H */
diff --git a/inc/messages/message_command.h b/inc/messages/message_command.h
new file mode 100644 (file)
index 0000000..b0b1489
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * 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_COMMAND_H
+#define MESSAGE_COMMAND_H
+
+#include "command.h"
+#include "messages/message.h"
+
+/**
+ * @brief Command message data
+ */
+typedef struct message_command {
+       message_t base;    /** Base class */
+       command_s command; /** Command carried by message */
+} message_command_t;
+
+/**
+ * @brief Initializes message_command_t object.
+ *
+ * @param[in] message ack message.
+ */
+void message_command_init(message_command_t *message);
+
+/**
+ * @brief Get command for mesage.
+ *
+ * @param[in] message ack message.
+ *
+ * @return command const pointer.
+ */
+const command_s *message_command_get_command(message_command_t *message);
+
+/**
+ * @brief Set command for mesage.
+ *
+ * @param[in] message ack message.
+ * @param[in] command command to be set.
+ */
+void message_command_set_command(message_command_t *message, const command_s *cmd);
+
+/**
+ * @brief Destroys message_command_t object.
+ *
+ * @param[in] message ack message.
+ */
+void message_command_destroy(message_command_t *message);
+
+/**
+ * @brief Deserializes message_command_t from reader's buffer.
+ *
+ * @param[in] message ack message.
+ * @param[in] reader reader object.
+ *
+ * @return 0 on success, other value on failure.
+ */
+int message_command_deserialize(message_command_t *message, reader_t *reader);
+
+/**
+ * @brief Serializes message_command_t into writer's buffer.
+ *
+ * @param[in] message message object.
+ * @param[in] writer writer object.
+ *
+ * @return 0 on success, other value on failure.
+ */
+int message_command_serialize(message_command_t *message, writer_t *writer);
+
+#endif /* end of include guard: MESSAGE_COMMAND_H */
diff --git a/inc/messages/message_connect.h b/inc/messages/message_connect.h
new file mode 100644 (file)
index 0000000..8c16d18
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * 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_CONNECT_H
+#define MESSAGE_CONNECT_H
+
+#include "messages/message.h"
+
+/**
+ * @brief Connect message data
+ */
+typedef struct message_connect {
+       message_t base; /** Base class */
+} message_connect_t;
+
+/**
+ * @brief Initializes message_connect_t object.
+ *
+ * @param[in] message ack message.
+ */
+void message_connect_init(message_connect_t *message);
+
+/**
+ * @brief Destroys message_connect_t object.
+ *
+ * @param[in] message ack message.
+ */
+void message_connect_destroy(message_connect_t *message);
+
+/**
+ * @brief Deserializes message_connect_t from reader's buffer.
+ *
+ * @param[in] message ack message.
+ * @param[in] reader reader object.
+ *
+ * @return 0 on success, other value on failure.
+ */
+int message_connect_deserialize(message_connect_t *message, reader_t *reader);
+
+/**
+ * @brief Serializes message_connect_t into writer's buffer.
+ *
+ * @param[in] message message object.
+ * @param[in] writer writer object.
+ *
+ * @return 0 on success, other value on failure.
+ */
+int message_connect_serialize(message_connect_t *message, writer_t *writer);
+
+#endif /* end of include guard: MESSAGE_CONNECT_H */
diff --git a/inc/messages/message_connect_accepted.h b/inc/messages/message_connect_accepted.h
new file mode 100644 (file)
index 0000000..069353f
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * 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_CONNECT_ACCEPTED_H
+#define MESSAGE_CONNECT_ACCEPTED_H
+
+#include "messages/message.h"
+
+/**
+ * @brief Connect accepted message data
+ */
+typedef struct message_connect_accepted {
+       message_t base; /** Base class */
+} message_connect_accepted_t;
+
+/**
+ * @brief Initializes message_connect_accepted_t object.
+ *
+ * @param[in] message ack message.
+ */
+void message_connect_accepted_init(message_connect_accepted_t *message);
+
+/**
+ * @brief Destroys message_connect_accepted_t object.
+ *
+ * @param[in] message ack message.
+ */
+void message_connect_accepted_destroy(message_connect_accepted_t *message);
+
+/**
+ * @brief Deserializes message_connect_accepted_t from reader's buffer.
+ *
+ * @param[in] message ack message.
+ * @param[in] reader reader object.
+ *
+ * @return 0 on success, other value on failure.
+ */
+int message_connect_accepted_deserialize(message_connect_accepted_t *message, reader_t *reader);
+
+/**
+ * @brief Serializes message_connect_accepted_t into writer's buffer.
+ *
+ * @param[in] message message object.
+ * @param[in] writer writer object.
+ *
+ * @return 0 on success, other value on failure.
+ */
+int message_connect_accepted_serialize(message_connect_accepted_t *message, writer_t *writer);
+
+#endif /* end of include guard: MESSAGE_CONNECT_ACCEPTED_H */
diff --git a/inc/messages/message_connect_refused.h b/inc/messages/message_connect_refused.h
new file mode 100644 (file)
index 0000000..38ccec4
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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_CONNECT_REFUSED_H
+#define MESSAGE_CONNECT_REFUSED_H
+
+#include "messages/message.h"
+
+/**
+ * @brief Connect refused message data
+ */
+typedef struct message_connect_refused {
+       message_t base; /** Base class */
+} message_connect_refused_t;
+
+/**
+ * @brief Initializes message_connect_refused_t object.
+ *
+ * @param[in] message ack message.
+ */
+void message_connect_refused_init(message_connect_refused_t *message);
+
+/**
+ * @brief Destroys message_connect_refused_t object.
+ *
+ * @param[in] message ack message.
+ */
+void message_connect_refused_destroy(message_connect_refused_t *message);
+
+/**
+ * @brief Deserializes message_connect_refused_t from reader's buffer.
+ *
+ * @param[in] message ack message.
+ * @param[in] reader reader object.
+ *
+ * @return 0 on success, other value on failure.
+ */
+int message_connect_refused_deserialize(message_connect_refused_t *message, reader_t *reader);
+
+/**
+ * @brief Serializes message_connect_refused_t into writer's buffer.
+ *
+ * @param[in] message message object.
+ * @param[in] writer writer object.
+ *
+ * @return 0 on success, other value on failure.
+ */
+int message_connect_refused_serialize(message_connect_refused_t *message, writer_t *writer);
+
+#endif /* end of include guard: MESSAGE_CONNECT_REFUSED_H */
+
diff --git a/inc/messages/message_keep_alive.h b/inc/messages/message_keep_alive.h
new file mode 100644 (file)
index 0000000..d3552ce
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * 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_KEEP_ALIVE_H
+#define MESSAGE_KEEP_ALIVE_H
+
+#include "messages/message.h"
+
+/**
+ * @brief Keep alive message data
+ */
+typedef struct message_keep_alive {
+       message_t base; /** Base class */
+} message_keep_alive_t;
+
+/**
+ * @brief Initializes message_keep_alive_t object.
+ *
+ * @param[in] message ack message.
+ */
+void message_keep_alive_init(message_keep_alive_t *message);
+
+/**
+ * @brief Destroys message_keep_alive_t object.
+ *
+ * @param[in] message ack message.
+ */
+void message_keep_alive_destroy(message_keep_alive_t *message);
+
+/**
+ * @brief Deserializes message_keep_alive_t from reader's buffer.
+ *
+ * @param[in] message ack message.
+ * @param[in] reader reader object.
+ *
+ * @return 0 on success, other value on failure.
+ */
+int message_keep_alive_deserialize(message_keep_alive_t *message, reader_t *reader);
+
+/**
+ * @brief Serializes message_keep_alive_t into writer's buffer.
+ *
+ * @param[in] message message object.
+ * @param[in] writer writer object.
+ *
+ * @return 0 on success, other value on failure.
+ */
+int message_keep_alive_serialize(message_keep_alive_t *message, writer_t *writer);
+
+#endif /* end of include guard: MESSAGE_KEEP_ALIVE_H */
+
diff --git a/src/messages/message_ack.c b/src/messages/message_ack.c
new file mode 100644 (file)
index 0000000..d81b4c9
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+
+#include "messages/message_ack.h"
+#include "messages/macros.h"
+
+static int _message_ack_serialze_vcall(message_t *msg, writer_t *writer)
+{
+       message_ack_t *ack_msg = container_of(msg, message_ack_t, base);
+       return message_ack_serialize(ack_msg, writer);
+}
+
+static int _message_ack_deserialize_vcall(message_t *msg, reader_t *reader)
+{
+       message_ack_t *ack_msg = container_of(msg, message_ack_t, base);
+       return message_ack_deserialize(ack_msg, reader);
+}
+
+static void _message_ack_destroy_vcall(message_t *msg)
+{
+       message_ack_t *ack_msg = container_of(msg, message_ack_t, base);
+       message_ack_destroy(ack_msg);
+}
+
+void message_ack_init(message_ack_t *message)
+{
+       message_base_init(&message->base);
+
+       message_set_type(&message->base, MESSAGE_ACK);
+
+       message->base.vtable.serialize = _message_ack_serialze_vcall;
+       message->base.vtable.deserialize = _message_ack_deserialize_vcall;
+       message->base.vtable.destroy = _message_ack_destroy_vcall;
+
+       message->ack_serial = -1; // ack_serial not set
+}
+
+void message_ack_init_from_request(message_ack_t *message, message_t *request)
+{
+       message_ack_init(message);
+
+       message->ack_serial = message_get_serial(request);
+}
+
+void message_ack_destroy(message_ack_t *message)
+{
+       message_base_destroy(&message->base);
+}
+
+int64_t message_ack_get_ack_serial(message_ack_t *message)
+{
+       return message->ack_serial;
+}
+
+int message_ack_deserialize(message_ack_t *message, reader_t *reader)
+{
+       int err = 0;
+
+       err |= message_base_deserialize(&message->base, reader);
+       err |= reader_read_int64(reader, &message->ack_serial);
+
+       return err;
+}
+
+int message_ack_serialize(message_ack_t *message, writer_t *writer)
+{
+       int err = 0;
+
+       err |= message_base_serialize(&message->base, writer);
+       err |= writer_write_int64(writer, message->ack_serial);
+
+       return err;
+}
diff --git a/src/messages/message_bye.c b/src/messages/message_bye.c
new file mode 100644 (file)
index 0000000..135a8fa
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+#include "messages/message_bye.h"
+
+void message_bye_init(message_bye_t *message)
+{
+       message_base_init(&message->base);
+       message_set_type(&message->base, MESSAGE_BYE);
+}
+
+void message_bye_destroy(message_bye_t *message)
+{
+       message_base_destroy(&message->base);
+}
+
+int message_bye_deserialize(message_bye_t *message, reader_t *reader)
+{
+       return message_base_deserialize(&message->base, reader);
+}
+
+int message_bye_serialize(message_bye_t *message, writer_t *writer)
+{
+       return message_base_serialize(&message->base, writer);
+}
diff --git a/src/messages/message_command.c b/src/messages/message_command.c
new file mode 100644 (file)
index 0000000..6fcf179
--- /dev/null
@@ -0,0 +1,192 @@
+/*
+ * 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_COMMAND_C
+#define MESSAGE_COMMAND_C
+
+#include <string.h>
+
+#include "messages/message_command.h"
+#include "messages/macros.h"
+
+static int _message_command_serialze_vcall(message_t *msg, writer_t *writer)
+{
+       message_command_t *command_msg = container_of(msg, message_command_t, base);
+       return message_command_serialize(command_msg, writer);
+}
+
+static int _message_command_deserialize_vcall(message_t *msg, reader_t *reader)
+{
+       message_command_t *command_msg = container_of(msg, message_command_t, base);
+       return message_command_deserialize(command_msg, reader);
+}
+
+static void _message_command_destroy_vcall(message_t *msg)
+{
+       message_command_t *command_msg = container_of(msg, message_command_t, base);
+       message_command_destroy(command_msg);
+}
+
+void message_command_init(message_command_t *message)
+{
+       message_base_init(&message->base);
+
+       message_set_type(&message->base, MESSAGE_COMMAND);
+
+       message->base.vtable.serialize = _message_command_serialze_vcall;
+       message->base.vtable.deserialize = _message_command_deserialize_vcall;
+       message->base.vtable.destroy = _message_command_destroy_vcall;
+
+       memset(&message->command, 0x0, sizeof(command_s));
+}
+
+void message_command_destroy(message_command_t *message)
+{
+       message_base_destroy(&message->base);
+}
+
+static int _camera_command_deserialize(command_s *cmd, reader_t *reader)
+{
+       int32_t elevation, azimuth;
+       int err = 0;
+
+       err |= reader_read_int32(reader, &elevation);
+       err |= reader_read_int32(reader, &azimuth);
+
+       if (err) return err;
+
+       cmd->data.camera_position.camera_elevation = elevation;
+       cmd->data.camera_position.camera_azimuth = azimuth;
+
+       return 0;
+}
+
+static int _drive_command_deserialize(command_s *cmd, reader_t *reader)
+{
+
+       int32_t speed, dir;
+       int err = 0;
+
+       err |= reader_read_int32(reader, &speed);
+       err |= reader_read_int32(reader, &dir);
+
+       if (err) return err;
+
+       cmd->data.steering.speed = speed;
+       cmd->data.steering.direction = dir;
+
+       return 0;
+}
+
+static int _command_deserialize(command_s *cmd, reader_t *reader)
+{
+       int32_t type;
+
+       if (reader_read_int32(reader, &type)) {
+               return -1;
+       }
+
+       cmd->type = type;
+
+       switch (type) {
+               case COMMAND_TYPE_DRIVE:
+                       return _drive_command_deserialize(cmd, reader);
+               case COMMAND_TYPE_CAMERA:
+                       return _camera_command_deserialize(cmd, reader);
+                       break;
+               case COMMAND_TYPE_NONE:
+                       return 0;
+               default:
+                       return -1;
+       }
+}
+
+static int _camera_command_serialize(command_s *cmd, writer_t *writer)
+{
+       int32_t elevation = cmd->data.camera_position.camera_elevation;
+       int32_t azimuth = cmd->data.camera_position.camera_azimuth;
+       int err = 0;
+
+       err |= writer_write_int32(writer, elevation);
+       err |= writer_write_int32(writer, azimuth);
+
+       return err;
+}
+
+static int _drive_command_serialize(command_s *cmd, writer_t *writer)
+{
+       int32_t speed = cmd->data.steering.speed;
+       int32_t dir = cmd->data.steering.direction;
+       int err = 0;
+
+       err |= writer_write_int32(writer, speed);
+       err |= writer_write_int32(writer, dir);
+
+       return err;
+}
+
+static int _command_serialize(command_s *cmd, writer_t *writer)
+{
+       int32_t type = cmd->type;
+
+       if (writer_write_int32(writer, type)) {
+               return -1;
+       }
+
+       switch (cmd->type) {
+               case COMMAND_TYPE_DRIVE:
+                       return _drive_command_serialize(cmd, writer);
+               case COMMAND_TYPE_CAMERA:
+                       return _camera_command_serialize(cmd, writer);
+                       break;
+               case COMMAND_TYPE_NONE:
+                       return 0;
+               default:
+                       return -1;
+       }
+}
+
+int message_command_deserialize(message_command_t *message, reader_t *reader)
+{
+       int err = 0;
+
+       err |= message_base_deserialize(&message->base, reader);
+       err |= _command_deserialize(&message->command, reader);
+
+       return err;
+}
+
+int message_command_serialize(message_command_t *message, writer_t *writer)
+{
+       int err = 0;
+
+       err |= message_base_serialize(&message->base, writer);
+       err |= _command_serialize(&message->command, writer);
+
+       return err;
+}
+
+const command_s *message_command_get_command(message_command_t *message)
+{
+       return &message->command;
+}
+
+void message_command_set_command(message_command_t *message, const command_s *cmd)
+{
+       memcpy(&message->command, cmd, sizeof(command_s));
+}
+
+#endif /* end of include guard: MESSAGE_COMMAND_C */
diff --git a/src/messages/message_connect.c b/src/messages/message_connect.c
new file mode 100644 (file)
index 0000000..935eb5e
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+#include "messages/message_connect.h"
+
+void message_connect_init(message_connect_t *message)
+{
+       message_base_init(&message->base);
+       message_set_type(&message->base, MESSAGE_CONNECT);
+}
+
+void message_connect_destroy(message_connect_t *message)
+{
+       message_base_destroy(&message->base);
+}
+
+int message_connect_deserialize(message_connect_t *message, reader_t *reader)
+{
+       return message_base_deserialize(&message->base, reader);
+}
+
+int message_connect_serialize(message_connect_t *message, writer_t *writer)
+{
+       return message_base_serialize(&message->base, writer);
+}
diff --git a/src/messages/message_connect_accepted.c b/src/messages/message_connect_accepted.c
new file mode 100644 (file)
index 0000000..81122c4
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+#include "messages/message_connect_accepted.h"
+
+void message_connect_accepted_init(message_connect_accepted_t *message)
+{
+       message_base_init(&message->base);
+       message_set_type(&message->base, MESSAGE_CONNECT_ACCEPTED);
+}
+
+void message_connect_accepted_destroy(message_connect_accepted_t *message)
+{
+       message_base_destroy(&message->base);
+}
+
+int message_connect_accepted_deserialize(message_connect_accepted_t *message, reader_t *reader)
+{
+       return message_base_deserialize(&message->base, reader);
+}
+
+int message_connect_accepted_serialize(message_connect_accepted_t *message, writer_t *writer)
+{
+       return message_base_serialize(&message->base, writer);
+}
+
diff --git a/src/messages/message_connect_refused.c b/src/messages/message_connect_refused.c
new file mode 100644 (file)
index 0000000..4406f69
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+#include "messages/message_connect_refused.h"
+
+void message_connect_refused_init(message_connect_refused_t *message)
+{
+       message_base_init(&message->base);
+       message_set_type(&message->base, MESSAGE_CONNECT_REFUSED);
+}
+
+void message_connect_refused_destroy(message_connect_refused_t *message)
+{
+       message_base_destroy(&message->base);
+}
+
+int message_connect_refused_deserialize(message_connect_refused_t *message, reader_t *reader)
+{
+       return message_base_deserialize(&message->base, reader);
+}
+
+int message_connect_refused_serialize(message_connect_refused_t *message, writer_t *writer)
+{
+       return message_base_serialize(&message->base, writer);
+}
diff --git a/src/messages/message_keep_alive.c b/src/messages/message_keep_alive.c
new file mode 100644 (file)
index 0000000..e64aef4
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+#include "messages/message_keep_alive.h"
+
+void message_keep_alive_init(message_keep_alive_t *message)
+{
+       message_base_init(&message->base);
+       message_set_type(&message->base, MESSAGE_KEEP_ALIVE);
+}
+
+void message_keep_alive_destroy(message_keep_alive_t *message)
+{
+       message_base_destroy(&message->base);
+}
+
+int message_keep_alive_deserialize(message_keep_alive_t *message, reader_t *reader)
+{
+       return message_base_deserialize(&message->base, reader);
+}
+
+int message_keep_alive_serialize(message_keep_alive_t *message, writer_t *writer)
+{
+       return message_base_serialize(&message->base, writer);
+}