From: Hwankyu Jhun Date: Mon, 2 Jan 2023 01:34:23 +0000 (+0000) Subject: Implement C header generator X-Git-Tag: accepted/tizen/unified/20230420.153149~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F17%2F286217%2F4;p=platform%2Fcore%2Fappfw%2Ftidl.git Implement C header generator This patch is for protocol version 2. Change-Id: Id4216a97ada075b80fc1c580c6f1809948c43d17 Signed-off-by: Hwankyu Jhun --- diff --git a/idlc/ast/parser.cc b/idlc/ast/parser.cc index d2e6e72..dc6581f 100644 --- a/idlc/ast/parser.cc +++ b/idlc/ast/parser.cc @@ -49,7 +49,7 @@ void Parser::SetDoc(Document* doc) { doc_ = std::shared_ptr(doc); } -std::shared_ptr Parser::GetDoc() { +std::shared_ptr Parser::GetDoc() const { return doc_; } @@ -71,7 +71,7 @@ void Parser::SetVersion(int ver) { ver_ = ver; } -int Parser::GetVersion() { +int Parser::GetVersion() const { return ver_; } @@ -88,19 +88,19 @@ void Parser::ReportError(const std::string& err, unsigned line) { 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_; } diff --git a/idlc/ast/parser.h b/idlc/ast/parser.h index dcb2c55..9ce8252 100644 --- a/idlc/ast/parser.h +++ b/idlc/ast/parser.h @@ -35,14 +35,14 @@ class Parser { bool Parse(const std::string& input); bool ParseFromFile(const std::string& path); void SetDoc(Document* doc); - std::shared_ptr GetDoc(); + std::shared_ptr 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_; diff --git a/idlc/gen/c_header_gen_base.h b/idlc/gen/c_header_gen_base.h index b61571c..c54936c 100644 --- a/idlc/gen/c_header_gen_base.h +++ b/idlc/gen/c_header_gen_base.h @@ -34,7 +34,7 @@ class CHeaderGeneratorBase : public CGeneratorBase { 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); diff --git a/idlc/gen/version2/c_body_generator_array_base_cb.hh b/idlc/gen/version2/c_body_generator_array_base_cb.hh index 36b5ab8..67c83f7 100644 --- a/idlc/gen/version2/c_body_generator_array_base_cb.hh +++ b/idlc/gen/version2/c_body_generator_array_base_cb.hh @@ -14,8 +14,8 @@ * 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 { @@ -385,4 +385,4 @@ if (h->value) } // 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_ diff --git a/idlc/gen/version2/c_body_generator_base.hh b/idlc/gen/version2/c_body_generator_base.hh index 7ef4a74..506a2e6 100644 --- a/idlc/gen/version2/c_body_generator_base.hh +++ b/idlc/gen/version2/c_body_generator_base.hh @@ -14,8 +14,8 @@ * 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 #include @@ -85,4 +85,4 @@ class CBodyGeneratorBase : public tidl::CBodyGeneratorBase { } // namespace version2 } // namespace tidl -#endif // IDLC_GEN_VERSION2_C_BODY_GENERATOR_BASE_H_ +#endif // IDLC_GEN_VERSION2_C_BODY_GENERATOR_BASE_HH_ diff --git a/idlc/gen/version2/c_body_generator_list_base_cb.hh b/idlc/gen/version2/c_body_generator_list_base_cb.hh index a28883f..3d2db5c 100644 --- a/idlc/gen/version2/c_body_generator_list_base_cb.hh +++ b/idlc/gen/version2/c_body_generator_list_base_cb.hh @@ -14,8 +14,8 @@ * 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 { @@ -476,4 +476,4 @@ free(value); } // 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_ diff --git a/idlc/gen/version2/c_header_generator_array_base_cb.hh b/idlc/gen/version2/c_header_generator_array_base_cb.hh new file mode 100644 index 0000000..55a73bd --- /dev/null +++ b/idlc/gen/version2/c_header_generator_array_base_cb.hh @@ -0,0 +1,111 @@ +/* + * 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 { + +/** + * The prefix of the array structure. + * The name of the array structure. + * The type of the input parameter. + * The type of the output parameter. + */ +constexpr const char CB_STRUCTURE_ARRAY_BASE[] = +R"__c_cb( +/** + * @briefs Creates a _ handle. + * + * @remarks The @a h should be released using the __destroy() + * if it's no longer needed. + * @param[out] h The _ 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 __destroy() + */ +int __create(__h *h); + +/** + * @brief Destroys the _ handle. + * + * @param[in] h The _ 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 __create() + */ +int __destroy(__h h); + +/** + * @brief Creates and returns a copy of the given _ handle. + * + * @remarks A new created _ should be released using + * the __destroy() if it's no longer needed. + * @param[in] h The _ handle + * @param[out] clone If successful, a new created _ 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 __destroy() + */ +int __clone(__h h, __h *clone); + +/** + * @brief Sets the value to the _ 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 _ 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 __get() + */ +int __set(__h h, *value, int size); + +/** + * @brief Gets the value from the _ handle. + * + * @remarks A new created value should be released if it's no longer needed. + * @param[in] h The _ 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 __set() + */ +int __get(__h h, *value, int *size); +)__c_cb"; + +} // namespace version2 +} // namespace tidl + +#endif // IDLC_GEN_VERSION2_C_HEADER_GENERATOR_ARRAY_BASE_CB_HH_ diff --git a/idlc/gen/version2/c_header_generator_base.cc b/idlc/gen/version2/c_header_generator_base.cc new file mode 100644 index 0000000..f46027a --- /dev/null +++ b/idlc/gen/version2/c_header_generator_base.cc @@ -0,0 +1,127 @@ +/* + * 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 + +#include +#include + +#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 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(*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("", GetHandlePrefix()) + .Change("", st.GetID()) + .Change("", param_type_in) + .Change("", 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("", GetHandlePrefix()) + .Change("", st.GetID()) + .Change("", 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("", GetHandlePrefix()) + .Change("", 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("", GetHandlePrefix()) + .Change("", st.GetID()) + .Change("", param_type_in) + .Change("", param_type_out) + .Change("", 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 diff --git a/idlc/gen/version2/c_header_generator_base.hh b/idlc/gen/version2/c_header_generator_base.hh new file mode 100644 index 0000000..31f83e0 --- /dev/null +++ b/idlc/gen/version2/c_header_generator_base.hh @@ -0,0 +1,46 @@ +/* + * 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 + +#include "idlc/gen/c_header_gen_base.h" + +namespace tidl { +namespace version2 { + +class CHeaderGeneratorBase : public tidl::CHeaderGeneratorBase { + public: + explicit CHeaderGeneratorBase(std::shared_ptr 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_ diff --git a/idlc/gen/version2/c_header_generator_base_cb.hh b/idlc/gen/version2/c_header_generator_base_cb.hh new file mode 100644 index 0000000..89c3d75 --- /dev/null +++ b/idlc/gen/version2/c_header_generator_base_cb.hh @@ -0,0 +1,118 @@ +/* + * 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 { + +/** + * The prefix of the structure. e.g. rpc_port_proxy_ or rpc_port_stub_ + * The name of the structure. + */ +constexpr const char CB_STRUCTURE_BASE[] = +R"__c_cb( +/** + * @brief Creates a _ handle. + * + * @remarks The @a h handle should be released using the __destroy() + * if it's no longer needed. + * @param[out] h The _ 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 __destroy() + */ +int __create(__h *h); + +/** + * @brief Destroys the _ handle. + * + * @param[in] h The _ 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 __create() + */ +int __destroy(__h h); + +/** + * @brief Creates and returns a copy of the given _ handle. + * + * @remarks A new created _ should be released using + * the __destroy() if it's no longer needed. + * @param[in] h The _ handle + * @param[out] clone If successful, a new created _ 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 __destroy() + */ +int __clone(__h h, __h *clone); +)__c_cb"; + +/** + * The prefix of the structure. e.g. rpc_port_proxy_ or rpc_port_stub_ + * The name of the structure. + * The type of the input parameter. + * The type of the output parameter. + * The name of the element of the structure. + */ +constexpr const char CB_STRUCTURE_BASE_SET_GET[] = +R"__c_cb( +/** + * @brief Sets the to the _ handle. + * + * @remarks The is internally copied and stored. + * You should release it if it's allocated when it's no longer needed. + * @param[in] h The _ handle + * @param[in] value The + * @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 __get_() + */ +int __set_(__h h, value); + +/** + * @brief Gets the from the _ handle. + * + * @remarks A new created value should be released if it's allocated when it's no longer needed. + * @param[in] h The _ handle + * @param[out] value The + * @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 __set_ + */ +int __get_(__h h, value); +)__c_cb"; + +} // namespace version2 +} // namespace tidl + +#endif // IDLC_GEN_VERSION2_C_HEADER_GENERATOR_BASE_CB_HH_ diff --git a/idlc/gen/version2/c_header_generator_list_base_cb.hh b/idlc/gen/version2/c_header_generator_list_base_cb.hh new file mode 100644 index 0000000..e8198bb --- /dev/null +++ b/idlc/gen/version2/c_header_generator_list_base_cb.hh @@ -0,0 +1,145 @@ +/* + * 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 { + +/** + * The prefix of the list structure. + * The name of the list structure. + * 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 _ 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 __foreach() + */ +typedef bool (*__cb)(value, void *user_data); + +/** + * @brief Creates a _ handle. + * + * @remarks The @a h handle should be released using the __destroy() + * if it's no longer needed. + * @param[out] h The _ 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 __destroy() + */ +int __create(__h *h); + +/** + * @brief Destroys the _ handle. + * + * @param[in] The _ 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 __create() + */ +int __destroy(__h h); + +/** + * @brief Creates and returns a copy of the given _ handle. + * + * @remarks A new created _ should be released using + * the __destroy() if it's no longer needed. + * @param[in] h The _ handle + * @param[out] clone If successful, a new created _ 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 __destroy() + */ +int __clone(__h h, __h *clone); + +/** + * @brief Adds the value to the _ 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 _ 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 __remove() + */ +int __add(__h h, value); + +/** + * @brief Retrieves all values contained in the _ handle. + * @details This function called __cb once for each value contained in the _ handle. + * If the __cb callback function returns @c false, the iteration will be finished. + * + * @param[in] h The _ 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 __cb() + */ +int __foreach(__h h, __cb callback, void *user_data); + +/** + * @brief Removes the element at the given position in the _ handle. + * + * @param[in] h The _ 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 __remove(__h h, unsigned int nth); + +/** + * @brief Gets the number of elements in the _ handle. + * + * @param[in] h The _ 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 __length(__h h, unsigned int *length); +)__c_cb"; + +} // namespace version2 +} // namespace tidl + +#endif // IDLC_GEN_VERSION2_C_HEADER_GENERATOR_LIST_BASE_CB_HH_ diff --git a/idlc/gen/version2/c_proxy_body_generator_cb.hh b/idlc/gen/version2/c_proxy_body_generator_cb.hh index 2c58500..0129f76 100644 --- a/idlc/gen/version2/c_proxy_body_generator_cb.hh +++ b/idlc/gen/version2/c_proxy_body_generator_cb.hh @@ -14,8 +14,8 @@ * 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 { @@ -1067,4 +1067,4 @@ h->delegates = g_list_append(h->delegates, ); } // namespace version2 } // namespace tidl -#endif // IDLC_GEN_VERSION2_C_PROXY_BODY_GENERATOR_CB_H_ +#endif // IDLC_GEN_VERSION2_C_PROXY_BODY_GENERATOR_CB_HH_ diff --git a/idlc/gen/version2/c_proxy_header_generator.cc b/idlc/gen/version2/c_proxy_header_generator.cc new file mode 100644 index 0000000..5059feb --- /dev/null +++ b/idlc/gen/version2/c_proxy_header_generator.cc @@ -0,0 +1,168 @@ +/* + * 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 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(*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("", GetHandlePrefix()) + .Change("", 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("", GetHandlePrefix()) + .Change("", iface.GetID()) + .Change("", 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(*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("", GetHandlePrefix()) + .Change("", 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("", GetHandlePrefix()) + .Change("", iface.GetID()) + .Change("", decl.GetID()) + .Change("", 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("", GetReturnTypeString(decl.GetType())) + .Change("", GetHandlePrefix()) + .Change("", iface.GetID()) + .Change("", decl.GetID()) + .Change("", GenMethodParams(iface, decl)) + .Transform([&](std::string code) { return SmartIndent(code); }) + .Out(stream); +} + +} // namespace version2 +} // namespace tidl diff --git a/idlc/gen/version2/c_proxy_header_generator.hh b/idlc/gen/version2/c_proxy_header_generator.hh new file mode 100644 index 0000000..9b69734 --- /dev/null +++ b/idlc/gen/version2/c_proxy_header_generator.hh @@ -0,0 +1,57 @@ +/* + * 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 +#include + +#include "idlc/gen/version2/c_header_generator_base.hh" + +namespace tidl { +namespace version2 { + +class CProxyHeaderGenerator : public CHeaderGeneratorBase { + public: + explicit CProxyHeaderGenerator(std::shared_ptr 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_ diff --git a/idlc/gen/version2/c_proxy_header_generator_cb.hh b/idlc/gen/version2/c_proxy_header_generator_cb.hh new file mode 100644 index 0000000..a7e66ea --- /dev/null +++ b/idlc/gen/version2/c_proxy_header_generator_cb.hh @@ -0,0 +1,346 @@ +/* + * 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 { + +/** + * The prefix of the interface. + * The name of the interface. + */ +constexpr const char CB_INTERFACE_HANDLE[] = +R"__c_cb( +/** + * @brief The _ handle. + */ +typedef struct __s *__h; +)__c_cb"; + +constexpr const char CB_INTERFACE_DELEGATE_HANDLE[] = +R"__c_cb( +/** + * @brief The __ handle. + */ +typedef struct ___s *___h; +)__c_cb"; + +/** + * The prefix of the interface. + * The name of the interface. + * The name of the delegate. + * 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 ___create() + */ +typedef void (*___cb)(void *user_data); + +/** + * @brief Creates a __ handle. + * + * @param[out] h The __ 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 ___destroy() + * @see ___dispose() + * @see ___set_callback() + * @see ___set_once() + */ +int ___create(___h *h); + +/** + * @brief Destroys the __ handle. + * + * @param[in] h The __ 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 ___create() + */ +int ___destroy(___h h); + +/** + * @brief Creates and returns a copy of the given __ handle. + * + * @remarks A new created __ should be released using + * the ___destroy() if it's no longer needed. + * @param[in] h The __ handle + * @param[out] clone If successful, a new created __ 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 ___destroy() + */ +int ___clone(___h h, ___h *clone); + +/** + * @brief Sets the callback function to the __ handle. + * + * @param[in] h The __ 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 ___set_callback(___h h, ___cb callback, void *user_data); + +/** + * @brief Set the once flag to the __ 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 ___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 ___dispose(). + * + * @param[in] h The __ 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 ___set_once(___h h, bool once); + +/** + * @brief Gets the ID of the __ handle. + * + * @param[in] h The __ 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 ___get_id(___h h, int *id); + +/** + * @brief Gets the sequence ID of the __ handle. + * + * @param[in] h The __ 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 ___get_seq_id(___h h, int *seq_id); + +/** + * @brief Checks whether the delegate is for one-time or not. + * + * @param[in] h The __ 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 ___is_once(___h h, bool *once); + +/** + * @brief Gets the tag from the __ handle. + * + * @remarks The @a tag should be released using free(). + * @param[in] h The __ 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 ___get_tag(___h h, char **tag); + +/** + * @brief Disposes the __ handle from the _ handle. + * + * @param[in] proxy The _ handle + * @param[in] h The __ 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 ___create() + */ +int ___dispose(__h proxy, ___h h); +)__c_cb"; + +/** + * The prefix of the interface. + * 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 _ handle + * @param[in] user_data The user data passed from the registeration function + * @see #__callback_s + */ +typedef void (*__connected_cb)(__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 _ handle + * @param[in] user_data The user data passed from the registeration function + * @see #__callback_s + */ +typedef void (*__disconnected_cb)(__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 _ handle + * @param[in] user_data The user data passed from the registeration function + * @see #__callback_s + */ +typedef void (*__rejected_cb)(__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 __create() function. + * + * @see __connected_cb + * @see __disconnected_cb + * @see __rejected_cb + */ +typedef struct { + __connected_cb connected; /**< This callback function is called when the proxy is connected to the stub. */ + __disconnected_cb disconnected; /**< This callback function is called when the proxy is disconnected from the stub. */ + __rejected_cb rejected; /**< This callback function is called when the proxy is rejected to connect to the stub. */ +} __callback_s; + +/** + * @brief Creates a _ handle. + * @remarks The @a h handle should be released using + * the __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 _ 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 __destroy() + * @see #__callback_s + */ +int __create(const char *stub_appid, __callback_s *callback, void *user_data, __h *h); + +/** + * @brief Destroys the _ handle. + * + * @param[in] h The _ 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 __create() + */ +int __destroy(__h h); + +/** + * @brief Connects to the stub. + * + * @param[in] h The _ 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 __connect(__h h); + +/** + * @brief Connects to the stub synchronously. + * + * @param[in] h The _ 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 __connect_sync(__h h); + +/** + * @brief Disconnects from the stub. + * + * @param[in] h The _ 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 __disconnect(__h h); +)__c_cb"; + +/** + * The type of the return value. + * The prefix of the interface. + * The of the interface. + * The name of the method. + * The parameters of the method. + */ +constexpr const char CB_INTERFACE_METHOD_BASE[] = +R"__c_cb( +/** + * @brief Calls the () 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 _ 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 + */ +__invoke_(__h h); +)__c_cb"; + +} // namespace version2 +} // namespace tidl + +#endif // IDLC_GEN_VERSION2_C_PROXY_HEADER_GENERATOR_CB_HH_ diff --git a/idlc/main.cc b/idlc/main.cc index d08c30a..816e510 100644 --- a/idlc/main.cc +++ b/idlc/main.cc @@ -38,6 +38,7 @@ #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" @@ -77,9 +78,10 @@ #include "idlc/gen_cion/java_cion_common_gen.h" void GenerateStubCodes(std::shared_ptr options, - tidl::Parser& ps) { + const tidl::Parser& ps) { if (options->IsCion()) { - auto trans = std::shared_ptr(new tidl::PluginLoader("")); + auto trans = std::shared_ptr( + new tidl::PluginLoader("")); switch (options->GetLanguage()) { case tidl::Options::LANGUAGE_TYPE_C: { @@ -130,7 +132,8 @@ void GenerateStubCodes(std::shared_ptr options, break; } } else if (options->IsAitt()) { - auto trans = std::shared_ptr(new tidl::AIttPluginLoader("")); + auto trans = std::shared_ptr( + new tidl::AIttPluginLoader("")); switch (options->GetLanguage()) { case tidl::Options::LANGUAGE_TYPE_C: { @@ -269,9 +272,10 @@ void GenerateStubCodes(std::shared_ptr options, } void GenerateProxyCodes(std::shared_ptr options, - tidl::Parser& ps) { + const tidl::Parser& ps) { if (options->IsCion()) { - auto trans = std::shared_ptr(new tidl::PluginLoader("")); + auto trans = std::shared_ptr( + new tidl::PluginLoader("")); switch (options->GetLanguage()) { case tidl::Options::LANGUAGE_TYPE_C: { @@ -323,7 +327,8 @@ void GenerateProxyCodes(std::shared_ptr options, break; } } else if (options->IsAitt()) { - auto trans = std::shared_ptr(new tidl::AIttPluginLoader("")); + auto trans = std::shared_ptr( + new tidl::AIttPluginLoader("")); switch (options->GetLanguage()) { case tidl::Options::LANGUAGE_TYPE_C: { @@ -418,17 +423,22 @@ void GenerateProxyCodes(std::shared_ptr options, 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); @@ -468,9 +478,10 @@ void GenerateProxyCodes(std::shared_ptr options, } void GenerateGroupCodes(std::shared_ptr options, - tidl::Parser& ps) { + const tidl::Parser& ps) { if (options->IsCion()) { - auto trans = std::shared_ptr(new tidl::PluginLoader("")); + auto trans = std::shared_ptr( + new tidl::PluginLoader("")); switch (options->GetLanguage()) { case tidl::Options::LANGUAGE_TYPE_C: { @@ -520,8 +531,9 @@ void GenerateGroupCodes(std::shared_ptr options, default: break; } - } else if (options->IsAitt()) { - auto trans = std::shared_ptr(new tidl::AIttPluginLoader("")); + } else if (options->IsAitt()) { + auto trans = std::shared_ptr( + new tidl::AIttPluginLoader("")); switch (options->GetLanguage()) { case tidl::Options::LANGUAGE_TYPE_C: { @@ -647,7 +659,8 @@ void GenerateGroupCodes(std::shared_ptr options, } } -void GenerateCodes(std::shared_ptr options, tidl::Parser& ps) { +void GenerateCodes(std::shared_ptr options, + const tidl::Parser& ps) { switch (options->GetType()) { case tidl::Options::Type::TYPE_STUB: GenerateStubCodes(options, ps);