From 3dce7e3cf3ab57093aedd9ebffe8188c7a8db720 Mon Sep 17 00:00:00 2001 From: "jh9216.park" Date: Fri, 15 Oct 2021 07:07:43 -0400 Subject: [PATCH] Fix java generator - implement delegator class - remake stub generator - remake proxy generator Change-Id: Ic2b628e171aca748aad7c4980f347445bf14761b Signed-off-by: jh9216.park --- Makefile.dibs | 4 +- idlc/gen_cion/java_cion_common_gen.cc | 104 ++++ ...java_cion_data_gen.h => java_cion_common_gen.h} | 16 +- idlc/gen_cion/java_cion_data_gen.cc | 71 --- idlc/gen_cion/java_cion_gen_base.cc | 507 ++++++++++++++- idlc/gen_cion/java_cion_gen_base.h | 31 +- idlc/gen_cion/java_cion_gen_cb.h | 687 +++++---------------- idlc/gen_cion/java_cion_interface_gen.cc | 76 --- idlc/gen_cion/java_cion_interface_gen.h | 40 -- idlc/gen_cion/java_cion_proxy_gen.cc | 286 +++++---- idlc/gen_cion/java_cion_proxy_gen.h | 8 +- idlc/gen_cion/java_cion_proxy_gen_cb.h | 173 ++++++ idlc/gen_cion/java_cion_proxy_repo_gen.cc | 9 +- idlc/gen_cion/java_cion_structure_gen.cc | 69 +-- idlc/gen_cion/java_cion_structure_gen.h | 8 - idlc/gen_cion/java_cion_stub_base_service_gen.cc | 86 --- idlc/gen_cion/java_cion_stub_base_service_gen.h | 43 -- idlc/gen_cion/java_cion_stub_gen.cc | 454 ++++++-------- idlc/gen_cion/java_cion_stub_gen.h | 20 +- idlc/gen_cion/java_cion_stub_gen_cb.h | 309 +++++++++ idlc/gen_cion/java_cion_stub_repo_gen.cc | 9 +- idlc/gen_cion/java_cion_utility_gen.cc | 6 +- idlc/main.cc | 21 +- 23 files changed, 1655 insertions(+), 1382 deletions(-) create mode 100644 idlc/gen_cion/java_cion_common_gen.cc rename idlc/gen_cion/{java_cion_data_gen.h => java_cion_common_gen.h} (69%) delete mode 100644 idlc/gen_cion/java_cion_data_gen.cc delete mode 100644 idlc/gen_cion/java_cion_interface_gen.cc delete mode 100644 idlc/gen_cion/java_cion_interface_gen.h create mode 100644 idlc/gen_cion/java_cion_proxy_gen_cb.h delete mode 100644 idlc/gen_cion/java_cion_stub_base_service_gen.cc delete mode 100644 idlc/gen_cion/java_cion_stub_base_service_gen.h create mode 100644 idlc/gen_cion/java_cion_stub_gen_cb.h diff --git a/Makefile.dibs b/Makefile.dibs index 3a43ec2..fd32ab9 100644 --- a/Makefile.dibs +++ b/Makefile.dibs @@ -43,13 +43,11 @@ SRC_FILES := \ idlc/gen_cion/cs_cion_gen_base.cc \ idlc/gen_cion/cs_cion_proxy_gen.cc \ idlc/gen_cion/cs_cion_stub_gen.cc \ - idlc/gen_cion/java_cion_data_gen.cc \ + idlc/gen_cion/java_cion_common_gen.cc \ idlc/gen_cion/java_cion_gen_base.cc \ - idlc/gen_cion/java_cion_interface_gen.cc \ idlc/gen_cion/java_cion_proxy_gen.cc \ idlc/gen_cion/java_cion_proxy_repo_gen.cc \ idlc/gen_cion/java_cion_structure_gen.cc \ - idlc/gen_cion/java_cion_stub_base_service_gen.cc \ idlc/gen_cion/java_cion_stub_gen.cc \ idlc/gen_cion/java_cion_stub_repo_gen.cc \ idlc/gen_cion/java_cion_utility_gen.cc \ diff --git a/idlc/gen_cion/java_cion_common_gen.cc b/idlc/gen_cion/java_cion_common_gen.cc new file mode 100644 index 0000000..c418c7b --- /dev/null +++ b/idlc/gen_cion/java_cion_common_gen.cc @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2021 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_cion/java_cion_common_gen.h" +#include "idlc/gen_cion/java_cion_gen_cb.h" + +#include +#include + +#include +#include + +namespace tidl { + +JavaCionCommonGen::JavaCionCommonGen( + std::shared_ptr doc) : JavaCionGeneratorBase(doc) { +} + +void JavaCionCommonGen::OnInitGen(std::ofstream& stream) { + std::string fname = MakeDir(FileName, "/common"); + if (fname.empty()) + return; + + stream.open(fname + "/DelegatorBase.java"); + stream << "package org.tizen.gen." << FileName + ".common;" << NLine(1); + stream << ReplaceAll(DELEGATOR_BASE, "", GetDelegateId()); + stream.close(); + + stream.open(fname + "/NotConnectedSocketException.java"); + stream << "package org.tizen.gen." << FileName << ".common;" << NLine(2); + stream << CB_CION_JAVA_EXCEPTION_NotConnectedSocketException << NLine(1); + stream.close(); + + stream.open(fname + "/InvalidProtocolException.java"); + stream << "package org.tizen.gen." << FileName << ".common;" << NLine(2); + stream << CB_CION_JAVA_EXCEPTION_InvalidProtocolException << NLine(1); + stream.close(); + + stream.open(fname + "/InvalidIOException.java"); + stream << "package org.tizen.gen." << FileName << ".common;" << NLine(2); + stream << CB_CION_JAVA_EXCEPTION_InvalidIOException << NLine(1); + stream.close(); + + stream.open(fname + "/PermissionDeniedException.java"); + stream << "package org.tizen.gen." << FileName << ".common;" << NLine(2); + stream << CB_CION_JAVA_EXCEPTION_PermissionDeniedException << NLine(1); + stream.close(); + + stream.open(fname + "/InvalidIDException.java"); + stream << "package org.tizen.gen." << FileName << ".common;" << NLine(2); + stream << CB_CION_JAVA_EXCEPTION_InvalidIDException << NLine(1); + stream.close(); + + stream.open(fname + "/InvalidCallbackException.java"); + stream << "package org.tizen.gen." << FileName << ".common;" << NLine(2); + stream << CB_CION_JAVA_EXCEPTION_InvalidCallbackException << NLine(1); + stream.close(); + + stream.open(fname + "/InvalidArgumentException.java"); + stream << "package org.tizen.gen." << FileName << ".common;" << NLine(2); + stream << CB_CION_JAVA_EXCEPTION_InvalidArgumentException << NLine(1); + stream.close(); +} + +std::string JavaCionCommonGen::GetDelegateId() { + int id = 1; + std::string str; + + for (auto& i : GetDocument().GetBlocks()) { + if (i->GetType() != Block::TYPE_INTERFACE) + continue; + + Interface& iface = static_cast(*i); + for (auto& d : iface.GetDeclarations().GetDecls()) { + if (d->GetMethodType() != Declaration::MethodType::DELEGATE) + continue; + + str += Tab(1); + str += "public static final int "; + str = str + i->GetID() + "_" + d->GetID() + "__ = " + + std::to_string(id++) + ";\n"; + } + } + + return str; +} + +void JavaCionCommonGen::OnFiniGen(std::ofstream& stream) { +} + +} // namespace tidl diff --git a/idlc/gen_cion/java_cion_data_gen.h b/idlc/gen_cion/java_cion_common_gen.h similarity index 69% rename from idlc/gen_cion/java_cion_data_gen.h rename to idlc/gen_cion/java_cion_common_gen.h index d26d327..5e43a6f 100644 --- a/idlc/gen_cion/java_cion_data_gen.h +++ b/idlc/gen_cion/java_cion_common_gen.h @@ -14,28 +14,26 @@ * limitations under the License. */ -#ifndef IDLC_GEN_CION_JAVA_CION_DATA_GEN_H_ -#define IDLC_GEN_CION_JAVA_CION_DATA_GEN_H_ +#ifndef IDLC_GEN_CION_JAVA_CION_COMMON_GEN_H_ +#define IDLC_GEN_CION_JAVA_CION_COMMON_GEN_H_ #include #include #include -#include "idlc/ast/type.h" -#include "idlc/ast/structure.h" #include "idlc/gen_cion/java_cion_gen_base.h" namespace tidl { -class JavaCionDataGen : public JavaCionGeneratorBase { +class JavaCionCommonGen : public JavaCionGeneratorBase { public: - explicit JavaCionDataGen(std::shared_ptr doc); - virtual ~JavaCionDataGen() = default; + explicit JavaCionCommonGen(std::shared_ptr doc); + virtual ~JavaCionCommonGen() = default; void OnInitGen(std::ofstream& stream) override; void OnFiniGen(std::ofstream& stream) override; - std::string NLine(int cnt); + std::string GetDelegateId(); }; } // namespace tidl -#endif // IDLC_GEN_CION_JAVA_CION_DATA_GEN_H_ +#endif // IDLC_GEN_CION_JAVA_CION_COMMON_GEN_H_ diff --git a/idlc/gen_cion/java_cion_data_gen.cc b/idlc/gen_cion/java_cion_data_gen.cc deleted file mode 100644 index fa6afb1..0000000 --- a/idlc/gen_cion/java_cion_data_gen.cc +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2021 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_cion/java_cion_data_gen.h" -#include "idlc/gen_cion/java_cion_gen_cb.h" - -#include -#include - -#include -#include - -namespace tidl { - -JavaCionDataGen::JavaCionDataGen( - std::shared_ptr doc) : JavaCionGeneratorBase(doc) { -} - -void JavaCionDataGen::OnInitGen(std::ofstream& stream) { - std::string fname = MakeDir(FileName, "/data"); - if (fname.empty()) - return; - - stream.open(fname + "/ReceivedPayloadInfo.java"); - stream << "package org.tizen.gen." << FileName + ".data;" << NLine(2); - stream << RECEIVED_PAYLOAD_INFO_CLASS; - stream.close(); - - stream.open(fname + "/ReceivedDataInfo.java"); - stream << "package org.tizen.gen." << FileName + ".data;" << NLine(2); - stream << RECEIVED_DATA_INFO_CLASS; - stream.close(); - - stream.open(fname + "/ConnectedPeer.java"); - stream << "package org.tizen.gen." << FileName + ".data;" << NLine(2); - stream << CONNECTED_PEER; - stream.close(); - - stream.open(fname + "/DiscoveredPeer.java"); - stream << "package org.tizen.gen." << FileName + ".data;" << NLine(2); - stream << DISCOVERED_PEER; - stream.close(); -} - -void JavaCionDataGen::OnFiniGen(std::ofstream& stream) { -} - -std::string JavaCionDataGen::NLine(int cnt) { - std::string t; - - for (int i = 0; i < cnt; i++) { - t += "\n"; - } - - return t; -} - -} // namespace tidl diff --git a/idlc/gen_cion/java_cion_gen_base.cc b/idlc/gen_cion/java_cion_gen_base.cc index a125194..b0eda5d 100644 --- a/idlc/gen_cion/java_cion_gen_base.cc +++ b/idlc/gen_cion/java_cion_gen_base.cc @@ -15,6 +15,7 @@ */ #include "idlc/gen_cion/java_cion_gen_base.h" +#include "idlc/gen_cion/java_cion_gen_cb.h" #include #include @@ -32,7 +33,7 @@ JavaCionGeneratorBase::JavaCionGeneratorBase(std::shared_ptr doc) : Generator(doc) { type_map_ = { {"char", "byte"}, {"int", "int"}, {"short", "short"}, - {"long", "long"}, {"string", "String"}, {"bool", "bool"}, + {"long", "long"}, {"string", "String"}, {"bool", "boolean"}, {"list", "LinkedList"}, {"array", "ArrayList"}, {"float", "float"}, {"double", "double"}, {"bundle", "Bundle"}, {"void", "void"}, {"file", "String"} @@ -40,11 +41,11 @@ JavaCionGeneratorBase::JavaCionGeneratorBase(std::shared_ptr doc) meta_type_map_ = { {"char", "Byte"}, - {"int", "Int"}, + {"int", "Integer"}, {"short", "Short"}, {"long", "Long"}, {"string", "String"}, - {"bool", "Bool"}, + {"bool", "Boolean"}, {"float", "Float"}, {"double", "Double"}, {"bundle", "Bundle"}, @@ -52,16 +53,16 @@ JavaCionGeneratorBase::JavaCionGeneratorBase(std::shared_ptr doc) }; parcel_reader_map_ = { - {"char", "readByte()"}, - {"int", "readInt()"}, - {"short", "readShort()"}, - {"long", "readLong()"}, - {"string", "readString()"}, - {"bool", "readBoolean()"}, - {"float", "readFloat()"}, - {"double", "readDouble()"}, - {"bundle", "readBundle()"}, - {"file", "readString()"} + {"char", "Byte"}, + {"int", "Int"}, + {"short", "Short"}, + {"long", "Long"}, + {"string", "String"}, + {"bool", "Boolean"}, + {"float", "Float"}, + {"double", "Double"}, + {"bundle", "Bundle"}, + {"file", "String"} }; } @@ -77,6 +78,7 @@ void JavaCionGeneratorBase::GenMethodId(std::ofstream& stream, << "public static final int __" << i->GetID() << " = " << cnt++ << ";" << NLine(1); } + stream << NLine(1); } void JavaCionGeneratorBase::GenDeclaration(std::ofstream& stream, @@ -119,15 +121,17 @@ std::string JavaCionGeneratorBase::GetParameters(const Parameters& ps) { } auto dir = i->GetParameterType().GetDirection(); - if (dir == ParameterType::Direction::OUT) - ret += "Out<"; - else if (dir == ParameterType::Direction::REF) - ret += "Ref<"; - - ret += ConvertTypeToString(i->GetParameterType().GetBaseType()); - if (dir == ParameterType::Direction::OUT - || dir == ParameterType::Direction::REF) - ret += ">"; + if (dir == ParameterType::Direction::OUT) { + ret += "Out<" + + ConvertTypeToString(i->GetParameterType().GetBaseType(), true) + + ">"; + } else if (dir == ParameterType::Direction::REF) { + ret += "Ref<" + + ConvertTypeToString(i->GetParameterType().GetBaseType(), true) + + ">"; + } else { + ret += ConvertTypeToString(i->GetParameterType().GetBaseType()); + } ret += " " + i->GetID(); first = false; @@ -137,15 +141,15 @@ std::string JavaCionGeneratorBase::GetParameters(const Parameters& ps) { } std::string JavaCionGeneratorBase::GetViewModelName(std::string id) { - return id + FileName + "ViewModel"; + return id + "ViewModel"; } std::string JavaCionGeneratorBase::GetRepoClassName(std::string id) { - return id + FileName + "Repo"; + return id + "Repo"; } std::string JavaCionGeneratorBase::GetServiceBaseClassName(std::string id) { - return id + FileName + "ServiceBase"; + return id; } std::string JavaCionGeneratorBase::GetParcelReader( @@ -156,8 +160,7 @@ std::string JavaCionGeneratorBase::GetParcelReader( ret_str += Tab(tab_size) + ConvertTypeToString(type); ret_str += " " + variable_name + " = "; ret_str += "new " + ConvertTypeToString(type) + "();" + NLine(1); - ret_str += Tab(tab_size) + parcel_name + " = " + - variable_name + ".deserialize(" + parcel_name + ");" + NLine(1); + ret_str += Tab(tab_size) + variable_name + ".deserialize(" + parcel_name + ");" + NLine(1); return ret_str; } @@ -185,10 +188,10 @@ std::string JavaCionGeneratorBase::GetParcelReader( if (assign) { ret_str += Tab(tab_size) + ConvertTypeToString(type); ret_str += " " + variable_name + " = " + parcel_name + "." - + parcel_reader_map_[type.ToString()] + ";"; + + "read" + parcel_reader_map_[type.ToString()] + "();"; } else { ret_str += Tab(tab_size) + parcel_name + "." - + parcel_reader_map_[type.ToString()]; + + "read" + parcel_reader_map_[type.ToString()] + "();"; } return ret_str; @@ -238,4 +241,450 @@ std::string JavaCionGeneratorBase::MakeDir(const std::string& file_name, return fname; } +void JavaCionGeneratorBase::GenSerializer(std::ofstream& stream, + const Structure& st) { + stream << Tab(1) << "private static void serialize(CionParcel h, " + << st.GetID() << " param) "; + GenBrace(stream, TAB_SIZE * 1, [&]() { + for (auto& i : st.GetElements().GetElms()) { + auto& t = i->GetType(); + if (!t.IsUserDefinedType() && t.GetMetaType() == nullptr) { + stream << Tab(2) << "h.write" + << "(param.get" + << i->GetID() + << "());" << NLine(1); + } else { + if (t.GetMetaType() != nullptr) { + stream << Tab(2) << "serialize(h, param.get" << i->GetID() + << "(), null);" << NLine(1); + } else { + stream << Tab(2) << "serialize(h, param.get" << i->GetID() + << "());" << NLine(1); + } + } + } + }, false); + stream << NLine(1); + stream << Tab(1) << "private static void deserialize(CionParcel h, " + << st.GetID() << " param) "; + GenBrace(stream, TAB_SIZE * 1, [&]() { + for (auto& i : st.GetElements().GetElms()) { + auto& t = i->GetType(); + if (!t.IsUserDefinedType() && t.GetMetaType() == nullptr) { + stream << Tab(2) << ConvertTypeToString(t) + << " " << i->GetID() << " = " + << "h.read" + << ConvertTypeToParcelType(t.ToString()) + << "();" << NLine(1); + stream << Tab(2) << "param.set" << i->GetID() << "(" << i->GetID() + << ");" << NLine(1); + } else { + stream << Tab(2) << "param.set" << i->GetID() << "(new " + << ConvertTypeToString(t) + << "());" << NLine(1); + if (t.GetMetaType() != nullptr) { + stream << Tab(2) << "deserialize(h, param.get" << i->GetID() + << "(), null);" << NLine(1); + } else { + stream << Tab(2) << "deserialize(h, param.get" << i->GetID() + << "());" << NLine(1); + } + } + } + }, false); + stream << NLine(1); +} + +void JavaCionGeneratorBase::GenSerializer(std::ofstream& stream) { + for (auto& i : GetDocument().GetBlocks()) { + if (i->GetType() == Block::TYPE_STRUCTURE) { + const Structure& st = static_cast(*i); + GenSerializer(stream, st); + } + } +} + +void JavaCionGeneratorBase::GenListSerializer(std::ofstream& stream, + const BaseType& type) { + stream << Tab(1) << "private static void serialize(CionParcel h, " + << ConvertTypeToString(type) << " param, " + << ConvertTypeToString(*(type.GetMetaType()), true) << " a) "; + GenBrace(stream, TAB_SIZE, [&]() { + stream << Tab(2) + << "h.write(param.size());" + << NLine(1); + stream << Tab(2) << "for (" << ConvertTypeToString(*(type.GetMetaType()), true) + << " i : param) "; + GenBrace(stream, TAB_SIZE * 2, [&]() { + auto* ptr = type.GetMetaType(); + if (ptr == nullptr) return; + + auto& mt = *ptr; + if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) { + stream << Tab(3) << "h.write(i);" << NLine(1); + } else { + if (mt.GetMetaType() != nullptr) { + stream << Tab(3) << "serialize(h, i, null);" << NLine(1); + } else { + stream << Tab(3) << "serialize(h, i);" << NLine(1); + } + } + }, false); + }, false); + stream << NLine(1); + + stream << Tab(1) << "private static void deserialize(CionParcel h, " + << ConvertTypeToString(type) << " param, " + << ConvertTypeToString(*(type.GetMetaType()), true) << " a) "; + GenBrace(stream, TAB_SIZE, [&]() { + stream << Tab(2) + << "int l = h.readInt();" + << NLine(1); + stream << Tab(2) << "for (int i = 0; i < l; i++) "; + GenBrace(stream, TAB_SIZE * 2, [&]() { + auto* ptr = type.GetMetaType(); + if (ptr == nullptr) + return; + + auto& mt = *ptr; + if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) { + stream << Tab(3) << ConvertTypeToString(*(type.GetMetaType()), true) + << " v = h.read" + << ConvertTypeToParcelType(mt.ToString()) + << "();" << NLine(1); + } else { + stream << Tab(3) << ConvertTypeToString(*(type.GetMetaType()), true) + << " v = new " << ConvertTypeToString(mt) + << "();" << NLine(1); + if (mt.GetMetaType() != nullptr) { + stream << Tab(3) << "deserialize(h, v, null);" << NLine(1); + } else { + stream << Tab(3) << "deserialize(h, v);" << NLine(1); + } + } + if (type.ToString() == "list") + stream << Tab(3) << "param.addLast(v);" << NLine(1); + else + stream << Tab(3) << "param.add(v);" << NLine(1); + }, false); + }, false); + stream << NLine(1); +} + +void JavaCionGeneratorBase::GenListSerializer(std::ofstream& stream) { + serializer_list_.clear(); + for (auto& i : GetDocument().GetBlocks()) { + if (i->GetType() == Block::TYPE_STRUCTURE) { + const Structure& st = static_cast(*i); + for (auto& j : st.GetElements().GetElms()) { + auto& t = j->GetType(); + AddSerializerList(t); + } + } else if (i->GetType() == Block::TYPE_INTERFACE) { + const Interface& iface = static_cast(*i); + for (auto& j : iface.GetDeclarations().GetDecls()) { + auto& t = j->GetType(); + AddSerializerList(t); + for (auto& k : j->GetParameters().GetParams()) { + auto& t1 = k->GetParameterType().GetBaseType(); + AddSerializerList(t1); + } + } + } + } + + for (auto& p : serializer_list_) { + const BaseType* t = p.second; + GenListSerializer(stream, *t); + } +} + +void JavaCionGeneratorBase::AddSerializerList(const BaseType& type) { + if (type.GetMetaType() != nullptr) { + serializer_list_[ConvertTypeToString(type)] = &type; + AddSerializerList(*type.GetMetaType()); + } +} + +std::string JavaCionGeneratorBase::ConvertTypeToParcelType(const std::string& key) { + return parcel_reader_map_[key]; +} + +void JavaCionGeneratorBase::GenCallbacks(std::ofstream& stream, + const Interface& iface, bool is_proxy) { + for (auto& i : iface.GetDeclarations().GetDecls()) { + if (i->GetMethodType() != Declaration::MethodType::DELEGATE) + continue; + if (is_proxy) + GenCallbackProxy(stream, *i, iface.GetID()); + else + GenCallbackStub(stream, *i, iface.GetID()); + } +} + +void JavaCionGeneratorBase::GenCallbackProxy(std::ofstream& stream, + const Declaration& decl, const std::string& id) { + std::string str; + + str = ReplaceAll(CB_CALLBACK_CLASS_PROXY, "", decl.GetID()); + str = ReplaceAll(str, "", + GetParameters(decl.GetParameters())); + str = ReplaceAll(str, "", + GetOnInvoked(decl, id)); + str = ReplaceAll(str, "",id); + str = ReplaceAll(str, "",decl.GetID()); + stream << str; + stream << NLine(1); +} + +void JavaCionGeneratorBase::GenCallbackStub(std::ofstream& stream, + const Declaration& decl, const std::string& id) { + std::string str; + str = ReplaceAll(CB_CALLBACK_CLASS_STUB, "", decl.GetID()); + str = ReplaceAll(str, "", + GetParameters(decl.GetParameters())); + str = ReplaceAll(str, "",id); + str = ReplaceAll(str, "",decl.GetID()); + + std::string ser; + for (auto& i : decl.GetParameters().GetParams()) { + auto& pt = i->GetParameterType(); + ser += ConvertTypeToSerializer(pt.GetBaseType(), i->GetID(), "p", id); + } + + ser = AddIndent(TAB_SIZE * 3, ser); + str = ReplaceAll(str, "", ser); + + std::string share; + for (auto& i : decl.GetParameters().GetParams()) { + auto& pt = i->GetParameterType(); + if(HasFile(pt.GetBaseType())) + share += "_serverBase.shareFile(" + i->GetID() + ");\n"; + } + + share = AddIndent(TAB_SIZE * 3, share); + str = ReplaceAll(str, "", share); + + stream << str; + stream << NLine(1); +} + +std::string JavaCionGeneratorBase::GetOnInvoked(const Declaration& decl, + const std::string& id) { + std::string str; + int cnt = 1; + for (auto& i : decl.GetParameters().GetParams()) { + std::string v = "param" + std::to_string(cnt); + std::string c = ConvertTypeToDeserializer( + i->GetParameterType().GetBaseType(), v, "parcel", true, id); + str += AddIndent(TAB_SIZE * 3, c); + cnt++; + } + + cnt = 1; + str += Tab(3); + str += "onInvoked("; + for (int i = 0; i < decl.GetParameters().GetParams().size(); i++) { + if (cnt != 1) { + str += ", "; + } + std::string v = "param" + std::to_string(cnt); + str += v; + cnt++; + } + str += ");"; + + return str; +} + +std::string JavaCionGeneratorBase::ConvertTypeToSerializer( + const BaseType& type, std::string id, std::string parcel, + std::string iface_id) { + std::string ret; + + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr) { + if (IsDelegateType(type)) + return "DelegatorBase.serialize(" + parcel + ", " + id + ");\n"; + if (iface_id != "") + ret += iface_id + "."; + if (type.GetMetaType() != nullptr) + ret += "serialize(" + parcel + ", " + id + ", null);\n"; + else + ret += "serialize(" + parcel + ", " + id + ");\n"; + return ret; + } + + ret += parcel + ".write(" + id + ");\n"; + + return ret; +} + +std::string JavaCionGeneratorBase::ConvertTypeToDeserializer( + const BaseType& type, std::string id, std::string parcel, + bool make_new_type, std::string iface_id, bool setter) { + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr) { + std::string n; + + if (type.GetMetaType() != nullptr) + n = ConvertTypeToString(type); + else + n = type.ToString(); + + std::string ret; + + if (make_new_type) + ret = n + " "; + + if (IsDelegateType(type)) { + ret += id + " = new " + n + + "(info, new WeakReference(b));\n"; + ret += "DelegatorBase."; + } else { + ret += id + " = new " + n +"();\n"; + } + if (iface_id != "") + ret += iface_id + "."; + + if (type.GetMetaType() != nullptr) + ret += "deserialize(" + parcel + ", " + id + ", null);\n"; + else + ret += "deserialize(" + parcel + ", " + id + ");\n"; + return ret; + } + + std::string ret; + if (make_new_type) { + ret = ConvertTypeToString(type) + " " + + id + " = " + parcel + ".read" + + parcel_reader_map_[type.ToString()] + + "();\n"; + } else if (!setter) { + ret = id + " = " + parcel + ".read" + + parcel_reader_map_[type.ToString()] + + "();\n"; + } else { + ret = id + ".set(" + parcel + ".read" + + parcel_reader_map_[type.ToString()] + + "());\n"; + } + + return ret; +} + +bool JavaCionGeneratorBase::HasFile(const BaseType& type) { + if (type.ToString() == "list" || type.ToString() == "array") { + std::string name = GetFullNameFromType(type); + if (name == "array_file" || name == "list_file" || name == "file") + return true; + } else if (type.ToString() == "file") { + return true; + } + + return false; +} + +std::string JavaCionGeneratorBase::GetFullNameFromType(const BaseType& type) { + std::string str; + + str += type.ToString(); + + if (type.GetMetaType() != nullptr) { + str += "_"; + str += GetFullNameFromType(*type.GetMetaType()); + } + + return str; +} + +void JavaCionGeneratorBase::GenVersion(std::ofstream& stream) { + GenTemplate(::CB_CION_JAVA_VERSION, stream, + [&]()->std::string { + return FULLVER; + }); + stream << NLine(1); +} + +void JavaCionGeneratorBase::GenDelegateId(std::ofstream& stream, + const Interface& iface) { + int cnt = 1; + for (auto& i : iface.GetDeclarations().GetDecls()) { + if (i->GetMethodType() != Declaration::MethodType::DELEGATE) + continue; + stream << Tab(1) << "private static final int __" + << i->GetID() << " = " << cnt++ << ";" << NLine(1); + } + stream << NLine(1); +} + +void JavaCionGeneratorBase::GenShareFile(std::ofstream& stream, + const Interface& iface, bool is_proxy) { + bool hasFile = false; + + for (auto& d : iface.GetDeclarations().GetDecls()) { + hasFile = HasFile(iface, *d, is_proxy); + if (hasFile == true) + break; + } + + if (hasFile == false) + return; + + stream << CB_SHARE_FILE_DEF << NLine(1); +} + +std::string JavaCionGeneratorBase::GetFullNameFromType(const BaseType& type, + const Interface& iface) { + std::string str; + if (IsDelegateType(iface, type)) + str += iface.GetID() + "_"; + + str += type.ToString(); + + if (type.GetMetaType() != nullptr) { + str += "_"; + str += GetFullNameFromType(*type.GetMetaType(), iface); + } + + return str; +} + +bool JavaCionGeneratorBase::HasFile(const Interface& iface, const BaseType& type) { + if (type.ToString() == "list" || type.ToString() == "array") { + std::string name = GetFullNameFromType(type, iface); + if (name == "array_file" || name == "list_file" || name == "file") + return true; + } else if (type.ToString() == "file") { + return true; + } + + return false; +} + +bool JavaCionGeneratorBase::HasFile(const Interface& iface, const Declaration& decl, bool is_proxy) { + for (auto& p : decl.GetParameters().GetParams()) { + auto& param_type = p->GetParameterType(); + if (is_proxy) { + if (param_type.GetDirection() != ParameterType::Direction::IN) + continue; + } else if (decl.GetMethodType() == Declaration::MethodType::DELEGATE) { + if (param_type.GetDirection() != ParameterType::Direction::IN) + continue; + } else { + if (param_type.GetDirection() == ParameterType::Direction::IN) + continue; + } + + if (HasFile(iface, param_type.GetBaseType()) == true) + return true; + } + + if (is_proxy) + return false; + + return HasFile(iface, decl.GetType()); +} + + } // namespace tidl diff --git a/idlc/gen_cion/java_cion_gen_base.h b/idlc/gen_cion/java_cion_gen_base.h index c84419b..9ed0db7 100644 --- a/idlc/gen_cion/java_cion_gen_base.h +++ b/idlc/gen_cion/java_cion_gen_base.h @@ -34,20 +34,48 @@ class JavaCionGeneratorBase : public Generator { void GenMethodId(std::ofstream& stream, const Interface& iface); void GenDeclaration(std::ofstream& stream, - const Declaration& decl, bool semicol); + const Declaration& decl, bool semicol = true); void GenParameters(std::ofstream& stream, const Parameters& ps); std::string ConvertTypeToString(const BaseType& type, bool is_meta = false); std::string GetParameters(const Parameters& ps); std::string GetParcelReader(const BaseType& type, std::string parcel_name, std::string variable_name, int tab_size, bool assign = true); + std::string GetOnInvoked(const Declaration& decl, const std::string& id); std::string GetRepoClassName(std::string id); std::string GetServiceBaseClassName(std::string id); std::string GetViewModelName(std::string id); + void GenSerializer(std::ofstream& stream, const Structure& st); + void GenSerializer(std::ofstream& stream); + void GenListSerializer(std::ofstream& stream, const BaseType& type); + void GenListSerializer(std::ofstream& stream); + void GenCallbacks(std::ofstream& stream, const Interface& iface, bool is_proxy); + void GenCallbackProxy(std::ofstream& stream, const Declaration& decl, + const std::string& id); + void GenCallbackStub(std::ofstream& stream, const Declaration& decl, + const std::string& id); + + std::string ConvertTypeToSerializer(const BaseType& type, std::string id, + std::string parcel, std::string iface_id = ""); + std::string ConvertTypeToDeserializer(const BaseType& type, std::string id, + std::string parcel, bool make_new_type = true, + std::string iface_id = "", bool setter = false); + + std::string ConvertTypeToParcelType(const std::string& key); + void AddSerializerList(const BaseType& type); std::string Tab(int cnt); std::string NLine(int cnt); std::string MakeDir(const std::string& file_name, const std::string& opt); + bool HasFile(const BaseType& type); + bool HasFile(const Interface& iface, const BaseType& type); + bool HasFile(const Interface& iface, const Declaration& decl, bool is_proxy); + std::string GetFullNameFromType(const BaseType& type); + std::string GetFullNameFromType(const BaseType& type, const Interface& iface); + void GenVersion(std::ofstream& stream); + void GenDelegateId(std::ofstream& stream, const Interface& iface); + void GenShareFile(std::ofstream& stream, const Interface& iface, + bool is_proxy); protected: const int TAB_SIZE = 4; @@ -56,6 +84,7 @@ class JavaCionGeneratorBase : public Generator { std::map type_map_; std::map meta_type_map_; std::map parcel_reader_map_; + std::map serializer_list_; }; } // namespace tidl diff --git a/idlc/gen_cion/java_cion_gen_cb.h b/idlc/gen_cion/java_cion_gen_cb.h index 832af7c..d9cb032 100644 --- a/idlc/gen_cion/java_cion_gen_cb.h +++ b/idlc/gen_cion/java_cion_gen_cb.h @@ -17,109 +17,6 @@ #ifndef IDLC_GEN_CION_JAVA_CION_GEN_CB_H_ #define IDLC_GEN_CION_JAVA_CION_GEN_CB_H_ -const char DEFAULT_STUB_FUNCTIONS[] = -R"__java_cb( - - public void acceptRequest(ConnectedPeer peer) { - repo.acceptRequest(peer); - } - - public void rejectRequest(ConnectedPeer peer, String reason) { - repo.rejectRequest(peer, reason); - } - - public void disconnectPeer(ConnectedPeer peer) { - repo.disconnect(peer); - } - - public void listen() { - repo.listen(); - } - - public LiveData> getConnectedPeerLiveData() { - return connectedPeerLiveData; - } - - public LiveData getLogsLiveData() { - return logsLiveData; - } - - public LiveData getReceivedDataLiveData() { - return receivedDataLiveData; - } - - public LiveData getReceivedPayloadLiveData() { - return receivedPayloadLiveData; - } - - public void setSyncResponse(byte[] data) { - repo.setSyncResponse(data); - } - - public void registerService(## service) { - this.service = service; - } - -)__java_cb"; - - -const char DEFAULT_PROXY_FUNCTIONS[] = -R"__java_cb( - private void sendAsync(FilePayload payload) { - repo.sendAsync(payload); - } - - private void sendAsync(DataPayload payload) { - repo.sendAsync(payload); - } - - private byte[] sendData(byte[] data) { - return repo.sendData(data); - } - - public void tryDiscovery() { - repo.tryDiscovery(); - } - - public void tryConnect(DiscoveredPeer peer) { - repo.tryConnect(peer); - } - - public void disconnect(DiscoveredPeer peer) { - repo.disconnect(peer); - } - - public LiveData> getDiscoveredPeerLiveData() { - return discoveredPeerLiveData; - } - - public LiveData getReceivedPayloadInfoLiveData() { - return receivedPayloadInfoLiveData; - } - - public void processReceivedEvent(CionParcel parcel) { - int method = parcel.readInt(); - if (method != __CALLBACK) - return; - - int id = parcel.readInt(); - int seq_id = parcel.readInt(); - boolean once = (parcel.readByte() == 1); - for (int i = 0; i < delegators.size(); i++) { - if (id == delegators.get(i).getDelegateId() - && seq_id == delegators.get(i).getSequenceId()) { - delegators.get(i).onInvoked(parcel); - if (once) - delegators.remove(i); - break; - } - } - } - - public LiveData getLogsLiveData() { - return logsLiveData; - } -)__java_cb"; const char DEFAULT_PROXY_REPO[] = R"__java_cb( @@ -127,126 +24,44 @@ R"__java_cb( import android.content.Context; import androidx.lifecycle.MutableLiveData; -import org.tizen.cion.ClientChannel; -import org.tizen.cion.ClientConnectionLifecycleCallback; -import org.tizen.cion.ConnectionResult; -import org.tizen.cion.DataPayload; -import org.tizen.cion.DiscoveryCallback; -import org.tizen.cion.FilePayload; -import org.tizen.cion.IPayload; -import org.tizen.cion.PayloadAsyncResult; -import org.tizen.cion.PayloadAsyncResultCallback; -import org.tizen.cion.PayloadTransferStatus; -import org.tizen.cion.PeerInfo; +import org.tizen.cion.*; import java.net.SocketTimeoutException; import java.util.ArrayList; -public class ## { +public abstract class ClientBase implements DiscoveryCallback, + ClientConnectionLifecycleCallback, PayloadAsyncResultCallback { private ClientChannel client; - private MutableLiveData> discoveredPeerLiveData; - private MutableLiveData receivedPayloadInfoLiveData; - private static volatile ## instance; private Context context; - private MutableLiveData logsLiveData; - private ##(Context context, String serviceName) { - discoveredPeerLiveData = new MutableLiveData<>(); - discoveredPeerLiveData.setValue(new ArrayList()); - logsLiveData = new MutableLiveData<>(); - logsLiveData.setValue(""); + public ClientBase(Context context, String serviceName) { client = new ClientChannel(context, serviceName); this.context = context; } - public static ## getInstance(Context context, String serviceName) { - if (instance == null) { - synchronized (##.class) { - instance = new ##(context, serviceName); - } - } - return instance; + public ClientBase(Context context, String serviceName, SecurityInfo sec) { + client = new ClientChannel(context, serviceName, sec); + this.context = context; } - public void disconnect(DiscoveredPeer peer) { + public void disconnect() { client.disconnect(); } - public void writeLog(String log) { - String logs = logsLiveData.getValue(); - if (!logs.isEmpty()) - logs += "\n"; - logs += log; - logsLiveData.postValue(logs); - } - - public void tryConnect(DiscoveredPeer peer) { - client.tryConnect(peer.getPeerInfo(), new ClientConnectionLifecycleCallback() { - @Override - public void onConnectionResult(PeerInfo info, ConnectionResult result) { - writeLog("Peer : " + info.getUuid() + ", Connection result : " + result); - ArrayList peers = discoveredPeerLiveData.getValue(); - for (int i = 0; i < peers.size(); i++) { - if (peers.get(i).equals(peer)) { - peer.setIsConnected(result.status == ConnectionResult.ConnectionStatus.CONNECTION_OK); - peers.set(i, peer); - break; - } - } - discoveredPeerLiveData.postValue(peers); - } - - @Override - public void onDisconnected(PeerInfo info) { - writeLog("Peer disconnected : " + info.getUuid()); - ArrayList peers = discoveredPeerLiveData.getValue(); - for (int i = 0; i < peers.size(); i++) { - if (peers.get(i).getPeerInfo().getUuid() == info.getUuid()) { - peer.setIsConnected(false); - peers.set(i, peer); - break; - } - } - discoveredPeerLiveData.postValue(peers); - } - - @Override - public void onPayloadReceived(IPayload data, PayloadTransferStatus status) { - writeLog("onPayloadReceived " + status); - receivedPayloadInfoLiveData.postValue(new ReceivedPayloadInfo(data, status)); - } - }); + public void tryConnect(PeerInfo peer) { + client.tryConnect(peer, this); } public void tryDiscovery() { - writeLog("Try discovery !!"); - client.tryDiscovery(new DiscoveryCallback() { - @Override - public void onDiscovered(PeerInfo info) { - ArrayList peers = discoveredPeerLiveData.getValue(); - peers.add(new DiscoveredPeer(info, false)); - discoveredPeerLiveData.postValue(peers); - writeLog("Peer discovered :" + info.getUuid()); - } - }); + client.tryDiscovery(this); } public void sendAsync(DataPayload payload) { - client.sendPayloadAsync(payload, new PayloadAsyncResultCallback() { - @Override - public void onResultReceived(PayloadAsyncResult result) { - writeLog("Async result " + result.toString()); - } - }); + client.sendPayloadAsync(payload, this); } public void sendAsync(FilePayload payload) { - client.sendPayloadAsync(payload, new PayloadAsyncResultCallback() { - @Override - public void onResultReceived(PayloadAsyncResult result) { - writeLog("Async result " + result.toString()); - } - }); + client.sendPayloadAsync(payload, this); } public byte[] sendData(byte[] data) { @@ -257,18 +72,6 @@ public class ## { } return null; } - - public MutableLiveData> getDiscoveredPeerLiveData() { - return discoveredPeerLiveData; - } - - public MutableLiveData getReceivedPayloadInfoLiveData() { - return receivedPayloadInfoLiveData; - } - - public MutableLiveData getLogsLiveData() { - return logsLiveData; - } } )__java_cb"; @@ -280,171 +83,61 @@ import android.content.Context; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; -import org.tizen.cion.ConnectionResult; -import org.tizen.cion.DataPayload; -import org.tizen.cion.IPayload; -import org.tizen.cion.PayloadAsyncResult; -import org.tizen.cion.PayloadAsyncResultCallback; -import org.tizen.cion.PayloadTransferStatus; -import org.tizen.cion.PeerInfo; -import org.tizen.cion.ServerChannel; -import org.tizen.cion.ServerConnectionLifecycleCallback; +import org.tizen.cion.*; import java.util.ArrayList; import java.util.concurrent.BlockingDeque; import java.util.concurrent.TimeUnit; -public class ## { +public abstract class ServerBase implements ServerConnectionLifecycleCallback { private ServerChannel server; - private MutableLiveData> connectedPeerLiveData; - private MutableLiveData receivedPayloadInfoLiveData; - private MutableLiveData receivedDataInfoLiveData; - private static volatile ## instance; private Context context; - private MutableLiveData logsLiveData; - private BlockingDeque syncCallRespQue; - - private ##(Context context, String serviceName, String displayName) { - connectedPeerLiveData = new MutableLiveData<>(); - connectedPeerLiveData.setValue(new ArrayList()); - logsLiveData = new MutableLiveData<>(); - logsLiveData.setValue(""); + private String serviceName; + private String displayName; + + public ServerBase(Context context, String serviceName, String displayName) { server = new ServerChannel(context, serviceName, displayName); this.context = context; + this.serviceName = serviceName; + this.displayName = displayName; + } + + public ServerBase(Context context, String serviceName, String displayName, SecurityInfo sec) { + server = new ServerChannel(context, serviceName, displayName, sec); + this.context = context; + this.serviceName = serviceName; + this.displayName = displayName; } - public LiveData getReceivedDataInfoLiveData() { - return receivedDataInfoLiveData; + public String getServiceName() { + return serviceName; } - public LiveData getReceivedPayloadInfoLiveData() { - return receivedPayloadInfoLiveData; + public String getDisplayName() { + return displayName; } - public void writeLog(String log) { - String logs = logsLiveData.getValue(); - if (!logs.isEmpty()) - logs += "\n"; - logs += log; - logsLiveData.postValue(logs); + public void listen() { + server.listen(this); } - public static ## getInstance( - Context context, String serviceName, String displayName) { - if (instance == null) { - synchronized (##.class) { - instance = new ##(context, serviceName, displayName); - } - } - return instance; + public void stop() { + server.stop(); } - public void setSyncResponse(byte[] response) { - try { - syncCallRespQue.offer(response, 5000, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - e.printStackTrace(); - } + public void disconnect(PeerInfo peerInfo) { + server.disconnect(peerInfo); } - public void acceptRequest(ConnectedPeer peer) { - ArrayList peers = connectedPeerLiveData.getValue(); - for (int i = 0; i < peers.size(); i++) { - if (peers.get(i).equals(peer)) { - peer.setIsConnected(true); - peers.set(i, peer); - writeLog("Accept peer: " + peer.isConnected()); - break; - } - } - connectedPeerLiveData.postValue(peers); - server.acceptRequest(peer.getPeerInfo()); - writeLog("Accept peer: " + peer.isConnected()); - } - - public void rejectRequest(ConnectedPeer peer, String reason) { - ArrayList peers = connectedPeerLiveData.getValue(); - for (int i = 0; i < peers.size(); i++) { - if (peers.get(i).equals(peer)) { - peer.setIsConnected(false); - peers.set(i, peer); - break; - } - } - connectedPeerLiveData.postValue(peers); - server.rejectRequest(peer.getPeerInfo(), reason); - writeLog("Reject peer: " + peer.isConnected()); - } - - public void disconnect(ConnectedPeer peer) { - ArrayList peers = connectedPeerLiveData.getValue(); - for (int i = 0; i < peers.size(); i++) { - if (peers.get(i).equals(peer)) { - peer.setIsConnected(false); - peers.set(i, peer); - break; - } - } - connectedPeerLiveData.postValue(peers); - server.disconnect(peer.getPeerInfo()); - writeLog("Disconnect peer: " + peer.isConnected()); + public void sendPayloadAsync(IPayload payload) { } - public void listen() { - server.listen(new ServerConnectionLifecycleCallback() { - @Override - public void onConnectionRequest(PeerInfo info) { - writeLog("OnConnection request from " + info.getUuid()); - ArrayList peers = connectedPeerLiveData.getValue(); - peers.add(new ConnectedPeer(info, false)); - connectedPeerLiveData.postValue(peers); - } - - @Override - public void onConnectionResult(PeerInfo info, ConnectionResult result) { - writeLog("OnConnectionResult " + result + ", uuid :" + info.getUuid()); - writeLog("Connection result: " + info.getDeviceName() + " : " + result.status); - } - - @Override - public void onPayloadReceived(PeerInfo info, IPayload data, PayloadTransferStatus status) { - writeLog("onPayloadReceived " + status + ", uuid :" + info.getUuid()); - receivedPayloadInfoLiveData.postValue(new ReceivedPayloadInfo(info, data, status)); - } - - @Override - public byte[] onDataReceived(PeerInfo info, byte[] data) { - writeLog("Payload received : " + new String(data)); - writeLog("onDataReceived length : " + data.length + ", uuid :" + info.getUuid()); - receivedDataInfoLiveData.postValue(new ReceivedDataInfo(info, data)); - byte[] ret = null; - try { - // block until response data is filled - ret = syncCallRespQue.take(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - return ret; - } - }); - writeLog("Listen start"); - } - - public MutableLiveData> getConnectedPeerLiveData() { - return connectedPeerLiveData; - } - - public MutableLiveData getLogsLiveData() { - return logsLiveData; + public void accept(PeerInfo peerInfo) { + server.acceptRequest(peerInfo); } - public void sendAsync(DataPayload payload) { - server.sendPayloadAsync(payload, new PayloadAsyncResultCallback() { - @Override - public void onResultReceived(PayloadAsyncResult result) { - writeLog("Async result " + result.toString()); - } - }); + public void reject(PeerInfo peerInfo, String reason) { + server.rejectRequest(peerInfo, reason); } } @@ -472,7 +165,7 @@ public class Out { const char REF_CLASS[] = R"__java_cb( -class Ref { +public class Ref { T s; public void set(T value) { s = value; @@ -489,228 +182,176 @@ class Ref { )__java_cb"; -const char RECEIVED_PAYLOAD_INFO_CLASS[] = -R"__java_cb( - -import org.tizen.cion.IPayload; -import org.tizen.cion.PayloadTransferStatus; -import org.tizen.cion.PeerInfo; - -public class ReceivedPayloadInfo { - private PeerInfo info; - private IPayload data; - private PayloadTransferStatus status; - - public ReceivedPayloadInfo(PeerInfo info, IPayload data, PayloadTransferStatus status) { - this.info = info; - this.data = data; - this.status = status; - } - - public ReceivedPayloadInfo(IPayload data, PayloadTransferStatus status) { - this.data = data; - this.status = status; - } - - public PeerInfo getInfo() { - return info; - } - - public IPayload getData() { - return data; - } - - public PayloadTransferStatus getStatus() { - return status; - } -} - -)__java_cb"; - -const char RECEIVED_DATA_INFO_CLASS[] = -R"__java_cb( - -import org.tizen.cion.PeerInfo; - -public class ReceivedDataInfo { - private PeerInfo info; - private byte[] data; - - public ReceivedDataInfo(PeerInfo info, byte[] data) { - this.info = info; - this.data = data; - } - - public PeerInfo getInfo() { - return info; - } - public byte[] getData() { - return data; - } -} - -)__java_cb"; - -const char PROXY_DELEGATOR_TOP[] = +const char DELEGATOR_BASE[] = R"__java_cb( import org.tizen.cion.CionParcel; -public abstract class ProxyDelegator { - private int delegateId; +public abstract class DelegatorBase { + private int id; + private int seqId; private boolean once; - private static int sequenceId = 0; - - )__java_cb"; + private static int _seqNum = 0; + -const char PROXY_DELEGATOR_BOTTOM[] = -R"__java_cb( - public ProxyDelegator(int delegateId, boolean once) { - this.delegateId = delegateId; + public DelegatorBase(int delegateId, boolean once) { + this.id = delegateId; + this.seqId = _seqNum++; this.once = once; - this.sequenceId++; } public abstract void onInvoked(CionParcel parcel); public int getDelegateId() { - return delegateId; + return id; + } + + public int getSequenceId() { + return seqId; } public boolean isOnce() { return once; } - public int getSequenceId() { - return sequenceId; + public static void serialize(CionParcel h, DelegatorBase from) { + h.write(from.id); + h.write(from.seqId); + h.write(from.once); } - public CionParcel serialize(CionParcel parcel) { - parcel.write(delegateId); - parcel.write(once); - parcel.write(sequenceId); - return parcel; + public static void deserialize(CionParcel h, DelegatorBase to) { + to.id = h.readInt(); + to.seqId = h.readInt(); + to.once = h.readBoolean(); + } + + public String getTag() { + return (new Integer(id).toString()) + "_" + (new Integer(seqId).toString()); } } )__java_cb"; -const char CONNECTED_PEER[] = +const char CB_CALLBACK_CLASS_PROXY[] = R"__java_cb( -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import org.tizen.cion.PeerInfo; + public static final class extends DelegatorBase { -public final class ConnectedPeer { + public (boolean once) { + super(DelegatorBase.___, once); + } - @NonNull - private final PeerInfo info; + public () { + super(DelegatorBase.___, false); + } - @NonNull - private boolean isConnected; + @Override + public void onInvoked(CionParcel parcel) { + + } - public ConnectedPeer(@NonNull PeerInfo info, @NonNull boolean isConnected) { - this.info = info; - this.isConnected = isConnected; + public void onInvoked() {} } +)__java_cb"; - public void setIsConnected(boolean isConnected) { this.isConnected = isConnected; } - - public boolean isConnected() { return isConnected; } - - public PeerInfo getPeerInfo() { return info; } - - public String getPeerDeviceName() { - return info.getDeviceName(); - } +const char CB_CALLBACK_CLASS_STUB[] = +R"__java_cb( + public static final class extends DelegatorBase { + private PeerInfo peerInfo; + private WeakReference service; + private boolean valid = true; + private serverBase; + + public (PeerInfo info, WeakReference service) { + super(DelegatorBase.___, false); + this.peerInfo = info; + this.service = service; + this.serverBase = () service.get().serverBase; + } - public String getPeerDevicePlatform() { - return info.getDevicePlatform(); + @Override + public void onInvoked(CionParcel parcel) {} + + public void Invoke() { + if (service.get() == null) + throw new InvalidProtocolException(); + if (isOnce() && !valid) + throw new InvalidCallbackException(); + + CionParcel p = new CionParcel(); + + p.write(__CALLBACK); + serialize(p, this); + + // Send + DataPayload dp = new DataPayload(p.toByteArray()); + serverBase.sendPayloadAsync(dp); + valid = false; + + } } +)__java_cb"; - public int getPeerChannelId() { - return info.getChannelId(); - } +const char CB_SHARE_FILE_DEF[] = +R"__java_cb( + private void shareFile(List paths) { + if (paths == null) + throw new InvalidArgumentException(); - @NonNull - @Override - public String toString() { - return info.getUuid(); + for (String path : paths) { + shareFile(path); + } } - @Override - public boolean equals(@Nullable Object obj) { - return obj instanceof ConnectedPeer - && this.info.getUuid().equals(((ConnectedPeer) obj).info.getUuid()); - } + private void shareFile(String path) { + if (path == null) + throw new InvalidArgumentException(); - @Override - protected Object clone() { - return new DiscoveredPeer(info, isConnected); + FilePayload fp = new FilePayload(); + fp.setFilePath(path); + super.sendAsync(fp); } -} - )__java_cb"; +const char CB_CION_JAVA_VERSION[] = +R"__java_cb(/* + * Generated by tidlc $$. + */ +)__java_cb"; -const char DISCOVERED_PEER[] = +const char CB_CION_JAVA_EXCEPTION_NotConnectedSocketException[] = R"__java_cb( -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import org.tizen.cion.PeerInfo; - -public final class DiscoveredPeer { - - @NonNull - private final PeerInfo info; - - @NonNull - private boolean isConnected; - - public DiscoveredPeer(@NonNull PeerInfo info, @NonNull boolean isConnected) { - this.info = info; - this.isConnected = isConnected; - } - - public void setIsConnected(boolean isConnected) { this.isConnected = isConnected; } - - public boolean isConnected() { return isConnected; } - - public PeerInfo getPeerInfo() { return info; } - - public String getPeerDeviceName() { - return info.getDeviceName(); - } - - public String getPeerDevicePlatform() { - return info.getDevicePlatform(); - } +public class NotConnectedSocketException extends RuntimeException {} +)__java_cb"; - public int getPeerChannelId() { - return info.getChannelId(); - } +const char CB_CION_JAVA_EXCEPTION_InvalidProtocolException[] = +R"__java_cb( +public class InvalidProtocolException extends RuntimeException {} +)__java_cb"; - @NonNull - @Override - public String toString() { - return info.getUuid(); - } +const char CB_CION_JAVA_EXCEPTION_InvalidIOException[] = +R"__java_cb( +public class InvalidIOException extends RuntimeException {} +)__java_cb"; - @Override - public boolean equals(@Nullable Object obj) { - return obj instanceof DiscoveredPeer - && this.info.getUuid().equals(((DiscoveredPeer) obj).info.getUuid()); - } +const char CB_CION_JAVA_EXCEPTION_PermissionDeniedException[] = +R"__java_cb( +public class PermissionDeniedException extends RuntimeException {} +)__java_cb"; - @Override - protected Object clone() { - return new DiscoveredPeer(info, isConnected); - } -} +const char CB_CION_JAVA_EXCEPTION_InvalidIDException[] = +R"__java_cb( +public class InvalidIDException extends RuntimeException {} +)__java_cb"; +const char CB_CION_JAVA_EXCEPTION_InvalidCallbackException[] = +R"__java_cb( +public class InvalidCallbackException extends RuntimeException {} )__java_cb"; +const char CB_CION_JAVA_EXCEPTION_InvalidArgumentException[] = +R"__java_cb( +public class InvalidArgumentException extends RuntimeException {} +)__java_cb"; #endif // IDLC_GEN_CION_JAVA_CION_GEN_CB_H_ diff --git a/idlc/gen_cion/java_cion_interface_gen.cc b/idlc/gen_cion/java_cion_interface_gen.cc deleted file mode 100644 index 6a8cdc4..0000000 --- a/idlc/gen_cion/java_cion_interface_gen.cc +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2021 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_cion/java_cion_interface_gen.h" -#include "idlc/gen_cion/java_cion_gen_cb.h" - -#include -#include - -#include -#include - -namespace tidl { - -JavaCionInterfaceGen::JavaCionInterfaceGen( - std::shared_ptr doc) : JavaCionGeneratorBase(doc) { -} - -void JavaCionInterfaceGen::OnInitGen(std::ofstream& stream) { - std::string fname = MakeDir(FileName, "/interfaces"); - if (fname.empty()) - return; - - stream.open(fname + "/ProxyDelegator.java"); - stream << "package org.tizen.gen." << FileName + ".interfaces;" << NLine(1); - stream << PROXY_DELEGATOR_TOP; - GenDelegateId(stream); - stream << PROXY_DELEGATOR_BOTTOM; - stream.close(); -} - -void JavaCionInterfaceGen::GenDelegateId(std::ofstream& stream) { - int id = 0; - for (auto& i : GetDocument().GetBlocks()) { - if (i->GetType() != Block::TYPE_INTERFACE) - continue; - - Interface& iface = static_cast(*i); - for (auto& d : iface.GetDeclarations().GetDecls()) { - if (d->GetMethodType() != Declaration::MethodType::DELEGATE) - continue; - - stream << Tab(1) << "public static final int " << - i->GetID() << "_" << d->GetID() << "__ = " << id++ << ";" << NLine(1); - } - } -} - - -void JavaCionInterfaceGen::OnFiniGen(std::ofstream& stream) { -} - -std::string JavaCionInterfaceGen::NLine(int cnt) { - std::string t; - - for (int i = 0; i < cnt; i++) { - t += "\n"; - } - - return t; -} - -} // namespace tidl diff --git a/idlc/gen_cion/java_cion_interface_gen.h b/idlc/gen_cion/java_cion_interface_gen.h deleted file mode 100644 index 45c6a85..0000000 --- a/idlc/gen_cion/java_cion_interface_gen.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2021 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_CION_JAVA_CION_INTERFACE_GEN_H_ -#define IDLC_GEN_CION_JAVA_CION_INTERFACE_GEN_H_ - -#include -#include -#include - -#include "idlc/gen_cion/java_cion_gen_base.h" - -namespace tidl { - -class JavaCionInterfaceGen : public JavaCionGeneratorBase { - public: - explicit JavaCionInterfaceGen(std::shared_ptr doc); - virtual ~JavaCionInterfaceGen() = default; - - void OnInitGen(std::ofstream& stream) override; - void OnFiniGen(std::ofstream& stream) override; - void GenDelegateId(std::ofstream& stream); - std::string NLine(int cnt); -}; - -} // namespace tidl -#endif // IDLC_GEN_CION_JAVA_CION_INTERFACE_GEN_H_ diff --git a/idlc/gen_cion/java_cion_proxy_gen.cc b/idlc/gen_cion/java_cion_proxy_gen.cc index cde3037..19029c4 100644 --- a/idlc/gen_cion/java_cion_proxy_gen.cc +++ b/idlc/gen_cion/java_cion_proxy_gen.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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. @@ -15,12 +15,11 @@ */ #include "idlc/gen_cion/java_cion_proxy_gen.h" -#include "idlc/gen_cion/java_cion_gen_cb.h" - -#include -#include -#include +namespace { +#include "idlc/gen_cion/java_cion_gen_cb.h" +#include "idlc/gen_cion/java_cion_proxy_gen_cb.h" +} namespace tidl { @@ -28,30 +27,28 @@ JavaCionProxyGen::JavaCionProxyGen(std::shared_ptr doc) : JavaCionGeneratorBase(doc) {} void JavaCionProxyGen::OnInitGen(std::ofstream& stream) { - std::string fname = MakeDir(FileName, "/viewmodel"); + std::string fname = MakeDir(FileName, "/client"); if (fname.empty()) return; for (auto& i : GetDocument().GetBlocks()) { if (i->GetType() != Block::TYPE_INTERFACE) continue; - Interface& iface = static_cast(*i); - stream.open(fname + "/" + GetViewModelName(i->GetID()) + ".java"); - stream << "package org.tizen.gen." << FileName << ".viewmodel;" << NLine(1); - stream << NLine(1); - stream << "import androidx.lifecycle.LiveData;" << NLine(1); - stream << "import androidx.lifecycle.ViewModel;" << NLine(1); - stream << "import org.tizen.cion.CionParcel;" << NLine(1); - stream << "import org.tizen.cion.DataPayload;" << NLine(1); - stream << "import org.tizen.cion.FilePayload;" << NLine(1); - stream << "import java.util.ArrayList;" << NLine(1); - stream << "import java.io.IOException;" << NLine(1); - stream << "import org.tizen.gen." << FileName << ".data.*;" << NLine(1); - stream << "import org.tizen.gen." << FileName << ".interfaces.*;" << NLine(1); + stream.open(fname + "/" + iface.GetID() + ".java"); + GenVersion(stream); + stream << "package org.tizen.gen." << FileName + ".client;" << NLine(2); + stream << std::endl; + + stream << "import org.tizen.gen." << FileName + ".common.*;" << NLine(2); + stream << "import org.tizen.cion.*;" << NLine(1) + << "import android.content.Context;" << NLine(1) + << "import java.util.ArrayList;" << NLine(1) + << "import java.util.LinkedList;" << NLine(1) + << "import java.util.List;" << NLine(2); - stream << NLine(1); GenInterface(stream, iface); + stream << NLine(1); stream.close(); } } @@ -59,32 +56,68 @@ void JavaCionProxyGen::OnInitGen(std::ofstream& stream) { void JavaCionProxyGen::OnFiniGen(std::ofstream& stream) { } -void JavaCionProxyGen::GenInterface( - std::ofstream& stream, const Interface& iface) { - stream << "public class " << GetViewModelName(iface.GetID()) - << " extends ViewModel " << NLine(1); +void JavaCionProxyGen::GenInterface(std::ofstream& stream, const Interface& iface) { + stream << "public class " << iface.GetID() + << " extends ClientBase "; GenBrace(stream, TAB_SIZE * 0, [&]() { - stream << Tab(1) << "private " << GetRepoClassName(iface.GetID()) - << " repo; " << NLine(1); - stream << Tab(1) << - "private LiveData> discoveredPeerLiveData;" - << NLine(1); - stream << Tab(1) << "private LiveData logsLiveData;" << NLine(1); - stream << Tab(1) - << "private LiveData receivedPayloadInfoLiveData;" - << NLine(1); - stream << Tab(1) << "private ArrayList delegators;" << NLine(1); - stream << NLine(1); - GenCtor(stream, iface); + stream << ReplaceAll(CB_DATA_MEMBERS, "", FULLVER); + GenCallbacks(stream, iface, true); + GenDelegateId(stream, iface); GenMethodId(stream, iface); + stream << CB_EVENT_METHODS; + GenSerializer(stream); + GenListSerializer(stream); + GenShareFile(stream, iface, true); + GenCtor(stream, iface); + GenConnectMethod(stream, iface); GenMethods(stream, iface); - stream << DEFAULT_PROXY_FUNCTIONS; - stream << NLine(1); - }); + }, false); +} + +void JavaCionProxyGen::GenCtor(std::ofstream& stream, const Interface& iface) { + bool securityCheck = false; + std::string m = "public $$(Context context, String serviceName) {\n"; + + m += Tab(1) + "super(context, serviceName, new SecurityInfo("; + + for (auto& attr : iface.GetAttributes().GetAttrs()) { + if (attr->GetKey() == "ca_path") { + m += "\"" + attr->GetValue() + "\", "; + securityCheck = true; + } else if (attr->GetKey() == "cert_path") { + m += "\"" + attr->GetValue() + "\", "; + securityCheck = true; + } else if (attr->GetKey() == "private_key") { + m += "\"" + attr->GetValue() + "\", "; + securityCheck = true; + } + } + + auto const pos = m.find_last_of(','); + m = m.substr(0, pos); + + if (securityCheck) + m += "));"; /* super(serviceName, new SecurityInfo(ca, cert, private_key) */ + else + m += ");"; /* super(serviceName) */ + + m += NLine(1); + m += " this.serviceName = serviceName;\n"; + m += "}"; + + GenTemplate(AddIndent(TAB_SIZE, m), stream, + [&]()->std::string { + return iface.GetID(); + }); +} + +void JavaCionProxyGen::GenConnectMethod(std::ofstream& stream, + const Interface& iface) { + stream << CB_CONNECT_METHOD; + stream << NLine(1); } -void JavaCionProxyGen::GenMethods( - std::ofstream& stream, const Interface& iface) { +void JavaCionProxyGen::GenMethods(std::ofstream& stream, const Interface& iface) { auto& decls = iface.GetDeclarations(); for (auto& i : decls.GetDecls()) { @@ -96,7 +129,6 @@ void JavaCionProxyGen::GenMethods( stream << Tab(1) << "public "; GenDeclaration(stream, *i, false); - stream << " throws IOException "; GenBrace(stream, TAB_SIZE * 1, [&]() { GenInvocation(stream, *i); }, false); @@ -104,108 +136,88 @@ void JavaCionProxyGen::GenMethods( } } -void JavaCionProxyGen::GenInvocation( - std::ofstream& stream, const Declaration& decl) { - stream << Tab(2) << "CionParcel parcel = new CionParcel();"; - stream << NLine(1); - stream << Tab(2) << "parcel.write(__" << decl.GetID() << ");"; - stream << NLine(1); - for (auto& i : decl.GetParameters().GetParams()) { - auto& pt = i->GetParameterType(); - if (pt.GetDirection() == ParameterType::Direction::OUT || - pt.GetDirection() == ParameterType::Direction::REF) - continue; +void JavaCionProxyGen::GenInvocation(std::ofstream& stream, const Declaration& decl) { + GenTemplate(CB_INVOCATION_PRE, stream, + [&]()->std::string { + std::string st; + st += Tab(2) + + "p.write(__" + decl.GetID() + ");" + NLine(1); + std::string m; + std::string l; + for (auto& i : decl.GetParameters().GetParams()) { + auto& pt = i->GetParameterType(); + if (pt.GetDirection() == ParameterType::Direction::OUT) + continue; + std::string id = i->GetID(); + if (pt.GetDirection() == ParameterType::Direction::REF) + id += ".get()"; + m += ConvertTypeToSerializer(pt.GetBaseType(), id, "p"); + if (IsDelegateType(pt.GetBaseType())) { + l += "_delegateList.add(" + id + ");\n"; + } + } - if (pt.GetBaseType().IsUserDefinedType()) - stream << Tab(2) << "parcel = " << i->GetID() << ".serialize(parcel);"; - else - stream << Tab(2) << "parcel.write(" << i->GetID() << ");"; - stream << NLine(1); - } + st += AddIndent(TAB_SIZE * 2, m) + NLine(1); - if (decl.GetMethodType() == Declaration::MethodType::SYNC) { - stream << Tab(2) - << "byte[] ret = sendData(parcel.toByteArray());" << NLine(1); - stream << Tab(2) - << "CionParcel ret_parcel = new CionParcel(ret);" << NLine(1); - stream << Tab(2) << "int cmd = ret_parcel.readInt();" << NLine(1); - stream << Tab(2) << "if (cmd != __RESULT)" << NLine(1); - stream << Tab(3) << "throw new IOException();" << NLine(1); - - for (auto& i : decl.GetParameters().GetParams()) { - auto& pt = i->GetParameterType(); - if (pt.GetDirection() != ParameterType::Direction::OUT && - pt.GetDirection() != ParameterType::Direction::REF) - continue; - if (pt.GetBaseType().IsUserDefinedType()) { - if (pt.GetDirection() == ParameterType::Direction::OUT) { - stream << Tab(2) << i->GetID() << ".set(new " - << pt.GetBaseType().ToString() << "());" << NLine(1); - - stream << Tab(2) << "ret_parcel = " << i->GetID() - << ".get().deserialize(ret_parcel);" << NLine(1); - } else { - stream << Tab(2) << "ret_parcel = " << i->GetID() - << ".get().deserialize(ret_parcel);" << NLine(1); - } + st += Tab(2) + "synchronized (_lock) {" + NLine(1); + if (!l.empty()) + st += AddIndent(TAB_SIZE * 2, l) + NLine(1); + + // Deserialize + if (decl.GetMethodType() == Declaration::MethodType::ASYNC) { + st += CB_ASYNC_INVOCATION_MID; } else { - stream << Tab(2) << i->GetID() - << ".set(" << i->GetID() << ".read" - << ConvertTypeToString(pt.GetBaseType(), true) - << "());" << NLine(1); + st += CB_SYNC_INVOCATION_MID; } - stream << NLine(1); - } - if (decl.GetType().IsUserDefinedType()) { - stream << Tab(2) << decl.GetType().ToString() - << " ret_val = new " << decl.GetType().ToString() - << "();" << NLine(1); - stream << Tab(2) << "ret_val.deserialize(ret_parcel);" << NLine(1); - stream << Tab(2) << "return ret_val;" << NLine(1); - } else { - stream << Tab(2) << ConvertTypeToString(decl.GetType()) - << " ret_val = ret_parcel.read" - << ConvertTypeToString(decl.GetType(), true) - << "();" << NLine(1); - stream << Tab(2) << "return ret_val;" << NLine(1); - } - } else { - stream << Tab(2) << - "sendAsync(new DataPayload(parcel.toByteArray()));" << NLine(1); - } + for (auto& i : decl.GetParameters().GetParams()) { + auto& pt = i->GetParameterType(); + if (pt.GetDirection() == ParameterType::Direction::OUT) + continue; + + if (pt.GetBaseType().ToString() == "file" || + (pt.GetBaseType().GetMetaType() != nullptr && + pt.GetBaseType().GetMetaType()->ToString() == "file")) { + st += GenTemplateString(CB_SHARE_FILE, [&]()->std::string { + std::string str = ""; + str += Tab(3) + "shareFile(" + i->GetID() + ");"; + return str; + }); + } + } + + // Deserialize + if (decl.GetMethodType() == Declaration::MethodType::ASYNC) { + st += Tab(2) + "}"; + return st; + } - for (auto& i : decl.GetParameters().GetParams()) { - auto& pt = i->GetParameterType(); - if (pt.GetDirection() == ParameterType::Direction::OUT || - pt.GetDirection() == ParameterType::Direction::REF) - continue; + for (auto& i : decl.GetParameters().GetParams()) { + if (i->GetParameterType().GetDirection() == + ParameterType::Direction::IN) { + continue; + } - if (pt.GetBaseType().ToString() == "file") { - stream << NLine(1); - stream << Tab(2) << "FilePayload " << i->GetID() - << "Payload = new FilePayload();" << NLine(1); - stream << Tab(2) << i->GetID() << "Payload.setFilePath(" - << i->GetID() << ");" << NLine(1); - stream << Tab(2) << "sendAsync(" << i->GetID() << "Payload);" << NLine(1); - } - } -} + // Out or Ref + std::string c = ConvertTypeToDeserializer( + i->GetParameterType().GetBaseType(), + i->GetID() + "_raw", "parcelReceived", true, "", true); + c += i->GetID() + ".set(" + i->GetID() + "_raw);" + NLine(1); -void JavaCionProxyGen::GenCtor(std::ofstream& stream, const Interface& iface) { - stream << Tab(1) << "public " << GetViewModelName(iface.GetID()) << - "(" << GetRepoClassName(iface.GetID()) << " repo) "; - GenBrace(stream, TAB_SIZE * 1, [&]() { - stream << Tab(2) << "super();" << NLine(1); - stream << Tab(2) << "this.repo = repo;" << NLine(1); - stream << Tab(2) << - "discoveredPeerLiveData = repo.getDiscoveredPeerLiveData();" - << NLine(1); - stream << Tab(2) << - "receivedPayloadInfoLiveData = repo.getReceivedPayloadInfoLiveData();" - << NLine(1); - stream << Tab(2) << "logsLiveData = repo.getLogsLiveData();" << NLine(1); - }); + if (c != "") + st += AddIndent(TAB_SIZE * 2, c); + } + + if (decl.GetType().ToString() != "void") { + st += AddIndent(TAB_SIZE * 2, ConvertTypeToDeserializer(decl.GetType(), + "ret", "parcelReceived")); + } + + st += NLine(1) + Tab(2) + "return ret;" + NLine(1); + st += Tab(2) + "}"; + + return st; + }); } } // namespace tidl diff --git a/idlc/gen_cion/java_cion_proxy_gen.h b/idlc/gen_cion/java_cion_proxy_gen.h index 5e7e152..5d3f24d 100644 --- a/idlc/gen_cion/java_cion_proxy_gen.h +++ b/idlc/gen_cion/java_cion_proxy_gen.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef IDLC_GEN_CION_JAVA_CION_PROXY_GEN_H_ -#define IDLC_GEN_CION_JAVA_CION_PROXY_GEN_H_ +#ifndef IDLC_JAVA_CION_GEN_JAVA_PROXY_GEN_H_ +#define IDLC_JAVA_CION_GEN_JAVA_PROXY_GEN_H_ #include #include @@ -33,13 +33,13 @@ class JavaCionProxyGen : public JavaCionGeneratorBase { void OnFiniGen(std::ofstream& stream) override; private: - void GenNamespace(std::ofstream& stream); void GenInterface(std::ofstream& stream, const Interface& iface); void GenCtor(std::ofstream& stream, const Interface& iface); + void GenConnectMethod(std::ofstream& stream, const Interface& iface); void GenMethods(std::ofstream& stream, const Interface& iface); void GenInvocation(std::ofstream& stream, const Declaration& decl); }; } // namespace tidl -#endif // IDLC_GEN_CION_JAVA_CION_PROXY_GEN_H_ +#endif // IDLC_JAVA_CION_GEN_JAVA_PROXY_GEN_H_ \ No newline at end of file diff --git a/idlc/gen_cion/java_cion_proxy_gen_cb.h b/idlc/gen_cion/java_cion_proxy_gen_cb.h new file mode 100644 index 0000000..d9ef4d2 --- /dev/null +++ b/idlc/gen_cion/java_cion_proxy_gen_cb.h @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2021 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_JAVA_CION_GEN_JAVA_PROXY_GEN_CB_H_ +#define IDLC_JAVA_CION_GEN_JAVA_PROXY_GEN_CB_H_ + + +const char CB_DATA_MEMBERS[] = +R"__java_cb( + public String serviceName; + private static final String _tidlVersion = ""; + private boolean _online = false; + private Object _lock = new Object(); + private List _delegateList = new LinkedList(); +)__java_cb"; + +const char CB_EVENT_METHODS[] = +R"__java_cb( + private void processReceivedEvent(CionParcel parcel) { + int id = parcel.readInt(); + int seqId = parcel.readInt(); + boolean once = parcel.readBoolean(); + + for (DelegatorBase i : _delegateList) { + if (i.getDelegateId() == id && i.getSequenceId() == seqId) { + i.onInvoked(parcel); + if (i.isOnce()) + _delegateList.remove(i); + break; + } + } + } + + @Override + public void onConnectionResult(PeerInfo peerInfo, ConnectionResult result) { + if (result.status == ConnectionResult.ConnectionStatus.CONNECTION_OK) { + _online = true; + } + } + + @Override + public void onDisconnected(PeerInfo peerInfo) { + _online = false; + } + + @Override + public void onDiscovered(PeerInfo peerInfo) { + } + + @Override + public void onLost(PeerInfo peerInfo) { + } + + @Override + public void onResultReceived(PayloadAsyncResult payloadAsyncResult) { + } + + @Override + public void onPayloadReceived(IPayload payload, PayloadTransferStatus status) { + if(payload.getType() == IPayload.PayloadType.PAYLOAD_FILE) { + onFileReceived((FilePayload)payload, status); + } else { + CionParcel parcelReceived; + + parcelReceived = new CionParcel(((DataPayload)payload).getData()); + int cmd = parcelReceived.readInt(); + if (cmd != __CALLBACK) + return; + + processReceivedEvent(parcelReceived); + } + } + + public void onFileReceived(FilePayload payload, PayloadTransferStatus status) {} + +)__java_cb"; + +const char CB_CONNECT_METHOD[] = +R"__java_cb( + /// + /// Starts discovering cion servers. + /// + /// Thrown when the discovery operation is already in progress. + @Override + public void tryDiscovery() { + super.tryDiscovery(); + } + + /// + /// Connects to the stub app. + /// + /// The peer to connect. + /// http://tizen.org/privilege/d2d.datasharing + /// http://tizen.org/privilege/internet + /// + /// Thrown when the permission is denied. + /// + /// If you want to use this method, you must add privileges. + @Override + public void tryConnect(PeerInfo peer) { + super.tryConnect(peer); + } + + /// + /// Disconnects from the stub app. + /// + @Override + public void disconnect() { + super.disconnect(); + } + + /// + /// Disposes delegate objects in this interface + /// + /// The tag string from delegate object + public void disposeCallback(String tag) { + for (DelegatorBase i : _delegateList) { + if (i.getTag().equals(tag)) { + _delegateList.remove(i); + return; + } + } + } +)__java_cb"; + +const char CB_INVOCATION_PRE[] = +R"__java_cb( if (!_online) + throw new NotConnectedSocketException(); + + CionParcel p = new CionParcel(); +$$ +)__java_cb"; + +const char CB_SHARE_FILE[] = +R"__java_cb( + try { +$$ + } catch (InvalidArgumentException e) { + } +)__java_cb"; + +const char CB_ASYNC_INVOCATION_MID[] = +R"__java_cb( + // Send + DataPayload dp = new DataPayload(p.toByteArray()); + super.sendAsync(dp); +)__java_cb"; + +const char CB_SYNC_INVOCATION_MID[] = +R"__java_cb( + // Send + byte[] dataReceived = sendData(p.toByteArray()); + + CionParcel parcelReceived = new CionParcel(dataReceived); + + int cmd = parcelReceived.readInt(); + if (cmd != __RESULT) + throw new InvalidProtocolException(); +)__java_cb"; +#endif // IDLC_JAVA_CION_GEN_JAVA_PROXY_GEN_CB_H_ diff --git a/idlc/gen_cion/java_cion_proxy_repo_gen.cc b/idlc/gen_cion/java_cion_proxy_repo_gen.cc index 8a13008..78accc2 100644 --- a/idlc/gen_cion/java_cion_proxy_repo_gen.cc +++ b/idlc/gen_cion/java_cion_proxy_repo_gen.cc @@ -30,7 +30,7 @@ JavaCionProxyRepoGen::JavaCionProxyRepoGen( } void JavaCionProxyRepoGen::OnInitGen(std::ofstream& stream) { - std::string fname = MakeDir(FileName, "/data"); + std::string fname = MakeDir(FileName, "/client"); if (fname.empty()) return; @@ -38,10 +38,9 @@ void JavaCionProxyRepoGen::OnInitGen(std::ofstream& stream) { if (i->GetType() != Block::TYPE_INTERFACE) continue; - stream.open(fname + "/" + GetRepoClassName(i->GetID()) + ".java"); - stream << "package org.tizen.gen." << FileName + ".data;" << NLine(2); - stream << ReplaceAll(DEFAULT_PROXY_REPO, "##", GetRepoClassName(i->GetID())) - << NLine(1); + stream.open(fname + "/ClientBase.java"); + stream << "package org.tizen.gen." << FileName + ".client;" << NLine(2); + stream << DEFAULT_PROXY_REPO; stream.close(); } } diff --git a/idlc/gen_cion/java_cion_structure_gen.cc b/idlc/gen_cion/java_cion_structure_gen.cc index ba7be13..439470d 100644 --- a/idlc/gen_cion/java_cion_structure_gen.cc +++ b/idlc/gen_cion/java_cion_structure_gen.cc @@ -30,7 +30,7 @@ JavaCionStructureGen::JavaCionStructureGen( } void JavaCionStructureGen::OnInitGen(std::ofstream& stream) { - std::string fname = MakeDir(FileName, "/data"); + std::string fname = MakeDir(FileName, "/common"); if (fname.empty()) return; @@ -39,7 +39,7 @@ void JavaCionStructureGen::OnInitGen(std::ofstream& stream) { continue; Structure& st = static_cast(*i); stream.open(fname + "/" + st.GetID() + ".java"); - stream << "package org.tizen.gen." << FileName + ".data;" << NLine(2); + stream << "package org.tizen.gen." << FileName + ".common;" << NLine(2); GenStructure(stream, st); stream << std::endl; stream.close(); @@ -54,7 +54,7 @@ void JavaCionStructureGen::GenStructure(std::ofstream& stream, stream << "import java.util.ArrayList;" << NLine(1); stream << "import java.util.LinkedList;" << NLine(1); stream << NLine(1); - stream << "public class " << st.GetID() << " "; + stream << "public final class " << st.GetID() << " "; GenBrace(stream, 0, [&]() { stream << NLine(1); for (auto& i : st.GetElements().GetElms()) { @@ -63,10 +63,7 @@ void JavaCionStructureGen::GenStructure(std::ofstream& stream, stream << NLine(1); } - GenSerializer(stream, st); stream << NLine(1); - GenDeserializer(stream, st); - GenTemplate(variable, stream, [&]()->std::string { std::string str; @@ -88,56 +85,10 @@ void JavaCionStructureGen::GenStructure(std::ofstream& stream, stream << NLine(1); } -void JavaCionStructureGen::GenSerializer(std::ofstream& stream, - const Structure& st) { - - stream << Tab(1) << "public CionParcel serialize(CionParcel parcel) "; - GenBrace(stream, TAB_SIZE * 1, [&]() { - for (auto& i : st.GetElements().GetElms()) { - stream << NLine(1); - if (i->GetType().GetMetaType() == nullptr) { - stream << Tab(2) << "parcel.write(" + i->GetID() + "_);" + NLine(1); - } else { - stream << Tab(2) << - "parcel.write(" + i->GetID() + "_.size());" + NLine(1); - stream << Tab(2) << "for (int i = 0; i < " + i->GetID() + - "_.size(); i++) {" + NLine(1); - if (!i->GetType().GetMetaType()->IsUserDefinedType()) { - stream << Tab(3) + "parcel.write(" + i->GetID() + "_.get(i)." + - ConvertTypeToString(*i->GetType().GetMetaType()) + - "Value());" + NLine(1); - } else { - stream << Tab(3) + "parcel = " + i->GetID() + - "_.get(i).serialize(parcel);" + NLine(1); - } - stream << Tab(2) << "}" + NLine(1); - } - } - stream << Tab(2) << "return parcel;" + NLine(1); - }, false, false); - stream << NLine(1); -} - -void JavaCionStructureGen::GenDeserializer(std::ofstream& stream, - const Structure& st) { - std::string parcel_name = "parcel"; - stream << Tab(1) << "public CionParcel deserialize(CionParcel " - << parcel_name << ") "; - GenBrace(stream, TAB_SIZE * 1, [&]() { - for (auto& i : st.GetElements().GetElms()) { - stream << NLine(1); - stream << GetParcelReader(i->GetType(), - parcel_name, i->GetID(), 2) + NLine(1); - } - stream << Tab(2) << "return " << parcel_name << ";" + NLine(1); - }, false, false); - stream << NLine(1); -} - void JavaCionStructureGen::GenSetter(std::ofstream& stream, const Element& ele) { const char setter[] = - "public void Set$$($$ $$) {\n" \ + "public void set$$($$ $$) {\n" \ " $$_ = $$;\n" \ "}\n"; @@ -163,7 +114,7 @@ void JavaCionStructureGen::GenSetter(std::ofstream& stream, void JavaCionStructureGen::GenGetter(std::ofstream& stream, const Element& ele) { const char getter[] = - "public $$ Get$$() {\n" \ + "public $$ get$$() {\n" \ " return $$_;\n" \ "}\n"; @@ -182,14 +133,4 @@ void JavaCionStructureGen::GenGetter(std::ofstream& stream, void JavaCionStructureGen::OnFiniGen(std::ofstream& stream) { } -std::string JavaCionStructureGen::NLine(int cnt) { - std::string t; - - for (int i = 0; i < cnt; i++) { - t += "\n"; - } - - return t; -} - } // namespace tidl diff --git a/idlc/gen_cion/java_cion_structure_gen.h b/idlc/gen_cion/java_cion_structure_gen.h index 7c87b2c..126414b 100644 --- a/idlc/gen_cion/java_cion_structure_gen.h +++ b/idlc/gen_cion/java_cion_structure_gen.h @@ -36,14 +36,6 @@ class JavaCionStructureGen : public JavaCionGeneratorBase { const Structure& st); void GenSetter(std::ofstream& stream, const Element& ele); void GenGetter(std::ofstream& stream, const Element& ele); - void GenSerializer(std::ofstream& stream, - const Structure& st); - void GenDeserializer(std::ofstream& stream, - const Structure& st); - std::string NLine(int cnt); - - private: - const int TAB_SIZE = 4; }; } // namespace tidl diff --git a/idlc/gen_cion/java_cion_stub_base_service_gen.cc b/idlc/gen_cion/java_cion_stub_base_service_gen.cc deleted file mode 100644 index 4884847..0000000 --- a/idlc/gen_cion/java_cion_stub_base_service_gen.cc +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2021 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_cion/java_cion_stub_base_service_gen.h" - -#include -#include - -#include -#include - -namespace tidl { - -JavaCionStubBaseServiceGen::JavaCionStubBaseServiceGen( - std::shared_ptr doc) : JavaCionGeneratorBase(doc) { -} - -void JavaCionStubBaseServiceGen::OnInitGen(std::ofstream& stream) { - std::string fname = MakeDir(FileName, "/interfaces"); - if (fname.empty()) - return; - - for (auto& i : GetDocument().GetBlocks()) { - if (i->GetType() != Block::TYPE_INTERFACE) - continue; - - Interface& iface = static_cast(*i); - stream.open(fname + "/" + GetServiceBaseClassName(i->GetID()) + ".java"); - stream << "package org.tizen.gen." << FileName + ".interfaces;" << NLine(2); - stream << "import org.tizen.gen." << FileName << ".data.*;" << NLine(2); - stream << "import java.util.LinkedList;" << NLine(1); - stream << "import java.util.ArrayList;" << NLine(1); - stream << NLine(1); - stream << "public abstract class " << GetServiceBaseClassName(i->GetID()) << " "; - GenBrace(stream, TAB_SIZE * 0, [&]() { - GenMethods(stream, iface); - stream << std::endl; - }, false); - stream.close(); - } -} - -void JavaCionStubBaseServiceGen::GenMethods( - std::ofstream& stream, const Interface& iface) { - auto& decls = iface.GetDeclarations(); - - for (auto& i : decls.GetDecls()) { - if (i->GetMethodType() == Declaration::MethodType::DELEGATE) - continue; - - if (!i->GetComments().empty()) - stream << AddIndent(TAB_SIZE * 1, i->GetComments()); - - stream << Tab(1) << "abstract public "; - GenDeclaration(stream, *i, false); - stream << ";" << NLine(1); - } -} - -void JavaCionStubBaseServiceGen::OnFiniGen(std::ofstream& stream) { -} - -std::string JavaCionStubBaseServiceGen::NLine(int cnt) { - std::string t; - - for (int i = 0; i < cnt; i++) { - t += "\n"; - } - - return t; -} - -} // namespace tidl diff --git a/idlc/gen_cion/java_cion_stub_base_service_gen.h b/idlc/gen_cion/java_cion_stub_base_service_gen.h deleted file mode 100644 index ca3940a..0000000 --- a/idlc/gen_cion/java_cion_stub_base_service_gen.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2021 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_CION_JAVA_CION_STUB_BASE_SERVICE_GEN_H_ -#define IDLC_GEN_CION_JAVA_CION_STUB_BASE_SERVICE_GEN_H_ - -#include -#include -#include - -#include "idlc/gen_cion/java_cion_gen_base.h" - -namespace tidl { - -class JavaCionStubBaseServiceGen : public JavaCionGeneratorBase { - public: - explicit JavaCionStubBaseServiceGen(std::shared_ptr doc); - virtual ~JavaCionStubBaseServiceGen() = default; - - void OnInitGen(std::ofstream& stream) override; - void OnFiniGen(std::ofstream& stream) override; - void GenMethods(std::ofstream& stream, const Interface& iface); - std::string NLine(int cnt); - - private: - const int TAB_SIZE = 4; -}; - -} // namespace tidl -#endif // IDLC_GEN_CION_JAVA_CION_STUB_BASE_SERVICE_GEN_H_ diff --git a/idlc/gen_cion/java_cion_stub_gen.cc b/idlc/gen_cion/java_cion_stub_gen.cc index 6b2965c..af125dd 100644 --- a/idlc/gen_cion/java_cion_stub_gen.cc +++ b/idlc/gen_cion/java_cion_stub_gen.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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. @@ -15,12 +15,11 @@ */ #include "idlc/gen_cion/java_cion_stub_gen.h" -#include "idlc/gen_cion/java_cion_gen_cb.h" - -#include -#include -#include +namespace { +#include "idlc/gen_cion/java_cion_gen_cb.h" +#include "idlc/gen_cion/java_cion_stub_gen_cb.h" +} namespace tidl { @@ -28,295 +27,246 @@ JavaCionStubGen::JavaCionStubGen(std::shared_ptr doc) : JavaCionGeneratorBase(doc) {} void JavaCionStubGen::OnInitGen(std::ofstream& stream) { - std::string fname = MakeDir(FileName, "/viewmodel"); + std::string fname = MakeDir(FileName, "/server"); if (fname.empty()) return; for (auto& i : GetDocument().GetBlocks()) { if (i->GetType() != Block::TYPE_INTERFACE) continue; - Interface& iface = static_cast(*i); - stream.open(fname + "/" + GetViewModelName(i->GetID()) + ".java"); - stream << "package org.tizen.gen." << FileName << ".viewmodel;" << NLine(2); - stream << "import androidx.lifecycle.LiveData;" << NLine(1); - stream << "import androidx.lifecycle.ViewModel;" << NLine(1); - stream << "import org.tizen.cion.CionParcel;" << NLine(1); - stream << "import org.tizen.cion.DataPayload;" << NLine(1); - stream << "import org.tizen.cion.FilePayload;" << NLine(1); - stream << "import java.util.ArrayList;" << NLine(1); - stream << "import org.tizen.gen." << FileName << ".data.*;" << NLine(1); - stream << "import org.tizen.gen." << FileName << ".interfaces.*;" << NLine(1); + stream.open(fname + "/" + iface.GetID() + ".java"); + GenVersion(stream); stream << NLine(1); + stream << "package org.tizen.gen." << FileName + ".server;" << NLine(2); + stream << std::endl; + + stream << "import org.tizen.gen." << FileName + ".common.*;" << NLine(2); + stream << "import org.tizen.cion.*;" << NLine(1) + << "import android.content.Context;" << NLine(1) + << "import java.lang.ref.WeakReference;" << NLine(1) + << "import java.util.ArrayList;" << NLine(1) + << "import java.util.LinkedList;" << NLine(1) + << "import java.util.List;" << NLine(2); GenInterface(stream, iface); stream.close(); } } -void JavaCionStubGen::OnFiniGen(std::ofstream& stream) { -} +void JavaCionStubGen::OnFiniGen(std::ofstream& stream) {} -void JavaCionStubGen::GenInterface( - std::ofstream& stream, const Interface& iface) { - stream << "public class " << GetViewModelName(iface.GetID()) - << " extends ViewModel " << NLine(1); +void JavaCionStubGen::GenInterface(std::ofstream& stream, const Interface& iface) { + stream << "public final class " << iface.GetID() + << " extends ServerBase "; GenBrace(stream, TAB_SIZE * 0, [&]() { - stream << Tab(1) << "private " << GetRepoClassName(iface.GetID()) << " repo; " << NLine(1); - stream << Tab(1) << - "private LiveData> connectedPeerLiveData;" - << NLine(1); - stream << Tab(1) << "private LiveData logsLiveData;" << NLine(1); - stream << Tab(1) - << "private LiveData receivedPayloadLiveData;" - << NLine(1); - stream << Tab(1) - << "private LiveData receivedDataLiveData;" - << NLine(1); - stream << Tab(1) - << "private " << GetServiceBaseClassName(iface.GetID()) << " service;" - << NLine(1); - stream << NLine(1); + stream << ReplaceAll(CB_DATA_MEMBERS, "", FULLVER); GenMethodId(stream, iface); - stream << NLine(1); + GenDelegateId(stream, iface); + GenServiceBase(stream, iface); + GenCallbacks(stream, iface, false); + GenSerializer(stream); + GenListSerializer(stream); + GenReceivedAsyncEvent(stream, iface); + GenReceivedSyncEvent(stream, iface); + GenConnectionRequestedEvent(stream); + GenDisconnectedEvent(stream); + GenConnectedEvent(stream); + GenShareFile(stream, iface, false); GenCtor(stream, iface); - stream << NLine(1); - GenSyncReceiver(stream, iface); - stream << NLine(1); - GenAsyncReceiver(stream, iface); - stream << ReplaceAll(DEFAULT_STUB_FUNCTIONS, - "##", GetServiceBaseClassName(iface.GetID())) << NLine(1); - stream << NLine(1); - }); + GenCommonMethods(stream); + }, false); } -void JavaCionStubGen::GenSyncReceiver( - std::ofstream& stream, const Interface& iface) { - stream << Tab(1) << "public void processReceivedData(byte[] data) "; - GenBrace(stream, TAB_SIZE * 1, [&]() { - std::string parcel_name = "parcel"; - std::string ret_parcel_name = "ret_parcel"; - stream << Tab(2) - << "CionParcel " << parcel_name - << " = new CionParcel(data);" << NLine(1); - stream << Tab(2) - << "CionParcel " << ret_parcel_name - << " = new CionParcel();" << NLine(1); - stream << Tab(2) << "int methodID = " << parcel_name - << ".readInt();" << NLine(1); - stream << Tab(2) << "switch (methodID) "; - GenBrace(stream, TAB_SIZE * 2, [&]() { - auto& decls = iface.GetDeclarations(); - for (auto& i : decls.GetDecls()) { - if (i->GetMethodType() != Declaration::MethodType::SYNC) - continue; - - stream << Tab(2) << - "case " << "__" << i->GetID() << " : "; - GenBrace(stream, 0, [&]() { - std::string params_str = ""; - for (auto& param : i->GetParameters().GetParams()) { - if (!params_str.empty()) - params_str += ", "; - auto& pt = param->GetParameterType(); - if (pt.GetDirection() == ParameterType::Direction::OUT) { - stream << Tab(3) - << "Out<" << ConvertTypeToString(pt.GetBaseType()) - << "> " << param->GetID() << " = null;" << NLine(1); - } else if (pt.GetDirection() == ParameterType::Direction::REF) { - stream << Tab(3) << ConvertTypeToString(pt.GetBaseType()) - << " " << param->GetID() << "Raw = new " - << ConvertTypeToString(pt.GetBaseType()) << "();" << NLine(1); - stream << Tab(3) - << "Ref<" << ConvertTypeToString(pt.GetBaseType()) - << "> " << param->GetID() << " = new Ref<" - << ConvertTypeToString(pt.GetBaseType()) << ">(" - << param->GetID() <<"Raw);" << NLine(1); - } else { - stream << GetParcelReader(pt.GetBaseType(), - parcel_name, param->GetID(), 3) << NLine(1); - } - params_str += param->GetID(); - } - - stream << Tab(3) << ConvertTypeToString(i->GetType()) - << " ret_" << i->GetID() << " = " << "service." << i->GetID() - << "(" << params_str << ");" << NLine(1); - if (i->GetType().IsUserDefinedType()) { - stream << Tab(3) << ret_parcel_name - << " = ret_" << i->GetID() << ".deserialize(" - << ret_parcel_name << ");" << NLine(1); - } else { - stream << Tab(3) - << ret_parcel_name - << ".write(ret_" << i->GetID() << ");" << NLine(1); - } - - stream << Tab(3) - << "setSyncResponse(" - << ret_parcel_name << ".toByteArray());" << NLine(1); - stream << Tab(3) << "break;" << NLine(1); - }, false); - } - }, false); +void JavaCionStubGen::GenServiceBase(std::ofstream& stream, const Interface& iface) { + stream << CB_SERVICE_BASE_FRONT; + GenDeclarations(stream, iface.GetDeclarations()); + stream << AddIndent(TAB_SIZE * 1, "}\n"); +} + +void JavaCionStubGen::GenDeclarations(std::ofstream& stream, + const Declarations& decls) { + for (auto& i : decls.GetDecls()) { + if (i->GetMethodType() == Declaration::MethodType::DELEGATE) + continue; + if (!i->GetComments().empty()) + stream << NLine(1) << AddIndent(TAB_SIZE * 2, i->GetComments()); + stream << Tab(2) << "public abstract "; + GenDeclaration(stream, *i); + stream << NLine(2); + } +} + +void JavaCionStubGen::GenReceivedSyncEvent(std::ofstream& stream, + const Interface& iface) { + stream << CB_ON_RECEIVED_SYNC_EVENT_FRONT; + for (auto& i : iface.GetDeclarations().GetDecls()) { + if (i->GetMethodType() != Declaration::MethodType::SYNC) + continue; + stream << Tab(4) << "case __" << i->GetID() << ": "; + GenBrace(stream, TAB_SIZE * 5, [&]() { + GenSyncInvocation(stream, *i); + stream << Tab(5) << "break;" << NLine(1); }, false); + } + stream << CB_ON_RECEIVED_SYNC_EVENT_BACK; } -void JavaCionStubGen::GenAsyncReceiver( - std::ofstream& stream, const Interface& iface) { - std::string parcel_name = "parcel"; - stream << Tab(1) - << "public void processReceivedPayload(CionParcel " - << parcel_name << ") "; - GenBrace(stream, TAB_SIZE * 1, [&]() { - stream << Tab(2) << "int methodID = " - << parcel_name << ".readInt();" << NLine(1); - stream << Tab(2) << "switch (methodID) "; - GenBrace(stream, TAB_SIZE * 2, [&]() { - auto& decls = iface.GetDeclarations(); - for (auto& i : decls.GetDecls()) { - if (i->GetMethodType() != Declaration::MethodType::ASYNC) - continue; - - stream << Tab(2) - << "case " << "__" << i->GetID() << " : " << NLine(1); - std::string params_str = ""; - for (auto& param : i->GetParameters().GetParams()) { - if (!params_str.empty()) - params_str += ", "; - auto& pt = param->GetParameterType(); - if (pt.GetDirection() == ParameterType::Direction::OUT) { - stream << Tab(3) - << "Out<" << ConvertTypeToString(pt.GetBaseType()) - << "> " << param->GetID() << " = null;" << NLine(1); - } else if (pt.GetDirection() == ParameterType::Direction::REF) { - stream << Tab(3) << ConvertTypeToString(pt.GetBaseType()) - << " " << param->GetID() << "Raw = new " - << ConvertTypeToString(pt.GetBaseType()) << "();" << NLine(1); - stream << Tab(3) - << "Ref<" << ConvertTypeToString(pt.GetBaseType()) - << "> " << param->GetID() << " = new Ref<" - << ConvertTypeToString(pt.GetBaseType()) << ">(" - << param->GetID() <<"Raw);" << NLine(1); - } else { - stream << GetParcelReader(pt.GetBaseType(), - parcel_name, param->GetID(), 3) << NLine(1); - } - - params_str += param->GetID(); - } - stream << Tab(3) << "service." << i->GetID() - << "(" << params_str << ");" << NLine(1); - - stream << Tab(3) << "break;" << NLine(1); - } - stream << Tab(2) << "default" << " : " << NLine(1); - stream << Tab(3) << "break;" << NLine(1); - }, false); +void JavaCionStubGen::GenReceivedAsyncEvent(std::ofstream& stream, + const Interface& iface) { + stream << CB_ON_RECEIVED_ASYNC_EVENT_FRONT; + for (auto& i : iface.GetDeclarations().GetDecls()) { + if (i->GetMethodType() != Declaration::MethodType::ASYNC) + continue; + stream << Tab(4) << "case __" << i->GetID() << ": "; + GenBrace(stream, TAB_SIZE * 5, [&]() { + GenAsyncInvocation(stream, *i); + stream << Tab(5) << "break;" << NLine(1); }, false); + } + stream << CB_ON_RECEIVED_ASYNC_EVENT_BACK; } -void JavaCionStubGen::GenInvocation( - std::ofstream& stream, const Declaration& decl) { - stream << Tab(2) << "CionParcel parcel = new CionParcel();"; - stream << NLine(1); - stream << Tab(2) << "parcel.write(__" << decl.GetID() << ");"; - stream << NLine(1); +void JavaCionStubGen::GenSyncInvocation(std::ofstream& stream, const Declaration& decl) { + bool hasRet = GenAsyncInvocation(stream, decl); + + // Serialize + int cnt = 0; + std::string m = CB_INVOCATION_RESULT_PRE; for (auto& i : decl.GetParameters().GetParams()) { auto& pt = i->GetParameterType(); - if (pt.GetDirection() == ParameterType::Direction::OUT || - pt.GetDirection() == ParameterType::Direction::REF) + cnt++; + if (pt.GetDirection() == ParameterType::Direction::IN) continue; + m += ConvertTypeToSerializer(pt.GetBaseType(), + "ref_param" + std::to_string(cnt) + ".get()", "result"); - if (pt.GetBaseType().IsUserDefinedType()) - stream << Tab(2) << "parcel = " << i->GetID() << ".serialize(parcel);"; - else - stream << Tab(2) << "parcel.write(" << i->GetID() << ");"; - stream << NLine(1); - } - - if (decl.GetMethodType() == Declaration::MethodType::SYNC) { - stream << Tab(2) - << "byte[] ret = sendData(parcel.toByteArray());" << NLine(1); - stream << Tab(2) - << "CionParcel ret_parcel = new CionParcel(ret);" << NLine(1); - stream << Tab(2) << "int cmd = ret_parcel.readInt();" << NLine(1); - stream << Tab(2) << "if (cmd != __RESULT)" << NLine(1); - stream << Tab(3) << "throw new IOException();" << NLine(1); - - for (auto& i : decl.GetParameters().GetParams()) { - auto& pt = i->GetParameterType(); - if (pt.GetDirection() != ParameterType::Direction::OUT && - pt.GetDirection() != ParameterType::Direction::REF) - continue; - if (pt.GetBaseType().IsUserDefinedType()) { - if (pt.GetDirection() == ParameterType::Direction::OUT) { - stream << Tab(2) << i->GetID() << ".set(new " - << pt.GetBaseType().ToString() << "());" << NLine(1); - - stream << Tab(2) << "ret_parcel = " << i->GetID() - << ".get().deserialize(ret_parcel);" << NLine(1); - } else { - stream << Tab(2) << "ret_parcel = " << i->GetID() - << ".get().deserialize(ret_parcel);" << NLine(1); - } - } else { - stream << Tab(2) << i->GetID() - << ".set(" << i->GetID() << ".read" - << ConvertTypeToString(pt.GetBaseType(), true) - << "());" << NLine(1); - } - stream << NLine(1); + if (HasFile(pt.GetBaseType())) { + m += "shareFile(ref_param" + std::to_string(cnt) + ".get());\n\n"; } + } - if (decl.GetType().IsUserDefinedType()) { - stream << Tab(2) << decl.GetType().ToString() - << " ret_val = new " << decl.GetType().ToString() - << "();" << NLine(1); - stream << Tab(2) << "ret_val.deserialize(ret_parcel);" << NLine(1); - stream << Tab(2) << "return ret_val;" << NLine(1); - } else { - stream << Tab(2) << ConvertTypeToString(decl.GetType()) - << " ret_val = ret_parcel.read" - << ConvertTypeToString(decl.GetType(), true) - << "();" << NLine(1); - stream << Tab(2) << "return ret_val;" << NLine(1); + if (hasRet) { + m += ConvertTypeToSerializer(decl.GetType(), "retVal", "result"); + if (HasFile(decl.GetType())) { + m += "shareFile(retVal);\n"; } - } else { - stream << Tab(2) << - "sendAsync(new DataPayload(parcel.toByteArray()));" << NLine(1); } + m += "\nreturnData = result.toByteArray();\n"; + + stream << AddIndent(TAB_SIZE * 5, m); +} + +bool JavaCionStubGen::GenAsyncInvocation(std::ofstream& stream, const Declaration& decl) { + int cnt = 1; + + // Deserialize for (auto& i : decl.GetParameters().GetParams()) { + std::string v = "param" + std::to_string(cnt); auto& pt = i->GetParameterType(); - if (pt.GetDirection() == ParameterType::Direction::OUT || - pt.GetDirection() == ParameterType::Direction::REF) + if (pt.GetDirection() == ParameterType::Direction::OUT) { + std::string mt = "Out<" + ConvertTypeToString(pt.GetBaseType(), true) + ">"; + mt += " ref_" + v + " = new " + mt + "();\n"; + stream << AddIndent(TAB_SIZE * 5, mt); + cnt++; continue; + } + + std::string c = ConvertTypeToDeserializer( + i->GetParameterType().GetBaseType(), v, "p"); + stream << AddIndent(TAB_SIZE * 5, c); + + if (pt.GetDirection() == ParameterType::Direction::REF) { + std::string mt = "Ref<" + ConvertTypeToString(pt.GetBaseType(), true) + ">"; + mt += " ref_" + v + " = new " + mt + "(" + v + ");\n"; + stream << AddIndent(TAB_SIZE * 5, mt); + } + + cnt++; + } + + // Invoke + cnt = 1; + std::string m; + + bool hasRet = false; + if (decl.GetType().ToString() != "void") { + m += ConvertTypeToString(decl.GetType()) + " retVal = "; + hasRet = true; + } + + m += "b." + decl.GetID() + "("; + for (auto& i : decl.GetParameters().GetParams()) { + if (cnt != 1) { + m += ", "; + } - if (pt.GetBaseType().ToString() == "file") { - stream << NLine(1); - stream << Tab(2) << "FilePayload " << i->GetID() - << "Payload = new FilePayload();" << NLine(1); - stream << Tab(2) << i->GetID() << "Payload.setFilePath(" - << i->GetID() << ");" << NLine(1); - stream << Tab(2) << "sendAsync(" << i->GetID() << "Payload);" << NLine(1); + std::string v; + auto& pt = i->GetParameterType(); + if (pt.GetDirection() == ParameterType::Direction::REF || + pt.GetDirection() == ParameterType::Direction::OUT) { + v = "ref_"; } + + m += v + "param" + std::to_string(cnt); + cnt++; } + + m += ");\n"; + stream << AddIndent(TAB_SIZE * 5, m); + + return hasRet; +} + +void JavaCionStubGen::GenConnectionRequestedEvent(std::ofstream& stream) { + stream << CB_ON_CONNECTIONREQUESTED_EVENT; +} + +void JavaCionStubGen::GenConnectedEvent(std::ofstream& stream) { + stream << CB_ON_CONNECTED_EVENT; +} + +void JavaCionStubGen::GenDisconnectedEvent(std::ofstream& stream) { + stream << CB_ON_DISCONNECTED_EVENT; } void JavaCionStubGen::GenCtor(std::ofstream& stream, const Interface& iface) { - stream << Tab(1) << "public " << GetViewModelName(iface.GetID()) << - "(" << GetRepoClassName(iface.GetID()) << " repo) "; - GenBrace(stream, TAB_SIZE * 1, [&]() { - stream << Tab(2) << "super();" << NLine(1); - stream << Tab(2) << "this.repo = repo;" << NLine(1); - stream << Tab(2) << - "connectedPeerLiveData = repo.getConnectedPeerLiveData();" - << NLine(1); - stream << Tab(2) << - "receivedPayloadLiveData = repo.getReceivedPayloadInfoLiveData();" - << NLine(1); - stream << Tab(2) << "logsLiveData = repo.getLogsLiveData();" << NLine(1); - }); + bool securityCheck = false; + std::string m = "public $$(Context context, String serviceName, String displayName) {\n"; + m += Tab(1) + "super(context, serviceName, displayName, new SecurityInfo("; + + for (auto& attr : iface.GetAttributes().GetAttrs()) { + if (attr->GetKey() == "ca_path") { + m += "\"" + attr->GetValue() + "\", "; + securityCheck = true; + } else if (attr->GetKey() == "cert_path") { + m += "\"" + attr->GetValue() + "\", "; + securityCheck = true; + } else if (attr->GetKey() == "private_key") { + m += "\"" + attr->GetValue() + "\", "; + securityCheck = true; + } + } + + auto const pos = m.find_last_of(','); + m = m.substr(0, pos); + + if (securityCheck) + m += "));"; /* super(serviceName, displayName, new SecurityInfo(a,b,c)); */ + else + m += ");"; /* super(serviceName, displayName); */ + + m += NLine(1); + m += "}"; + + GenTemplate(AddIndent(TAB_SIZE * 1, m), stream, + [&]()->std::string { + return iface.GetID(); + }); +} + +void JavaCionStubGen::GenCommonMethods(std::ofstream& stream) { + stream << CB_COMMON_METHODS; } } // namespace tidl diff --git a/idlc/gen_cion/java_cion_stub_gen.h b/idlc/gen_cion/java_cion_stub_gen.h index 1ad43f0..2916bcf 100644 --- a/idlc/gen_cion/java_cion_stub_gen.h +++ b/idlc/gen_cion/java_cion_stub_gen.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef IDLC_GEN_CION_JAVA_CION_STUB_GEN_H_ -#define IDLC_GEN_CION_JAVA_CION_STUB_GEN_H_ +#ifndef IDLC_JAVA_CION_GEN_JAVA_STUB_GEN_H_ +#define IDLC_JAVA_CION_GEN_JAVA_STUB_GEN_H_ #include #include @@ -33,14 +33,20 @@ class JavaCionStubGen : public JavaCionGeneratorBase { void OnFiniGen(std::ofstream& stream) override; private: - void GenNamespace(std::ofstream& stream); void GenInterface(std::ofstream& stream, const Interface& iface); + void GenServiceBase(std::ofstream& stream, const Interface& iface); + void GenReceivedAsyncEvent(std::ofstream& stream, const Interface& iface); + void GenReceivedSyncEvent(std::ofstream& stream, const Interface& iface); + void GenConnectionRequestedEvent(std::ofstream& stream); + void GenConnectedEvent(std::ofstream& stream); + void GenDisconnectedEvent(std::ofstream& stream); void GenCtor(std::ofstream& stream, const Interface& iface); - void GenAsyncReceiver(std::ofstream& stream, const Interface& iface); - void GenSyncReceiver(std::ofstream& stream, const Interface& iface); - void GenInvocation(std::ofstream& stream, const Declaration& decl); + void GenCommonMethods(std::ofstream& stream); + void GenDeclarations(std::ofstream& stream, const Declarations& decls); + void GenSyncInvocation(std::ofstream& stream, const Declaration& decl); + bool GenAsyncInvocation(std::ofstream& stream, const Declaration& decl); }; } // namespace tidl -#endif // IDLC_GEN_CION_JAVA_CION_STUB_GEN_H_ +#endif // IDLC_JAVA_CION_GEN_JAVA_STUB_GEN_H_ \ No newline at end of file diff --git a/idlc/gen_cion/java_cion_stub_gen_cb.h b/idlc/gen_cion/java_cion_stub_gen_cb.h new file mode 100644 index 0000000..e7bed24 --- /dev/null +++ b/idlc/gen_cion/java_cion_stub_gen_cb.h @@ -0,0 +1,309 @@ +/* + * Copyright (c) 2021 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_JAVA_CION_GEN_JAVA_STUB_GEN_CB_H_ +#define IDLC_JAVA_CION_GEN_JAVA_STUB_GEN_CB_H_ + +const char CB_DATA_MEMBERS[] = +R"__java_cb( private List _services = new LinkedList(); + private Class _serviceType; + private static final String _tidlVersion = ""; +)__java_cb"; + +const char CB_SERVICE_BASE_FRONT[] = +R"__java_cb( + public abstract class ServiceBase { + String serviceName; + String displayName; + PeerInfo client; + PeerInfo connectionRequestClient; + ServerBase serverBase; + + /// + /// The name of service + /// + public String getServiceName() { + return serviceName; + } + + /// + /// The display name of service + /// + public String getDisplayName() { + return displayName; + } + + /// + /// The PeerInfo of client + /// + public PeerInfo getClient() { + return client; + } + + protected ServiceBase() {} + + /// + /// Disconnects from the client app + /// + /// + /// Thrown when an internal IO error occurrs. + /// + public void disconnect() { + if (client != null) + serverBase.disconnect(client); + } + + /// + /// Accepts the connection request from the client. + /// + public void accept() { + if (connectionRequestClient != null) + serverBase.accept(connectionRequestClient); + } + + /// + /// Rejects the connection request from the client. + /// + /// The reason why reject the connection request. + public void reject(String reason) { + if (connectionRequestClient != null) + serverBase.reject(connectionRequestClient, reason); + } + + /// + /// This method will be called when connection requested from the client + /// + public abstract void onConnectionRequest(); + + /// + /// This method will be called when received file payload. + /// + public abstract void onFilePayloadReceived(FilePayload file, PayloadTransferStatus status); + + /// + /// This method will be called when the client is disconnected + /// + public abstract void onTerminate(); + + /// + /// This method will be called when the client is connected + /// + public abstract void onConnected(); + +)__java_cb"; + +const char CB_ON_RECEIVED_ASYNC_EVENT_FRONT[] = +R"__java_cb( + @Override + public void onPayloadReceived(PeerInfo info, IPayload data, PayloadTransferStatus status) { + try { + CionParcel p; + ServiceBase b = null; + + for (ServiceBase i : _services) { + if (i.client == null) + continue; + + if (i.client.getAppId().equals(info.getAppId()) && + i.client.getUuid().equals(info.getUuid())) { + b = i; + break; + } + } + + if (b == null) + return; + + if (data.getType() == IPayload.PayloadType.PAYLOAD_FILE) { + b.onFilePayloadReceived((FilePayload)data, status); + return; + } + + DataPayload dp = (DataPayload)data; + p = new CionParcel(dp.getData()); + int cmd = p.readInt(); + switch (cmd) { +)__java_cb"; + +const char CB_ON_RECEIVED_ASYNC_EVENT_BACK[] = +R"__java_cb( + default: + return; + } + } catch (Exception e) { + return; + } + } +)__java_cb"; + +const char CB_ON_RECEIVED_SYNC_EVENT_FRONT[] = +R"__java_cb( + @Override + public byte[] onDataReceived(PeerInfo info, byte[] data) { + CionParcel p; + byte[] returnData = new byte[0]; + + p = new CionParcel(data); + try { + ServiceBase b = null; + + for (ServiceBase i : _services) { + if (i.client == null) + continue; + + if (i.client.getAppId().equals(info.getAppId()) && + i.client.getUuid().equals(info.getUuid())) { + b = i; + break; + } + } + + if (b == null) + return returnData; + + CionParcel result = new CionParcel(); + int cmd = p.readInt(); + + switch (cmd) { +)__java_cb"; + +const char CB_ON_RECEIVED_SYNC_EVENT_BACK[] = +R"__java_cb( + default: + return returnData; + } + + return returnData; + } catch (Exception e) { + return returnData; + } + } +)__java_cb"; + + +const char CB_ON_CONNECTIONREQUESTED_EVENT[] = +R"__java_cb( + @Override + public void onConnectionRequest(PeerInfo peerInfo) { + ServiceBase s; + try { + final Object o = _serviceType.newInstance(); + s = (ServiceBase) o; + } catch (Exception e) { + return; + } + + s.serviceName = getServiceName(); + s.displayName = getDisplayName(); + s.connectionRequestClient = peerInfo; + s.serverBase = this; + s.onConnectionRequest(); + _services.add(s); + } +)__java_cb"; + +const char CB_ON_CONNECTED_EVENT[] = +R"__java_cb( + @Override + public void onConnectionResult(PeerInfo peerInfo, ConnectionResult result) { + for (ServiceBase i : _services) { + if (i.connectionRequestClient == null) + continue; + + if (i.connectionRequestClient.getAppId().equals(peerInfo.getAppId()) && + i.connectionRequestClient.getUuid().equals(peerInfo.getUuid())) { + if (result.status == ConnectionResult.ConnectionStatus.CONNECTION_OK) { + i.client = i.connectionRequestClient; + i.connectionRequestClient = null; + i.onConnected(); + } else { + _services.remove(i); + } + break; + } + } + } + +)__java_cb"; + +const char CB_ON_DISCONNECTED_EVENT[] = +R"__java_cb( + @Override + public void onDisconnected(PeerInfo peerInfo) { + for (ServiceBase i : _services) { + if (i.client == null) + continue; + + if (i.client.getAppId().equals(peerInfo.getAppId()) && + i.client.getUuid().equals(peerInfo.getUuid())) { + i.onTerminate(); + _services.remove(i); + break; + } + } + } +)__java_cb"; + +const char CB_COMMON_METHODS[] = +R"__java_cb( + /// + /// Listens to client apps + /// + /// The type object for making service instances + /// + /// Thrown when internal I/O error happen. + /// + /// + /// Thrown when serviceType is invalid. + /// + /// + /// Thrown when the listen operation is already in progress. + /// + /// + /// Thrown when an application does not have the privilege to access this method. + /// + /// http://tizen.org/privilege/d2d.datasharing + /// http://tizen.org/privilege/internet + public void listen(Class serviceType) { + _serviceType = serviceType; + super.listen(); + } + + /// + /// Stops the listen operation. + /// + /// Thrown when the server is not listening. + public void stop() { + super.stop(); + _services.clear(); + } + + /// + /// Gets service objects which are connected + /// + /// The enumerable service objects which are connected + public List getServices() { + return _services; + } +)__java_cb"; + + +constexpr const char CB_INVOCATION_RESULT_PRE[] = +R"__java_cb( +result.write(__RESULT); +)__java_cb"; + +#endif // IDLC_JAVA_CION_GEN_JAVA_STUB_GEN_CB_H_ diff --git a/idlc/gen_cion/java_cion_stub_repo_gen.cc b/idlc/gen_cion/java_cion_stub_repo_gen.cc index 46fef63..fba2945 100644 --- a/idlc/gen_cion/java_cion_stub_repo_gen.cc +++ b/idlc/gen_cion/java_cion_stub_repo_gen.cc @@ -30,7 +30,7 @@ JavaCionStubRepoGen::JavaCionStubRepoGen( } void JavaCionStubRepoGen::OnInitGen(std::ofstream& stream) { - std::string fname = MakeDir(FileName, "/data"); + std::string fname = MakeDir(FileName, "/server"); if (fname.empty()) return; @@ -38,10 +38,9 @@ void JavaCionStubRepoGen::OnInitGen(std::ofstream& stream) { if (i->GetType() != Block::TYPE_INTERFACE) continue; - stream.open(fname + "/" + GetRepoClassName(i->GetID()) + ".java"); - stream << "package org.tizen.gen." << FileName << ".data;" << NLine(2); - stream << ReplaceAll(DEFAULT_STUB_REPO, - "##", GetRepoClassName(i->GetID())) << NLine(1); + stream.open(fname + "/ServerBase.java"); + stream << "package org.tizen.gen." << FileName << ".server;" << NLine(2); + stream << DEFAULT_STUB_REPO << NLine(1); stream.close(); } } diff --git a/idlc/gen_cion/java_cion_utility_gen.cc b/idlc/gen_cion/java_cion_utility_gen.cc index aaeb5eb..b547fcc 100644 --- a/idlc/gen_cion/java_cion_utility_gen.cc +++ b/idlc/gen_cion/java_cion_utility_gen.cc @@ -30,17 +30,17 @@ JavaCionUtilityGen::JavaCionUtilityGen( } void JavaCionUtilityGen::OnInitGen(std::ofstream& stream) { - std::string fname = MakeDir(FileName, "/utility"); + std::string fname = MakeDir(FileName, "/common"); if (fname.empty()) return; stream.open(fname + "/Out.java"); - stream << "package org.tizen.gen." << FileName << ".utility;" << NLine(2); + stream << "package org.tizen.gen." << FileName << ".common;" << NLine(2); stream << OUT_CLASS; stream.close(); stream.open(fname + "/Ref.java"); - stream << "package org.tizen.gen." << FileName << ".utility;" << NLine(2); + stream << "package org.tizen.gen." << FileName << ".common;" << NLine(2); stream << REF_CLASS; stream.close(); } diff --git a/idlc/main.cc b/idlc/main.cc index 087b6c2..d73339a 100644 --- a/idlc/main.cc +++ b/idlc/main.cc @@ -50,9 +50,7 @@ #include "idlc/gen_cion/java_cion_proxy_repo_gen.h" #include "idlc/gen_cion/java_cion_utility_gen.h" #include "idlc/gen_cion/java_cion_structure_gen.h" -#include "idlc/gen_cion/java_cion_data_gen.h" -#include "idlc/gen_cion/java_cion_interface_gen.h" -#include "idlc/gen_cion/java_cion_stub_base_service_gen.h" +#include "idlc/gen_cion/java_cion_common_gen.h" void GenerateStubCodes(std::shared_ptr options, tidl::Parser& ps) { @@ -98,14 +96,8 @@ void GenerateStubCodes(std::shared_ptr options, tidl::JavaCionStructureGen structures(ps.GetDoc()); structures.Run(options->GetOutput(), true); - tidl::JavaCionDataGen data(ps.GetDoc()); - data.Run(options->GetOutput(), true); - - tidl::JavaCionInterfaceGen ifgen(ps.GetDoc()); - ifgen.Run(options->GetOutput(), true); - - tidl::JavaCionStubBaseServiceGen sb_service(ps.GetDoc()); - sb_service.Run(options->GetOutput(), true); + tidl::JavaCionCommonGen cgen(ps.GetDoc()); + cgen.Run(options->GetOutput(), true); break; } @@ -196,11 +188,8 @@ void GenerateProxyCodes(std::shared_ptr options, tidl::JavaCionStructureGen structures(ps.GetDoc()); structures.Run(options->GetOutput(), true); - tidl::JavaCionDataGen data(ps.GetDoc()); - data.Run(options->GetOutput(), true); - - tidl::JavaCionInterfaceGen ifgen(ps.GetDoc()); - ifgen.Run(options->GetOutput(), true); + tidl::JavaCionCommonGen cgen(ps.GetDoc()); + cgen.Run(options->GetOutput(), true); break; } -- 2.7.4