-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tomoya Fujita <[email protected]>
- Loading branch information
1 parent
f8b3563
commit f923c40
Showing
6 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2025 Sony Group Corporation. | ||
// | ||
// 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. | ||
|
||
#ifndef RMW__ENCLAVE_H_ | ||
#define RMW__ENCLAVE_H_ | ||
|
||
#include "rcutils/allocator.h" | ||
|
||
#include "rmw/macros.h" | ||
#include "rmw/ret_types.h" | ||
#include "rmw/visibility_control.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
/// Perform a deep copy of the enclave options from src into dst using the | ||
/// given allocator. | ||
/** | ||
* The dst will be left with an owned copy of the enclave whose | ||
* string values match the src. | ||
* If successful, src and dst will evaluate as equal. | ||
* | ||
* \param[in] src enclave options to be copied. | ||
* \param[in] allocator to use. | ||
* \param[out] dst Destination options to use. | ||
* \return RMW_RET_OK if success. | ||
* \return RMW_RET_INVALID_ARGUMENT if the src, dst or allocator is null. | ||
* \return RMW_RET_BAD_ALLOC if allocation fails. | ||
*/ | ||
RMW_PUBLIC | ||
RMW_WARN_UNUSED | ||
rmw_ret_t | ||
rmw_enclave_options_copy( | ||
const char * src, | ||
const rcutils_allocator_t * allocator, | ||
char ** dst); | ||
|
||
/// Destructor for enclave options | ||
/** | ||
* \param[in] enclave_options to destroy | ||
* \param[in] allocator to be used for destruction. | ||
* \return RMW_RET_OK if success. | ||
* \return RMW_RET_INVALID_ARGUMENT if allocator is invalid | ||
* or enclave_options is null. | ||
*/ | ||
RMW_PUBLIC | ||
rmw_ret_t | ||
rmw_enclave_options_fini( | ||
char * enclave_options, | ||
const rcutils_allocator_t * allocator | ||
); | ||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // RMW__ENCLAVE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2025 Sony Group Corporation. | ||
// | ||
// 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 <stddef.h> | ||
#include <string.h> | ||
|
||
#include "rcutils/allocator.h" | ||
#include "rcutils/strdup.h" | ||
|
||
#include "rmw/enclave.h" | ||
#include "rmw/error_handling.h" | ||
|
||
rmw_ret_t | ||
rmw_enclave_options_copy( | ||
const char * src, | ||
const rcutils_allocator_t * allocator, | ||
char ** dst) | ||
{ | ||
RMW_CHECK_ARGUMENT_FOR_NULL(src, RMW_RET_INVALID_ARGUMENT); | ||
RMW_CHECK_ARGUMENT_FOR_NULL(dst, RMW_RET_INVALID_ARGUMENT); | ||
RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); | ||
|
||
char * new_enclave = rcutils_strdup(src, *allocator); | ||
if (!new_enclave) { | ||
RMW_SET_ERROR_MSG("failed to copy enclave options"); | ||
return RMW_RET_BAD_ALLOC; | ||
} | ||
*dst = new_enclave; | ||
return RMW_RET_OK; | ||
} | ||
|
||
rmw_ret_t | ||
rmw_enclave_options_fini( | ||
char * enclave_options, | ||
const rcutils_allocator_t * allocator) | ||
{ | ||
RMW_CHECK_ARGUMENT_FOR_NULL(enclave_options, RMW_RET_INVALID_ARGUMENT); | ||
RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); | ||
|
||
allocator->deallocate(enclave_options, allocator->state); | ||
return RMW_RET_OK; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2025 Sony Group Corporation. | ||
// | ||
// 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 "gmock/gmock.h" | ||
|
||
#include "./time_bomb_allocator_testing_utils.h" | ||
#include "rmw/enclave.h" | ||
#include "rmw/error_handling.h" | ||
|
||
TEST(rmw_enclave_options, options_copy) { | ||
rcutils_allocator_t allocator = rcutils_get_default_allocator(); | ||
char * dst = nullptr; | ||
EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, rmw_enclave_options_copy(nullptr, &allocator, &dst)); | ||
rmw_reset_error(); | ||
|
||
EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, rmw_enclave_options_copy("src", nullptr, &dst)); | ||
rmw_reset_error(); | ||
|
||
EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, rmw_enclave_options_copy("src", &allocator, nullptr)); | ||
rmw_reset_error(); | ||
|
||
EXPECT_EQ(RMW_RET_OK, rmw_enclave_options_copy("src", &allocator, &dst)); | ||
EXPECT_STREQ(dst, "src"); | ||
EXPECT_EQ(RMW_RET_OK, rmw_enclave_options_fini(dst, &allocator)); | ||
} | ||
|
||
TEST(rmw_enclave_options, options_fini) { | ||
rcutils_allocator_t allocator = rcutils_get_default_allocator(); | ||
char * dst = nullptr; | ||
EXPECT_EQ(RMW_RET_OK, rmw_enclave_options_copy("src", &allocator, &dst)); | ||
EXPECT_STREQ(dst, "src"); | ||
|
||
EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, rmw_enclave_options_fini(nullptr, &allocator)); | ||
|
||
EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, rmw_enclave_options_fini(dst, nullptr)); | ||
|
||
EXPECT_EQ(RMW_RET_OK, rmw_enclave_options_fini(dst, &allocator)); | ||
} |