This patch is for protocol version 2.
Change-Id: Id4216a97ada075b80fc1c580c6f1809948c43d17
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
doc_ = std::shared_ptr<Document>(doc);
}
-std::shared_ptr<Document> Parser::GetDoc() {
+std::shared_ptr<Document> Parser::GetDoc() const {
return doc_;
}
ver_ = ver;
}
-int Parser::GetVersion() {
+int Parser::GetVersion() const {
return ver_;
}
error_ = true;
}
-bool Parser::IsBetaEnabled() {
+bool Parser::IsBetaEnabled() const {
return beta_enable_;
}
-bool Parser::IsCionEnabled() {
+bool Parser::IsCionEnabled() const {
return cion_enable_;
}
-bool Parser::IsAittEnabled() {
+bool Parser::IsAittEnabled() const {
return aitt_enable_;
}
-bool Parser::IsGroupEnabled() {
+bool Parser::IsGroupEnabled() const {
return group_enable_;
}
bool Parse(const std::string& input);
bool ParseFromFile(const std::string& path);
void SetDoc(Document* doc);
- std::shared_ptr<Document> GetDoc();
+ std::shared_ptr<Document> GetDoc() const;
void ReportError(const std::string& err, unsigned line);
- bool IsBetaEnabled();
- bool IsCionEnabled();
- bool IsAittEnabled();
- bool IsGroupEnabled();
+ bool IsBetaEnabled() const;
+ bool IsCionEnabled() const;
+ bool IsAittEnabled() const;
+ bool IsGroupEnabled() const;
void SetVersion(int ver);
- int GetVersion();
+ int GetVersion() const;
private:
void* scanner_;
void GenExplicitLinkageOpen(std::ofstream& stream);
void GenExplicitLinkageClose(std::ofstream& stream);
void GenStructureHandles(std::ofstream& stream);
- void GenStructures(std::ofstream& stream);
+ virtual void GenStructures(std::ofstream& stream);
private:
void GenStructureHandle(std::ofstream& stream, const Structure& st);
* limitations under the License.
*/
-#ifndef IDLC_GEN_VERSION2_C_BODY_GENERATOR_ARRAY_BASE_CB_H_
-#define IDLC_GEN_VERSION2_C_BODY_GENERATOR_ARRAY_BASE_CB_H_
+#ifndef IDLC_GEN_VERSION2_C_BODY_GENERATOR_ARRAY_BASE_CB_HH_
+#define IDLC_GEN_VERSION2_C_BODY_GENERATOR_ARRAY_BASE_CB_HH_
namespace tidl {
namespace version2 {
} // namespace version2
} // namespace tidl
-#endif // IDLC_GEN_VERSION2_C_BODY_GENERATOR_ARRAY_BASE_CB_H_
+#endif // IDLC_GEN_VERSION2_C_BODY_GENERATOR_ARRAY_BASE_CB_HH_
* limitations under the License.
*/
-#ifndef IDLC_GEN_VERSION2_C_BODY_GENERATOR_BASE_H_
-#define IDLC_GEN_VERSION2_C_BODY_GENERATOR_BASE_H_
+#ifndef IDLC_GEN_VERSION2_C_BODY_GENERATOR_BASE_HH_
+#define IDLC_GEN_VERSION2_C_BODY_GENERATOR_BASE_HH_
#include <memory>
#include <string>
} // namespace version2
} // namespace tidl
-#endif // IDLC_GEN_VERSION2_C_BODY_GENERATOR_BASE_H_
+#endif // IDLC_GEN_VERSION2_C_BODY_GENERATOR_BASE_HH_
* limitations under the License.
*/
-#ifndef IDLC_GEN_VERSION2_C_BODY_GENERATOR_LIST_BASE_CB_H_
-#define IDLC_GEN_VERSION2_C_BODY_GENERATOR_LIST_BASE_CB_H_
+#ifndef IDLC_GEN_VERSION2_C_BODY_GENERATOR_LIST_BASE_CB_HH_
+#define IDLC_GEN_VERSION2_C_BODY_GENERATOR_LIST_BASE_CB_HH_
namespace tidl {
namespace version2 {
} // namespace version2
} // namespace tidl
-#endif // IDLC_GEN_VERSION2_C_BODY_GENERATOR_LIST_BASE_CB_H_
+#endif // IDLC_GEN_VERSION2_C_BODY_GENERATOR_LIST_BASE_CB_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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 IDLC_GEN_VERSION2_C_HEADER_GENERATOR_ARRAY_BASE_CB_HH_
+#define IDLC_GEN_VERSION2_C_HEADER_GENERATOR_ARRAY_BASE_CB_HH_
+
+namespace tidl {
+namespace version2 {
+
+/**
+ * <PREFIX> The prefix of the array structure.
+ * <NAME> The name of the array structure.
+ * <PARAM_TYPE_IN> The type of the input parameter.
+ * <PARAM_TYPE_OUT> The type of the output parameter.
+ */
+constexpr const char CB_STRUCTURE_ARRAY_BASE[] =
+R"__c_cb(
+/**
+ * @briefs Creates a <PREFIX>_<NAME> handle.
+ *
+ * @remarks The @a h should be released using the <PREFIX>_<NAME>_destroy()
+ * if it's no longer needed.
+ * @param[out] h The <PREFIX>_<NAME> handle that is newly created
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see <PREFIX>_<NAME>_destroy()
+ */
+int <PREFIX>_<NAME>_create(<PREFIX>_<NAME>_h *h);
+
+/**
+ * @brief Destroys the <PREFIX>_<NAME> handle.
+ *
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see <PREFIX>_<NAME>_create()
+ */
+int <PREFIX>_<NAME>_destroy(<PREFIX>_<NAME>_h h);
+
+/**
+ * @brief Creates and returns a copy of the given <PREFIX>_<NAME> handle.
+ *
+ * @remarks A new created <PREFIX>_<NAME> should be released using
+ * the <PREFIX>_<NAME>_destroy() if it's no longer needed.
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @param[out] clone If successful, a new created <PREFIX>_<NAME> handle will be returned
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see <PREFIX>_<NAME>_destroy()
+ */
+int <PREFIX>_<NAME>_clone(<PREFIX>_<NAME>_h h, <PREFIX>_<NAME>_h *clone);
+
+/**
+ * @brief Sets the value to the <PREFIX>_<NAME> handle.
+ *
+ * @remarks The value is internally copied and stored.
+ * You should release it if it's allocaed when it's no longer needed,
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @param[in] value The array value
+ * @param[in] size The size of the array
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see <PREFIX>_<NAME>_get()
+ */
+int <PREFIX>_<NAME>_set(<PREFIX>_<NAME>_h h, <PARAM_TYPE_IN>*value, int size);
+
+/**
+ * @brief Gets the value from the <PREFIX>_<NAME> handle.
+ *
+ * @remarks A new created value should be released if it's no longer needed.
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @param[out] value The array value
+ * @param[out] size The size of the array
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see <PREFIX>_<NAME>_set()
+ */
+int <PREFIX>_<NAME>_get(<PREFIX>_<NAME>_h h, <PARAM_TYPE_OUT>*value, int *size);
+)__c_cb";
+
+} // namespace version2
+} // namespace tidl
+
+#endif // IDLC_GEN_VERSION2_C_HEADER_GENERATOR_ARRAY_BASE_CB_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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 "idlc/gen/version2/c_header_generator_base.hh"
+
+#include <string.h>
+
+#include <string>
+#include <vector>
+
+#include "idlc/gen/version2/c_header_generator_array_base_cb.hh"
+#include "idlc/gen/version2/c_header_generator_base_cb.hh"
+#include "idlc/gen/version2/c_header_generator_list_base_cb.hh"
+
+namespace tidl {
+namespace version2 {
+
+CHeaderGeneratorBase::CHeaderGeneratorBase(std::shared_ptr<Document> doc)
+ : tidl::CHeaderGeneratorBase(doc) {
+}
+
+void CHeaderGeneratorBase::GenStructures(std::ofstream& stream) {
+ for (auto& b : GetDocument().GetBlocks()) {
+ if (b->GetType() == Block::TYPE_STRUCTURE) {
+ auto& st = static_cast<const Structure&>(*b);
+ GenStructureBase(stream, st);
+ }
+ }
+
+ for (auto& i : GetStructures()) {
+ auto& st = i.second;
+ GenStructure(stream, *st);
+ }
+}
+
+void CHeaderGeneratorBase::GenStructureArrayBase(std::ofstream& stream,
+ const Structure& st) {
+ auto& elm = *(st.GetElements().begin());
+ auto& type = elm->GetType();
+ auto param_type_in = GetParamTypeString(ParameterType::Direction::IN, type);
+ auto param_type_out = GetParamTypeString(ParameterType::Direction::OUT, type);
+
+ ReplaceAll(CB_STRUCTURE_ARRAY_BASE)
+ .Change("<PREFIX>", GetHandlePrefix())
+ .Change("<NAME>", st.GetID())
+ .Change("<PARAM_TYPE_IN>", param_type_in)
+ .Change("<PARAM_TYPE_OUT>", param_type_out)
+ .Transform([&](std::string code) { return SmartIndent(code); })
+ .Out(stream);
+}
+
+void CHeaderGeneratorBase::GenStructureListBase(std::ofstream& stream,
+ const Structure& st) {
+ auto& elm = *(st.GetElements().begin());
+ auto& type = elm->GetType();
+ auto param_type = GetParamTypeString(ParameterType::Direction::IN, type);
+
+ ReplaceAll(CB_STRUCTURE_LIST_BASE)
+ .Change("<PREFIX>", GetHandlePrefix())
+ .Change("<NAME>", st.GetID())
+ .Change("<PARAM_TYPE_IN>", param_type)
+ .Transform([&](std::string code) { return SmartIndent(code); })
+ .Out(stream);
+}
+
+void CHeaderGeneratorBase::GenStructureMapBase(std::ofstream& stream,
+ const Structure& st) {
+}
+
+void CHeaderGeneratorBase::GenStructureSetBase(std::ofstream& stream,
+ const Structure& st) {
+}
+
+void CHeaderGeneratorBase::GenStructureBase(std::ofstream& stream,
+ const Structure& st) {
+ ReplaceAll(CB_STRUCTURE_BASE)
+ .Change("<PREFIX>", GetHandlePrefix())
+ .Change("<NAME>", st.GetID())
+ .Transform([&](std::string code) { return SmartIndent(code); })
+ .Out(stream);
+
+ for (const auto& e : st.GetElements()) {
+ auto& type = e->GetType();
+ auto param_type_in = GetParamTypeString(ParameterType::Direction::IN, type);
+ auto param_type_out = GetParamTypeString(ParameterType::Direction::OUT,
+ type);
+
+ ReplaceAll(CB_STRUCTURE_BASE_SET_GET)
+ .Change("<PREFIX>", GetHandlePrefix())
+ .Change("<NAME>", st.GetID())
+ .Change("<PARAM_TYPE_IN>", param_type_in)
+ .Change("<PARAM_TYPE_OUT>", param_type_out)
+ .Change("<ELEMENT_NAME>", e->GetID())
+ .Transform([&](std::string code) { return SmartIndent(code); })
+ .Out(stream);
+ }
+}
+
+void CHeaderGeneratorBase::GenStructure(std::ofstream& stream,
+ const Structure& st) {
+ if (st.GetID().compare(0, strlen("array"), "array") == 0)
+ GenStructureArrayBase(stream, st);
+ else if (st.GetID().compare(0, strlen("list"), "list") == 0)
+ GenStructureListBase(stream, st);
+ else if (st.GetID().compare(0, strlen("map"), "map") == 0)
+ GenStructureMapBase(stream, st);
+ else if (st.GetID().compare(0, strlen("set"), "set") == 0)
+ GenStructureSetBase(stream, st);
+ else
+ GenStructureBase(stream, st);
+}
+
+} // namespace version2
+} // namespace tidl
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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 IDLC_GEN_VERSION2_C_HEADER_GENERATOR_BASE_HH_
+#define IDLC_GEN_VERSION2_C_HEADER_GENERATOR_BASE_HH_
+
+#include <memory>
+
+#include "idlc/gen/c_header_gen_base.h"
+
+namespace tidl {
+namespace version2 {
+
+class CHeaderGeneratorBase : public tidl::CHeaderGeneratorBase {
+ public:
+ explicit CHeaderGeneratorBase(std::shared_ptr<Document> doc);
+ virtual ~CHeaderGeneratorBase() = default;
+
+ void GenStructures(std::ofstream& stream) override;
+
+ private:
+ void GenStructureArrayBase(std::ofstream& stream, const Structure& st);
+ void GenStructureListBase(std::ofstream& stream, const Structure& st);
+ void GenStructureMapBase(std::ofstream& stream, const Structure& st);
+ void GenStructureSetBase(std::ofstream& stream, const Structure& st);
+ void GenStructureBase(std::ofstream& stream, const Structure& st);
+ void GenStructure(std::ofstream& stream, const Structure& st);
+};
+
+} // namespace version2
+} // namespace tidl
+
+#endif // IDLC_GEN_VERSION2_C_HEADER_GENERATOR_BASE_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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 IDLC_GEN_VERSION2_C_HEADER_GENERATOR_BASE_CB_HH_
+#define IDLC_GEN_VERSION2_C_HEADER_GENERATOR_BASE_CB_HH_
+
+namespace tidl {
+namespace version2 {
+
+/**
+ * <PREFIX> The prefix of the structure. e.g. rpc_port_proxy_ or rpc_port_stub_
+ * <NAME> The name of the structure.
+ */
+constexpr const char CB_STRUCTURE_BASE[] =
+R"__c_cb(
+/**
+ * @brief Creates a <PREFIX>_<NAME> handle.
+ *
+ * @remarks The @a h handle should be released using the <PREFIX>_<NAME>_destroy()
+ * if it's no longer needed.
+ * @param[out] h The <PREFIX>_<NAME> handle that is newly created
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMTER Invaid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see <PREFIX>_<NAME>_destroy()
+ */
+int <PREFIX>_<NAME>_create(<PREFIX>_<NAME>_h *h);
+
+/**
+ * @brief Destroys the <PREFIX>_<NAME> handle.
+ *
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see <PREFIX>_<NAME>_create()
+ */
+int <PREFIX>_<NAME>_destroy(<PREFIX>_<NAME>_h h);
+
+/**
+ * @brief Creates and returns a copy of the given <PREFIX>_<NAME> handle.
+ *
+ * @remarks A new created <PREFIX>_<NAME> should be released using
+ * the <PREFIX>_<NAME>_destroy() if it's no longer needed.
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @param[out] clone If successful, a new created <PREFIX>_<NAME> handle will be returned
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see <PREFIX>_<NAME>_destroy()
+ */
+int <PREFIX>_<NAME>_clone(<PREFIX>_<NAME>_h h, <PREFIX>_<NAME>_h *clone);
+)__c_cb";
+
+/**
+ * <PREFIX> The prefix of the structure. e.g. rpc_port_proxy_ or rpc_port_stub_
+ * <NAME> The name of the structure.
+ * <PARAM_TYPE_IN> The type of the input parameter.
+ * <PARAM_TYPE_OUT> The type of the output parameter.
+ * <ELEMENT_NAME> The name of the element of the structure.
+ */
+constexpr const char CB_STRUCTURE_BASE_SET_GET[] =
+R"__c_cb(
+/**
+ * @brief Sets the <ELEMENT_NAME> to the <PREFIX>_<NAME> handle.
+ *
+ * @remarks The <ELEMENT_NAME> is internally copied and stored.
+ * You should release it if it's allocated when it's no longer needed.
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @param[in] value The <ELEMENT_NAME>
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see <PREFIX>_<NAME>_get_<ELEMENT_NAME>()
+ */
+int <PREFIX>_<NAME>_set_<ELEMENT_NAME>(<PREFIX>_<NAME>_h h, <PARAM_TYPE_IN>value);
+
+/**
+ * @brief Gets the <ELEMENT_NAME> from the <PREFIX>_<NAME> handle.
+ *
+ * @remarks A new created value should be released if it's allocated when it's no longer needed.
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @param[out] value The <ELEMENT_NAME>
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see <PREFIX>_<NAME>_set_<ELEMENT_NAME>
+ */
+int <PREFIX>_<NAME>_get_<ELEMENT_NAME>(<PREFIX>_<NAME>_h h, <PARAM_TYPE_OUT>value);
+)__c_cb";
+
+} // namespace version2
+} // namespace tidl
+
+#endif // IDLC_GEN_VERSION2_C_HEADER_GENERATOR_BASE_CB_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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 IDLC_GEN_VERSION2_C_HEADER_GENERATOR_LIST_BASE_CB_HH_
+#define IDLC_GEN_VERSION2_C_HEADER_GENERATOR_LIST_BASE_CB_HH_
+
+namespace tidl {
+namespace version2 {
+
+/**
+ * <PREFIX> The prefix of the list structure.
+ * <NAME> The name of the list structure.
+ * <PARAM_TYPE_IN> The type of the input parameter.
+ */
+constexpr const char CB_STRUCTURE_LIST_BASE[] =
+R"__c_cb(
+/**
+ * @brief Called to retrieve the value contained in the <PREFIX>_<NAME> handle.
+ *
+ * @remarks The @a value MUST NOT be released by the application.
+ * @param[in] value The value of the list
+ * @param[in] user_data The user data passed from the foreach function
+ * @return @c true to continue with the next iteration of the loop,
+ * otherwise @c false to break out of the loop
+ * @see <PREFIX>_<NAME>_foreach()
+ */
+typedef bool (*<PREFIX>_<NAME>_cb)(<PARAM_TYPE_IN>value, void *user_data);
+
+/**
+ * @brief Creates a <PREFIX>_<NAME> handle.
+ *
+ * @remarks The @a h handle should be released using the <PREFIX>_<NAME>_destroy()
+ * if it's no longer needed.
+ * @param[out] h The <PREFIX>_<NAME> handle that is newly created
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see <PREFIX>_<NAME>_destroy()
+ */
+int <PREFIX>_<NAME>_create(<PREFIX>_<NAME>_h *h);
+
+/**
+ * @brief Destroys the <PREFIX>_<NAME> handle.
+ *
+ * @param[in] The <PREFIX>_<NAME> handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see <PREFIX>_<NAME>_create()
+ */
+int <PREFIX>_<NAME>_destroy(<PREFIX>_<NAME>_h h);
+
+/**
+ * @brief Creates and returns a copy of the given <PREFIX>_<NAME> handle.
+ *
+ * @remarks A new created <PREFIX>_<NAME> should be released using
+ * the <PREFIX>_<NAME>_destroy() if it's no longer needed.
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @param[out] clone If successful, a new created <PREFIX>_<NAME> handle will be returned
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see <PREFIX>_<NAME>_destroy()
+ */
+int <PREFIX>_<NAME>_clone(<PREFIX>_<NAME>_h h, <PREFIX>_<NAME>_h *clone);
+
+/**
+ * @brief Adds the value to the <PREFIX>_<NAME> handle.
+ *
+ * @remarks The value is internally copied and stored.
+ * You should release it if it's allocaed when it's no longer needed,
+ * @param[in] h The <PREFIX>_<NAME> handle.
+ * @param[in] value The value
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see <PREFIX>_<NAME>_remove()
+ */
+int <PREFIX>_<NAME>_add(<PREFIX>_<NAME>_h h, <PARAM_TYPE_IN>value);
+
+/**
+ * @brief Retrieves all values contained in the <PREFIX>_<NAME> handle.
+ * @details This function called <PREFIX>_<NAME>_cb once for each value contained in the <PREFIX>_<NAME> handle.
+ * If the <PREFIX>_<NAME>_cb callback function returns @c false, the iteration will be finished.
+ *
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @param[in] callback The iteration callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see <PREFIX>_<NAME>_cb()
+ */
+int <PREFIX>_<NAME>_foreach(<PREFIX>_<NAME>_h h, <PREFIX>_<NAME>_cb callback, void *user_data);
+
+/**
+ * @brief Removes the element at the given position in the <PREFIX>_<NAME> handle.
+ *
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @param[in] nth The position of the element
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int <PREFIX>_<NAME>_remove(<PREFIX>_<NAME>_h h, unsigned int nth);
+
+/**
+ * @brief Gets the number of elements in the <PREFIX>_<NAME> handle.
+ *
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @param[out] length The number of elements
+ * @return @c on 0 success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int <PREFIX>_<NAME>_length(<PREFIX>_<NAME>_h h, unsigned int *length);
+)__c_cb";
+
+} // namespace version2
+} // namespace tidl
+
+#endif // IDLC_GEN_VERSION2_C_HEADER_GENERATOR_LIST_BASE_CB_HH_
* limitations under the License.
*/
-#ifndef IDLC_GEN_VERSION2_C_PROXY_BODY_GENERATOR_CB_H_
-#define IDLC_GEN_VERSION2_C_PROXY_BODY_GENERATOR_CB_H_
+#ifndef IDLC_GEN_VERSION2_C_PROXY_BODY_GENERATOR_CB_HH_
+#define IDLC_GEN_VERSION2_C_PROXY_BODY_GENERATOR_CB_HH_
namespace tidl {
namespace version2 {
} // namespace version2
} // namespace tidl
-#endif // IDLC_GEN_VERSION2_C_PROXY_BODY_GENERATOR_CB_H_
+#endif // IDLC_GEN_VERSION2_C_PROXY_BODY_GENERATOR_CB_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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 "idlc/gen/version2/c_proxy_header_generator.hh"
+
+#include "idlc/gen/version2/c_proxy_header_generator_cb.hh"
+
+namespace tidl {
+namespace version2 {
+
+CProxyHeaderGenerator::CProxyHeaderGenerator(std::shared_ptr<Document> doc)
+ : CHeaderGeneratorBase(doc) {
+}
+
+void CProxyHeaderGenerator::OnInitGen(std::ofstream& stream) {
+ GenVersion(stream);
+ GenPragmaOnce(stream);
+ GenIncludeDefaultHeaders(stream, false);
+ GenExplicitLinkageOpen(stream);
+ GenStructureHandles(stream);
+ GenInterfaceHandles(stream);
+ GenStructures(stream);
+ GenInterfaces(stream);
+}
+
+void CProxyHeaderGenerator::OnFiniGen(std::ofstream& stream) {
+ GenExplicitLinkageClose(stream);
+}
+
+void CProxyHeaderGenerator::GenInterfaceHandles(std::ofstream& stream) {
+ for (auto& b : GetDocument().GetBlocks()) {
+ if (b->GetType() != Block::TYPE_INTERFACE)
+ continue;
+
+ auto& iface = static_cast<const Interface&>(*b);
+ GenInterfaceHandle(stream, iface);
+ for (const auto& d : iface.GetDeclarations()) {
+ if (d->GetMethodType() != Declaration::MethodType::DELEGATE)
+ continue;
+
+ GenInterfaceDelegateHandle(stream, iface, *d);
+ }
+ }
+}
+
+void CProxyHeaderGenerator::GenInterfaceHandle(std::ofstream& stream,
+ const Interface& iface) {
+ ReplaceAll(CB_INTERFACE_HANDLE)
+ .Change("<PREFIX>", GetHandlePrefix())
+ .Change("<NAME>", iface.GetID())
+ .Transform([&](std::string code) { return SmartIndent(code); })
+ .Out(stream);
+}
+
+void CProxyHeaderGenerator::GenInterfaceDelegateHandle(std::ofstream& stream,
+ const Interface& iface, const Declaration& decl) {
+ ReplaceAll(CB_INTERFACE_DELEGATE_HANDLE)
+ .Change("<PREFIX>", GetHandlePrefix())
+ .Change("<NAME>", iface.GetID())
+ .Change("<DELEGATE_NAME>", decl.GetID())
+ .Transform([&](std::string code) { return SmartIndent(code); })
+ .Out(stream);
+}
+
+void CProxyHeaderGenerator::GenInterfaces(std::ofstream& stream) {
+ for (auto& i : GetDocument().GetBlocks()) {
+ if (i->GetType() != Block::TYPE_INTERFACE)
+ continue;
+
+ const Interface &iface = static_cast<const Interface&>(*i);
+ GenInterface(stream, iface);
+ }
+}
+
+void CProxyHeaderGenerator::GenInterface(std::ofstream& stream,
+ const Interface& iface) {
+ for (const auto& d : iface.GetDeclarations()) {
+ if (d->GetMethodType() != Declaration::MethodType::DELEGATE)
+ continue;
+
+ GenInterfaceDelegateBase(stream, iface, *d);
+ }
+
+ GenInterfaceBase(stream, iface);
+
+ for (const auto& d : iface.GetDeclarations()) {
+ if (d->GetMethodType() == Declaration::MethodType::DELEGATE)
+ continue;
+
+ GenInterfaceMethodBase(stream, iface, *d);
+ }
+}
+
+void CProxyHeaderGenerator::GenInterfaceBase(std::ofstream& stream,
+ const Interface& iface) {
+ ReplaceAll(CB_INTERFACE_BASE)
+ .Change("<PREFIX>", GetHandlePrefix())
+ .Change("<NAME>", iface.GetID())
+ .Transform([&](std::string code) { return SmartIndent(code); })
+ .Out(stream);
+}
+
+std::string CProxyHeaderGenerator::GenDelegateParams(const Interface& iface,
+ const Declaration& decl) {
+ std::string params;
+ for (const auto& p : decl.GetParameters()) {
+ params += ", ";
+ auto& param_type = p->GetParameterType();
+ auto& type = param_type.GetBaseType();
+ params += GetParamTypeString(param_type.GetDirection(), type, iface) +
+ p->GetID();
+ }
+
+ return params;
+}
+
+void CProxyHeaderGenerator::GenInterfaceDelegateBase(std::ofstream& stream,
+ const Interface& iface, const Declaration& decl) {
+ ReplaceAll(CB_INTERFACE_DELEGATE_BASE)
+ .Change("<PREFIX>", GetHandlePrefix())
+ .Change("<NAME>", iface.GetID())
+ .Change("<DELEGATE_NAME>", decl.GetID())
+ .Change("<DELEGATE_PARAMS>", GenDelegateParams(iface, decl))
+ .Transform([&](std::string code) { return SmartIndent(code); })
+ .Out(stream);
+}
+
+std::string CProxyHeaderGenerator::GenMethodParams(const Interface& iface,
+ const Declaration& decl) {
+ std::string params;
+ for (const auto& p : decl.GetParameters()) {
+ params += ", ";
+ auto& param_type = p->GetParameterType();
+ auto& type = param_type.GetBaseType();
+ params += GetParamTypeString(param_type.GetDirection(), type, iface) +
+ p->GetID();
+ }
+
+ return params;
+}
+
+void CProxyHeaderGenerator::GenInterfaceMethodBase(std::ofstream& stream,
+ const Interface& iface, const Declaration& decl) {
+ ReplaceAll(CB_INTERFACE_METHOD_BASE)
+ .Change("<RETURN_TYPE>", GetReturnTypeString(decl.GetType()))
+ .Change("<PREFIX>", GetHandlePrefix())
+ .Change("<NAME>", iface.GetID())
+ .Change("<METHOD_NAME>", decl.GetID())
+ .Change("<METHOD_PARAMS>", GenMethodParams(iface, decl))
+ .Transform([&](std::string code) { return SmartIndent(code); })
+ .Out(stream);
+}
+
+} // namespace version2
+} // namespace tidl
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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 IDLC_GEN_VERSION2_C_PROXY_HEADER_GENERATOR_HH_
+#define IDLC_GEN_VERSION2_C_PROXY_HEADER_GENERATOR_HH_
+
+#include <memory>
+#include <string>
+
+#include "idlc/gen/version2/c_header_generator_base.hh"
+
+namespace tidl {
+namespace version2 {
+
+class CProxyHeaderGenerator : public CHeaderGeneratorBase {
+ public:
+ explicit CProxyHeaderGenerator(std::shared_ptr<Document> doc);
+ virtual ~CProxyHeaderGenerator() = default;
+
+ void OnInitGen(std::ofstream& stream) override;
+ void OnFiniGen(std::ofstream& stream) override;
+
+ private:
+ void GenInterfaceHandles(std::ofstream& stream);
+ void GenInterfaceHandle(std::ofstream& stream, const Interface& iface);
+ void GenInterfaceDelegateHandle(std::ofstream& stream, const Interface& iface,
+ const Declaration& decl);
+
+ void GenInterfaces(std::ofstream& stream);
+ void GenInterface(std::ofstream& stream, const Interface& iface);
+ void GenInterfaceDelegateBase(std::ofstream& stream, const Interface& iface,
+ const Declaration& decl);
+ void GenInterfaceBase(std::ofstream& stream, const Interface& iface);
+ void GenInterfaceMethodBase(std::ofstream& stream, const Interface& ifaceo,
+ const Declaration& decl);
+ std::string GenDelegateParams(const Interface& iface,
+ const Declaration& decl);
+ std::string GenMethodParams(const Interface& iface, const Declaration& decl);
+};
+
+} // namespace version2
+} // namespace tidl
+
+#endif // IDLC_GEN_VERSION2_C_PROXY_HEADER_GENERATOR_HH_
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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 IDLC_GEN_VERSION2_C_PROXY_HEADER_GENERATOR_CB_HH_
+#define IDLC_GEN_VERSION2_C_PROXY_HEADER_GENERATOR_CB_HH_
+
+namespace tidl {
+namespace version2 {
+
+/**
+ * <PREFIX> The prefix of the interface.
+ * <NAME> The name of the interface.
+ */
+constexpr const char CB_INTERFACE_HANDLE[] =
+R"__c_cb(
+/**
+ * @brief The <PREFIX>_<NAME> handle.
+ */
+typedef struct <PREFIX>_<NAME>_s *<PREFIX>_<NAME>_h;
+)__c_cb";
+
+constexpr const char CB_INTERFACE_DELEGATE_HANDLE[] =
+R"__c_cb(
+/**
+ * @brief The <PREFIX>_<NAME>_<DELEGATE_NAME> handle.
+ */
+typedef struct <PREFIX>_<NAME>_<DELEGATE_NAME>_s *<PREFIX>_<NAME>_<DELEGATE_NAME>_h;
+)__c_cb";
+
+/**
+ * <PREFIX> The prefix of the interface.
+ * <NAME> The name of the interface.
+ * <DELEGATE_NAME> The name of the delegate.
+ * <DELEGATE_PARAMS> The parameters of the callback function.
+ */
+constexpr const char CB_INTERFACE_DELEGATE_BASE[] =
+R"__c_cb(
+/**
+ * @brief Called when the event is received.
+ *
+ * @param[in] user_data The user data passed from the callback registration function
+ * @param[in] ...
+ *
+ * @see <PREFIX>_<NAME>_<DELEGATE_NAME>_create()
+ */
+typedef void (*<PREFIX>_<NAME>_<DELEGATE_NAME>_cb)(void *user_data<DELEGATE_PARAMS>);
+
+/**
+ * @brief Creates a <PREFIX>_<NAME>_<DELEGATE_NAME> handle.
+ *
+ * @param[out] h The <PREFIX>_<NAME>_<DELEGATE_NAME> handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memorya
+ * @see <PREFIX>_<NAME>_<DELEGATE_NAME>_destroy()
+ * @see <PREFIX>_<NAME>_<DELEGATE_NAME>_dispose()
+ * @see <PREFIX>_<NAME>_<DELEGATE_NAME>_set_callback()
+ * @see <PREFIX>_<NAME>_<DELEGATE_NAME>_set_once()
+ */
+int <PREFIX>_<NAME>_<DELEGATE_NAME>_create(<PREFIX>_<NAME>_<DELEGATE_NAME>_h *h);
+
+/**
+ * @brief Destroys the <PREFIX>_<NAME>_<DELEGATE_NAME> handle.
+ *
+ * @param[in] h The <PREFIX>_<NAME>_<DELEGATE_NAME> handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see <PREFIX>_<NAME>_<DELEGATE_NAME>_create()
+ */
+int <PREFIX>_<NAME>_<DELEGATE_NAME>_destroy(<PREFIX>_<NAME>_<DELEGATE_NAME>_h h);
+
+/**
+ * @brief Creates and returns a copy of the given <PREFIX>_<NAME>_<DELEGATE_NAME> handle.
+ *
+ * @remarks A new created <PREFIX>_<NAME>_<DELEGATE_NAME> should be released using
+ * the <PREFIX>_<NAME>_<DELEGATE_NAME>_destroy() if it's no longer needed.
+ * @param[in] h The <PREFIX>_<NAME>_<DELEGATE_NAME> handle
+ * @param[out] clone If successful, a new created <PREFIX>_<NAME>_<DELEGATE_NAME> handle will be returned
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see <PREFIX>_<NAME>_<DELEGATE_NAME>_destroy()
+ */
+int <PREFIX>_<NAME>_<DELEGATE_NAME>_clone(<PREFIX>_<NAME>_<DELEGATE_NAME>_h h, <PREFIX>_<NAME>_<DELEGATE_NAME>_h *clone);
+
+/**
+ * @brief Sets the callback function to the <PREFIX>_<NAME>_<DELEGATE_NAME> handle.
+ *
+ * @param[in] h The <PREFIX>_<NAME>_<DELEGATE_NAME> handle
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int <PREFIX>_<NAME>_<DELEGATE_NAME>_set_callback(<PREFIX>_<NAME>_<DELEGATE_NAME>_h h, <PREFIX>_<NAME>_<DELEGATE_NAME>_cb callback, void *user_data);
+
+/**
+ * @brief Set the once flag to the <PREFIX>_<NAME>_<DELEGATE_NAME> handle.
+ * @details If the once flag is 'true', the delegate handle will be deleted after invocation.
+ * If the @a h handle is not used using the method, the handle should be released using
+ * the <PREFIX>_<NAME>_<DELEGATE_NAME>_destroy() when it's no longer needed.
+ * If you don't want the delegate callback function to be called after it's used using the method,
+ * you should release the handle using the <PREFIX>_<NAME>_<DELEGATE_NAME>_dispose().
+ *
+ * @param[in] h The <PREFIX>_<NAME>_<DELEGATE_NAME> handle
+ * @param[in] once The flag if it's true, the delegate will be deleted after invocation
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int <PREFIX>_<NAME>_<DELEGATE_NAME>_set_once(<PREFIX>_<NAME>_<DELEGATE_NAME>_h h, bool once);
+
+/**
+ * @brief Gets the ID of the <PREFIX>_<NAME>_<DELEGATE_NAME> handle.
+ *
+ * @param[in] h The <PREFIX>_<NAME>_<DELEGATE_NAME> handle
+ * @param[out] id The ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int <PREFIX>_<NAME>_<DELEGATE_NAME>_get_id(<PREFIX>_<NAME>_<DELEGATE_NAME>_h h, int *id);
+
+/**
+ * @brief Gets the sequence ID of the <PREFIX>_<NAME>_<DELEGATE_NAME> handle.
+ *
+ * @param[in] h The <PREFIX>_<NAME>_<DELEGATE_NAME> handle
+ * @param[out] seq_id The Sequence ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int <PREFIX>_<NAME>_<DELEGATE_NAME>_get_seq_id(<PREFIX>_<NAME>_<DELEGATE_NAME>_h h, int *seq_id);
+
+/**
+ * @brief Checks whether the delegate is for one-time or not.
+ *
+ * @param[in] h The <PREFIX>_<NAME>_<DELEGATE_NAME> handle
+ * @param[out] once The flag, it's true, the handle is for one-time
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int <PREFIX>_<NAME>_<DELEGATE_NAME>_is_once(<PREFIX>_<NAME>_<DELEGATE_NAME>_h h, bool *once);
+
+/**
+ * @brief Gets the tag from the <PREFIX>_<NAME>_<DELEGATE_NAME> handle.
+ *
+ * @remarks The @a tag should be released using free().
+ * @param[in] h The <PREFIX>_<NAME>_<DELEGATE_NAME> handle
+ * @param[out] tag The tag
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ */
+int <PREFIX>_<NAME>_<DELEGATE_NAME>_get_tag(<PREFIX>_<NAME>_<DELEGATE_NAME>_h h, char **tag);
+
+/**
+ * @brief Disposes the <PREFIX>_<NAME>_<DELEGATE_NAME> handle from the <PREFIX>_<NAME> handle.
+ *
+ * @param[in] proxy The <PREFIX>_<NAME> handle
+ * @param[in] h The <PREFIX>_<NAME>_<DELEGATE_NAME> handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see <PREFIX>_<NAME>_<DELEGATE_NAME>_create()
+ */
+int <PREFIX>_<NAME>_<DELEGATE_NAME>_dispose(<PREFIX>_<NAME>_h proxy, <PREFIX>_<NAME>_<DELEGATE_NAME>_h h);
+)__c_cb";
+
+/**
+ * <PREFIX> The prefix of the interface.
+ * <NAME> The name of the interface.
+ */
+constexpr const char CB_INTERFACE_BASE[] =
+R"__c_cb(
+/**
+ * @brief Called when the proxy is connected.
+ * @details The callback function is called when the proxy is connected to the stub.
+ *
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @param[in] user_data The user data passed from the registeration function
+ * @see #<PREFIX>_<NAME>_callback_s
+ */
+typedef void (*<PREFIX>_<NAME>_connected_cb)(<PREFIX>_<NAME>_h h, void *user_data);
+
+/**
+ * @brief Called when the proxy is disconnected.
+ * @details The callback function is called when the proxy is disconnected from the stub.
+ *
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @param[in] user_data The user data passed from the registeration function
+ * @see #<PREFIX>_<NAME>_callback_s
+ */
+typedef void (*<PREFIX>_<NAME>_disconnected_cb)(<PREFIX>_<NAME>_h h, void *user_data);
+
+/**
+ * @brief Called when the proxy is rejected.
+ * @details The callback function is called when the proxy is rejected to connect to the stub.
+ *
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @param[in] user_data The user data passed from the registeration function
+ * @see #<PREFIX>_<NAME>_callback_s
+ */
+typedef void (*<PREFIX>_<NAME>_rejected_cb)(<PREFIX>_<NAME>_h h, void *user_data);
+
+/**
+ * @brief The structure type containing the set of callback functions for handling proxy events.
+ * @details It is one of the input parameters of the <PREFIX>_<NAME>_create() function.
+ *
+ * @see <PREFIX>_<NAME>_connected_cb
+ * @see <PREFIX>_<NAME>_disconnected_cb
+ * @see <PREFIX>_<NAME>_rejected_cb
+ */
+typedef struct {
+ <PREFIX>_<NAME>_connected_cb connected; /**< This callback function is called when the proxy is connected to the stub. */
+ <PREFIX>_<NAME>_disconnected_cb disconnected; /**< This callback function is called when the proxy is disconnected from the stub. */
+ <PREFIX>_<NAME>_rejected_cb rejected; /**< This callback function is called when the proxy is rejected to connect to the stub. */
+} <PREFIX>_<NAME>_callback_s;
+
+/**
+ * @brief Creates a <PREFIX>_<NAME> handle.
+ * @remarks The @a h handle should be released using
+ * the <PREFIX>_<NAME>_destroy() if it's no longer needed.
+ *
+ * @param[in] stub_appid The application ID of the stub
+ * @param[in] callback The set of callback functions to handle proxy events
+ * @param[in] user_data The user data to be passed to the callback function
+ * @param[out] h The <PREFIX>_<NAME> handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see <PREFIX>_<NAME>_destroy()
+ * @see #<PREFIX>_<NAME>_callback_s
+ */
+int <PREFIX>_<NAME>_create(const char *stub_appid, <PREFIX>_<NAME>_callback_s *callback, void *user_data, <PREFIX>_<NAME>_h *h);
+
+/**
+ * @brief Destroys the <PREFIX>_<NAME> handle.
+ *
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see <PREFIX>_<NAME>_create()
+ */
+int <PREFIX>_<NAME>_destroy(<PREFIX>_<NAME>_h h);
+
+/**
+ * @brief Connects to the stub.
+ *
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_IO_ERROR I/O error
+ * @retval #RPC_PORT_ERROR_PERMISSION_DENIED Permission denied
+ */
+int <PREFIX>_<NAME>_connect(<PREFIX>_<NAME>_h h);
+
+/**
+ * @brief Connects to the stub synchronously.
+ *
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_IO_ERROR I/O error
+ * @retval #RPC_PORT_ERROR_PERMISSION_DENIED Permission denied
+ */
+int <PREFIX>_<NAME>_connect_sync(<PREFIX>_<NAME>_h h);
+
+/**
+ * @brief Disconnects from the stub.
+ *
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int <PREFIX>_<NAME>_disconnect(<PREFIX>_<NAME>_h h);
+)__c_cb";
+
+/**
+ * <RETURN_TYPE> The type of the return value.
+ * <PREFIX> The prefix of the interface.
+ * <NAME> The of the interface.
+ * <METHOD_NAME> The name of the method.
+ * <METHOD_PARAMS> The parameters of the method.
+ */
+constexpr const char CB_INTERFACE_METHOD_BASE[] =
+R"__c_cb(
+/**
+ * @brief Calls the <METHOD_NAME>() method.
+ * @details The return value and args are decided by the interface declaration.
+ * You can get the result using get_last_result().
+ * Before returning the function, the function sets the result using set_last_result().
+ * @remarks The specific error code can be obtained using the get_last_result() function. Error codes are described in Exception section.
+ * @param[in] h The <PREFIX>_<NAME> handle
+ * @param[in] ...
+ * @exception #RPC_PORT_ERROR_NONE Successful
+ * @exception #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @exception #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory
+ * @exception #RPC_PORT_ERROR_IO_ERROR I/O error
+ */
+<RETURN_TYPE><PREFIX>_<NAME>_invoke_<METHOD_NAME>(<PREFIX>_<NAME>_h h<METHOD_PARAMS>);
+)__c_cb";
+
+} // namespace version2
+} // namespace tidl
+
+#endif // IDLC_GEN_VERSION2_C_PROXY_HEADER_GENERATOR_CB_HH_
#include "idlc/gen/cpp_group_body_gen.h"
#include "idlc/gen/dart_proxy_gen.h"
#include "idlc/gen/dart_stub_gen.h"
+#include "idlc/gen/version2/c_proxy_header_generator.hh"
#include "idlc/gen/version2/c_proxy_body_generator.hh"
#include "idlc/gen_cion/c_cion_proxy_header_gen.h"
#include "idlc/gen_cion/c_cion_proxy_body_gen.h"
#include "idlc/gen_cion/java_cion_common_gen.h"
void GenerateStubCodes(std::shared_ptr<tidl::Options> options,
- tidl::Parser& ps) {
+ const tidl::Parser& ps) {
if (options->IsCion()) {
- auto trans = std::shared_ptr<tidl::Transportable>(new tidl::PluginLoader(""));
+ auto trans = std::shared_ptr<tidl::Transportable>(
+ new tidl::PluginLoader(""));
switch (options->GetLanguage()) {
case tidl::Options::LANGUAGE_TYPE_C:
{
break;
}
} else if (options->IsAitt()) {
- auto trans = std::shared_ptr<tidl::Transportable>(new tidl::AIttPluginLoader(""));
+ auto trans = std::shared_ptr<tidl::Transportable>(
+ new tidl::AIttPluginLoader(""));
switch (options->GetLanguage()) {
case tidl::Options::LANGUAGE_TYPE_C:
{
}
void GenerateProxyCodes(std::shared_ptr<tidl::Options> options,
- tidl::Parser& ps) {
+ const tidl::Parser& ps) {
if (options->IsCion()) {
- auto trans = std::shared_ptr<tidl::Transportable>(new tidl::PluginLoader(""));
+ auto trans = std::shared_ptr<tidl::Transportable>(
+ new tidl::PluginLoader(""));
switch (options->GetLanguage()) {
case tidl::Options::LANGUAGE_TYPE_C:
{
break;
}
} else if (options->IsAitt()) {
- auto trans = std::shared_ptr<tidl::Transportable>(new tidl::AIttPluginLoader(""));
+ auto trans = std::shared_ptr<tidl::Transportable>(
+ new tidl::AIttPluginLoader(""));
switch (options->GetLanguage()) {
case tidl::Options::LANGUAGE_TYPE_C:
{
switch (options->GetLanguage()) {
case tidl::Options::LANGUAGE_TYPE_C:
{
- tidl::CProxyHeaderGen proxy_header(ps.GetDoc());
- proxy_header.EnableNamespace(options->HasNamespace());
- proxy_header.EnableProxy(true);
- proxy_header.Run(options->GetOutput() + ".h");
-
if (ps.GetVersion() == 2) {
+ tidl::version2::CProxyHeaderGenerator proxy_header(ps.GetDoc());
+ proxy_header.EnableNamespace(options->HasNamespace());
+ proxy_header.EnableProxy(true);
+ proxy_header.Run(options->GetOutput() + ".h");
+
tidl::version2::CProxyBodyGenerator proxy_body(ps.GetDoc(), options);
proxy_body.EnableNamespace(options->HasNamespace());
proxy_body.EnableProxy(true);
proxy_body.Run(options->GetOutput() + ".c");
} else {
+ tidl::CProxyHeaderGen proxy_header(ps.GetDoc());
+ proxy_header.EnableNamespace(options->HasNamespace());
+ proxy_header.EnableProxy(true);
+ proxy_header.Run(options->GetOutput() + ".h");
+
tidl::CProxyBodyGen proxy_body(ps.GetDoc(), options);
proxy_body.EnableNamespace(options->HasNamespace());
proxy_body.EnableProxy(true);
}
void GenerateGroupCodes(std::shared_ptr<tidl::Options> options,
- tidl::Parser& ps) {
+ const tidl::Parser& ps) {
if (options->IsCion()) {
- auto trans = std::shared_ptr<tidl::Transportable>(new tidl::PluginLoader(""));
+ auto trans = std::shared_ptr<tidl::Transportable>(
+ new tidl::PluginLoader(""));
switch (options->GetLanguage()) {
case tidl::Options::LANGUAGE_TYPE_C:
{
default:
break;
}
- } else if (options->IsAitt()) {
- auto trans = std::shared_ptr<tidl::Transportable>(new tidl::AIttPluginLoader(""));
+ } else if (options->IsAitt()) {
+ auto trans = std::shared_ptr<tidl::Transportable>(
+ new tidl::AIttPluginLoader(""));
switch (options->GetLanguage()) {
case tidl::Options::LANGUAGE_TYPE_C:
{
}
}
-void GenerateCodes(std::shared_ptr<tidl::Options> options, tidl::Parser& ps) {
+void GenerateCodes(std::shared_ptr<tidl::Options> options,
+ const tidl::Parser& ps) {
switch (options->GetType()) {
case tidl::Options::Type::TYPE_STUB:
GenerateStubCodes(options, ps);