This repository was archived by the owner on Sep 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrmw_node.cpp
More file actions
116 lines (96 loc) · 3.11 KB
/
rmw_node.cpp
File metadata and controls
116 lines (96 loc) · 3.11 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// 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 <rmw_embeddedrtps/config.h>
#include <rmw/allocators.h>
#include <rmw/error_handling.h>
#include <rmw/rmw.h>
#include "./types.hpp"
#ifdef __cplusplus
extern "C"
{
#endif
rmw_node_t *
rmw_create_node(
rmw_context_t * context,
const char * name,
const char * namespace_)
{
rmw_node_t * node_handle = NULL;
if (!name || strlen(name) == 0) {
RMW_SET_ERROR_MSG("name is null");
} else if (!namespace_ || strlen(namespace_) == 0) {
RMW_SET_ERROR_MSG("namespace is null");
} else if (!context) {
RMW_SET_ERROR_MSG("context is null");
} else {
rmw_ertps_mempool_item_t * memory_node = get_memory(&node_memory);
if (!memory_node) {
RMW_SET_ERROR_MSG("Not available memory node");
return NULL;
}
rmw_ertps_node_t * node_info = reinterpret_cast<rmw_ertps_node_t *>(memory_node->data);
node_info->context = context->impl;
node_handle = rmw_node_allocate();
if (!node_handle) {
RMW_SET_ERROR_MSG("failed to allocate rmw_node_t");
return NULL;
}
node_info->rmw_handle = node_handle;
node_handle->implementation_identifier = rmw_get_implementation_identifier();
node_handle->data = node_info;
node_handle->name = reinterpret_cast<const char *>(
rmw_allocate(sizeof(char) * (strlen(name) + 1)));
if (!node_handle->name) {
RMW_SET_ERROR_MSG("failed to allocate memory");
return NULL;
}
memcpy(const_cast<char *>(node_handle->name), name, strlen(name) + 1);
node_handle->namespace_ = reinterpret_cast<const char *>(
rmw_allocate(sizeof(char) * (strlen(namespace_) + 1)));
if (!node_handle->namespace_) {
RMW_SET_ERROR_MSG("failed to allocate memory");
return NULL;
}
memcpy(const_cast<char *>(node_handle->namespace_), namespace_, strlen(namespace_) + 1);
}
return node_handle;
}
rmw_ret_t rmw_destroy_node(
rmw_node_t * node)
{
(void) node;
RMW_SET_ERROR_MSG("Function not implemented");
return RMW_RET_UNSUPPORTED;
}
rmw_ret_t
rmw_node_assert_liveliness(
const rmw_node_t * node)
{
(void) node;
RMW_SET_ERROR_MSG("Function not implemented");
return RMW_RET_UNSUPPORTED;
}
const rmw_guard_condition_t *
rmw_node_get_graph_guard_condition(
const rmw_node_t * node)
{
rmw_ertps_node_t * custom_node = reinterpret_cast<rmw_ertps_node_t *>(node->data);
rmw_context_impl_t * context = custom_node->context;
rmw_guard_condition_t * graph_guard_condition =
&context->graph_guard_condition;
return graph_guard_condition;
}
#ifdef __cplusplus
}
#endif