2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "messages/message_factory.h"
21 #include "messages/message_ack.h"
22 #include "messages/message_bye.h"
23 #include "messages/message_command.h"
24 #include "messages/message_connect.h"
25 #include "messages/message_connect_accepted.h"
26 #include "messages/message_connect_refused.h"
27 #include "messages/message_keep_alive.h"
29 struct _message_factory {
33 message_command_t command;
34 message_connect_t connect;
35 message_connect_accepted_t connect_accepted;
36 message_connect_refused_t connect_refused;
37 message_keep_alive_t keep_alive;
41 message_t *message_factory_create_message(message_factory_t *factory, message_type_e type)
45 message_connect_init(&factory->messages.connect);
46 return &factory->messages.connect.base;
47 case MESSAGE_CONNECT_ACCEPTED:
48 message_connect_accepted_init(&factory->messages.connect_accepted);
49 return &factory->messages.connect_accepted.base;
50 case MESSAGE_CONNECT_REFUSED:
51 message_connect_refused_init(&factory->messages.connect_refused);
52 return &factory->messages.connect_refused.base;
53 case MESSAGE_KEEP_ALIVE:
54 message_keep_alive_init(&factory->messages.keep_alive);
55 return &factory->messages.keep_alive.base;
57 message_ack_init(&factory->messages.ack);
58 return &factory->messages.ack.base;
60 message_command_init(&factory->messages.command);
61 return &factory->messages.command.base;
63 message_bye_init(&factory->messages.bye);
64 return &factory->messages.bye.base;
70 message_factory_t *message_factory_create()
72 return malloc(sizeof(message_factory_t));
75 void message_factory_destroy(message_factory_t *factory)