1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "app_manager.h"
#include "app_manager_host.h"
#include "event.h"
#include "bi-inc/attr_container.h"
#include "coap_ext.h"
#if 0
bool send_coap_packet_to_host(coap_packet_t * packet)
{
int size;
uint8_t *buf;
size = coap_serialize_message_tcp(&packet, &buf);
if (!buf || size == 0)
return false;
app_manager_host_send_msg(buf, size);
APP_MGR_FREE(buf);
return true;
}
#endif
bool
send_request_to_host(request_t *msg)
{
if (COAP_EVENT == msg->action && !event_is_registered(msg->url)) {
app_manager_printf("Event is not registered\n");
return false;
}
int size;
char *packet = pack_request(msg, &size);
if (packet == NULL)
return false;
app_manager_host_send_msg(REQUEST_PACKET, packet, size);
free_req_resp_packet(packet);
return true;
}
bool
send_response_to_host(response_t *response)
{
int size;
char *packet = pack_response(response, &size);
if (packet == NULL)
return false;
app_manager_host_send_msg(RESPONSE_PACKET, packet, size);
free_req_resp_packet(packet);
return true;
}
bool
send_error_response_to_host(int mid, int status, const char *msg)
{
int payload_len = 0;
attr_container_t *payload = NULL;
response_t response[1] = { 0 };
if (msg) {
payload = attr_container_create("");
if (payload) {
attr_container_set_string(&payload, "error message", msg);
payload_len = attr_container_get_serialize_length(payload);
}
}
set_response(response, status, FMT_ATTR_CONTAINER, (const char *)payload,
payload_len);
response->mid = mid;
send_response_to_host(response);
if (payload)
attr_container_destroy(payload);
return true;
}
|