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 \
--- /dev/null
+/*
+ * 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 <sys/stat.h>
+#include <unistd.h>
+
+#include <ctime>
+#include <vector>
+
+namespace tidl {
+
+JavaCionCommonGen::JavaCionCommonGen(
+ std::shared_ptr<Document> 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, "<DELEGATOR_IDS>", 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<Interface&>(*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
* 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 <memory>
#include <string>
#include <map>
-#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<Document> doc);
- virtual ~JavaCionDataGen() = default;
+ explicit JavaCionCommonGen(std::shared_ptr<Document> 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_
+++ /dev/null
-/*
- * 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 <sys/stat.h>
-#include <unistd.h>
-
-#include <ctime>
-#include <vector>
-
-namespace tidl {
-
-JavaCionDataGen::JavaCionDataGen(
- std::shared_ptr<Document> 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
*/
#include "idlc/gen_cion/java_cion_gen_base.h"
+#include "idlc/gen_cion/java_cion_gen_cb.h"
#include <sys/stat.h>
#include <unistd.h>
: 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"}
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"},
};
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"}
};
}
<< "public static final int __"
<< i->GetID() << " = " << cnt++ << ";" << NLine(1);
}
+ stream << NLine(1);
}
void JavaCionGeneratorBase::GenDeclaration(std::ofstream& stream,
}
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;
}
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(
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;
}
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;
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<const Structure&>(*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<const Structure&>(*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<const Interface&>(*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, "<CLS_NAME>", decl.GetID());
+ str = ReplaceAll(str, "<CALLBACK_PARAMS>",
+ GetParameters(decl.GetParameters()));
+ str = ReplaceAll(str, "<METHOD_ON_INVOKED>",
+ GetOnInvoked(decl, id));
+ str = ReplaceAll(str, "<IFACE_NAME>",id);
+ str = ReplaceAll(str, "<DELEGATOR_NAME>",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, "<CLS_NAME>", decl.GetID());
+ str = ReplaceAll(str, "<CALLBACK_PARAMS>",
+ GetParameters(decl.GetParameters()));
+ str = ReplaceAll(str, "<IFACE_NAME>",id);
+ str = ReplaceAll(str, "<DELEGATOR_NAME>",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, "<SERIALIZE>", 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_FILE>", 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
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;
std::map<std::string, std::string> type_map_;
std::map<std::string, std::string> meta_type_map_;
std::map<std::string, std::string> parcel_reader_map_;
+ std::map<std::string, const BaseType*> serializer_list_;
};
} // namespace tidl
#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<ArrayList<ConnectedPeer>> getConnectedPeerLiveData() {
- return connectedPeerLiveData;
- }
-
- public LiveData<String> getLogsLiveData() {
- return logsLiveData;
- }
-
- public LiveData<ReceivedDataInfo> getReceivedDataLiveData() {
- return receivedDataLiveData;
- }
-
- public LiveData<ReceivedPayloadInfo> 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<ArrayList<DiscoveredPeer>> getDiscoveredPeerLiveData() {
- return discoveredPeerLiveData;
- }
-
- public LiveData<ReceivedPayloadInfo> 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<String> getLogsLiveData() {
- return logsLiveData;
- }
-)__java_cb";
const char DEFAULT_PROXY_REPO[] =
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<ArrayList<DiscoveredPeer>> discoveredPeerLiveData;
- private MutableLiveData<ReceivedPayloadInfo> receivedPayloadInfoLiveData;
- private static volatile ## instance;
private Context context;
- private MutableLiveData<String> logsLiveData;
- private ##(Context context, String serviceName) {
- discoveredPeerLiveData = new MutableLiveData<>();
- discoveredPeerLiveData.setValue(new ArrayList<DiscoveredPeer>());
- 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<DiscoveredPeer> 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<DiscoveredPeer> 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<DiscoveredPeer> 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) {
}
return null;
}
-
- public MutableLiveData<ArrayList<DiscoveredPeer>> getDiscoveredPeerLiveData() {
- return discoveredPeerLiveData;
- }
-
- public MutableLiveData<ReceivedPayloadInfo> getReceivedPayloadInfoLiveData() {
- return receivedPayloadInfoLiveData;
- }
-
- public MutableLiveData<String> getLogsLiveData() {
- return logsLiveData;
- }
}
)__java_cb";
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<ArrayList<ConnectedPeer>> connectedPeerLiveData;
- private MutableLiveData<ReceivedPayloadInfo> receivedPayloadInfoLiveData;
- private MutableLiveData<ReceivedDataInfo> receivedDataInfoLiveData;
- private static volatile ## instance;
private Context context;
- private MutableLiveData<String> logsLiveData;
- private BlockingDeque<byte[]> syncCallRespQue;
-
- private ##(Context context, String serviceName, String displayName) {
- connectedPeerLiveData = new MutableLiveData<>();
- connectedPeerLiveData.setValue(new ArrayList<ConnectedPeer>());
- 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<ReceivedDataInfo> getReceivedDataInfoLiveData() {
- return receivedDataInfoLiveData;
+ public String getServiceName() {
+ return serviceName;
}
- public LiveData<ReceivedPayloadInfo> 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<ConnectedPeer> 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<ConnectedPeer> 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<ConnectedPeer> 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<ConnectedPeer> 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<ArrayList<ConnectedPeer>> getConnectedPeerLiveData() {
- return connectedPeerLiveData;
- }
-
- public MutableLiveData<String> 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);
}
}
const char REF_CLASS[] =
R"__java_cb(
-class Ref<T> {
+public class Ref<T> {
T s;
public void set(T value) {
s = value;
)__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;
+<DELEGATOR_IDS>
-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 <CLS_NAME> extends DelegatorBase {
-public final class ConnectedPeer {
+ public <CLS_NAME>(boolean once) {
+ super(DelegatorBase.<IFACE_NAME>_<DELEGATOR_NAME>__, once);
+ }
- @NonNull
- private final PeerInfo info;
+ public <CLS_NAME>() {
+ super(DelegatorBase.<IFACE_NAME>_<DELEGATOR_NAME>__, false);
+ }
- @NonNull
- private boolean isConnected;
+ @Override
+ public void onInvoked(CionParcel parcel) {
+<METHOD_ON_INVOKED>
+ }
- public ConnectedPeer(@NonNull PeerInfo info, @NonNull boolean isConnected) {
- this.info = info;
- this.isConnected = isConnected;
+ public void onInvoked(<CALLBACK_PARAMS>) {}
}
+)__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 <CLS_NAME> extends DelegatorBase {
+ private PeerInfo peerInfo;
+ private WeakReference<ServiceBase> service;
+ private boolean valid = true;
+ private <IFACE_NAME> serverBase;
+
+ public <CLS_NAME>(PeerInfo info, WeakReference<ServiceBase> service) {
+ super(DelegatorBase.<IFACE_NAME>_<DELEGATOR_NAME>__, false);
+ this.peerInfo = info;
+ this.service = service;
+ this.serverBase = (<IFACE_NAME>) service.get().serverBase;
+ }
- public String getPeerDevicePlatform() {
- return info.getDevicePlatform();
+ @Override
+ public void onInvoked(CionParcel parcel) {}
+
+ public void Invoke(<CALLBACK_PARAMS>) {
+ if (service.get() == null)
+ throw new InvalidProtocolException();
+ if (isOnce() && !valid)
+ throw new InvalidCallbackException();
+
+ CionParcel p = new CionParcel();
+
+ p.write(__CALLBACK);
+ serialize(p, this);
+<SERIALIZE>
+ // Send
+ DataPayload dp = new DataPayload(p.toByteArray());
+ serverBase.sendPayloadAsync(dp);
+ valid = false;
+<SHARE_FILE>
+ }
}
+)__java_cb";
- public int getPeerChannelId() {
- return info.getChannelId();
- }
+const char CB_SHARE_FILE_DEF[] =
+R"__java_cb(
+ private void shareFile(List<String> 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_
+++ /dev/null
-/*
- * 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 <sys/stat.h>
-#include <unistd.h>
-
-#include <ctime>
-#include <vector>
-
-namespace tidl {
-
-JavaCionInterfaceGen::JavaCionInterfaceGen(
- std::shared_ptr<Document> 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<Interface&>(*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
+++ /dev/null
-/*
- * 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 <memory>
-#include <string>
-#include <map>
-
-#include "idlc/gen_cion/java_cion_gen_base.h"
-
-namespace tidl {
-
-class JavaCionInterfaceGen : public JavaCionGeneratorBase {
- public:
- explicit JavaCionInterfaceGen(std::shared_ptr<Document> 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_
/*
- * 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.
*/
#include "idlc/gen_cion/java_cion_proxy_gen.h"
-#include "idlc/gen_cion/java_cion_gen_cb.h"
-
-#include <sys/stat.h>
-#include <unistd.h>
-#include <vector>
+namespace {
+#include "idlc/gen_cion/java_cion_gen_cb.h"
+#include "idlc/gen_cion/java_cion_proxy_gen_cb.h"
+}
namespace tidl {
: 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<Interface&>(*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();
}
}
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<ArrayList<DiscoveredPeer>> discoveredPeerLiveData;"
- << NLine(1);
- stream << Tab(1) << "private LiveData<String> logsLiveData;" << NLine(1);
- stream << Tab(1)
- << "private LiveData<ReceivedPayloadInfo> receivedPayloadInfoLiveData;"
- << NLine(1);
- stream << Tab(1) << "private ArrayList<ProxyDelegator> delegators;" << NLine(1);
- stream << NLine(1);
- GenCtor(stream, iface);
+ stream << ReplaceAll(CB_DATA_MEMBERS, "<VERSION>", 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()) {
stream << Tab(1) << "public ";
GenDeclaration(stream, *i, false);
- stream << " throws IOException ";
GenBrace(stream, TAB_SIZE * 1, [&]() {
GenInvocation(stream, *i);
}, false);
}
}
-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
* 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 <memory>
#include <string>
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
--- /dev/null
+/*
+ * 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 = "<VERSION>";
+ private boolean _online = false;
+ private Object _lock = new Object();
+ private List<DelegatorBase> _delegateList = new LinkedList<DelegatorBase>();
+)__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(
+ /// <summary>
+ /// Starts discovering cion servers.
+ /// </summary>
+ /// <exception cref="InvalidOperationException">Thrown when the discovery operation is already in progress.</exception>
+ @Override
+ public void tryDiscovery() {
+ super.tryDiscovery();
+ }
+
+ /// <summary>
+ /// Connects to the stub app.
+ /// </summary>
+ /// <param name="peer">The peer to connect.</param>
+ /// <privilege>http://tizen.org/privilege/d2d.datasharing</privilege>
+ /// <privilege>http://tizen.org/privilege/internet</privilege>
+ /// <exception cref="PermissionDeniedException">
+ /// Thrown when the permission is denied.
+ /// </exception>
+ /// <remark> If you want to use this method, you must add privileges.</remark>
+ @Override
+ public void tryConnect(PeerInfo peer) {
+ super.tryConnect(peer);
+ }
+
+ /// <summary>
+ /// Disconnects from the stub app.
+ /// </summary>
+ @Override
+ public void disconnect() {
+ super.disconnect();
+ }
+
+ /// <summary>
+ /// Disposes delegate objects in this interface
+ /// </summary>
+ /// <param name="tag">The tag string from delegate object</param>
+ 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_
}
void JavaCionProxyRepoGen::OnInitGen(std::ofstream& stream) {
- std::string fname = MakeDir(FileName, "/data");
+ std::string fname = MakeDir(FileName, "/client");
if (fname.empty())
return;
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();
}
}
}
void JavaCionStructureGen::OnInitGen(std::ofstream& stream) {
- std::string fname = MakeDir(FileName, "/data");
+ std::string fname = MakeDir(FileName, "/common");
if (fname.empty())
return;
continue;
Structure& st = static_cast<Structure&>(*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();
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()) {
stream << NLine(1);
}
- GenSerializer(stream, st);
stream << NLine(1);
- GenDeserializer(stream, st);
-
GenTemplate(variable, stream,
[&]()->std::string {
std::string str;
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";
void JavaCionStructureGen::GenGetter(std::ofstream& stream,
const Element& ele) {
const char getter[] =
- "public $$ Get$$() {\n" \
+ "public $$ get$$() {\n" \
" return $$_;\n" \
"}\n";
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
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
+++ /dev/null
-/*
- * 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 <sys/stat.h>
-#include <unistd.h>
-
-#include <ctime>
-#include <vector>
-
-namespace tidl {
-
-JavaCionStubBaseServiceGen::JavaCionStubBaseServiceGen(
- std::shared_ptr<Document> 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<Interface&>(*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
+++ /dev/null
-/*
- * 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 <memory>
-#include <string>
-#include <map>
-
-#include "idlc/gen_cion/java_cion_gen_base.h"
-
-namespace tidl {
-
-class JavaCionStubBaseServiceGen : public JavaCionGeneratorBase {
- public:
- explicit JavaCionStubBaseServiceGen(std::shared_ptr<Document> 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_
/*
- * 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.
*/
#include "idlc/gen_cion/java_cion_stub_gen.h"
-#include "idlc/gen_cion/java_cion_gen_cb.h"
-
-#include <sys/stat.h>
-#include <unistd.h>
-#include <vector>
+namespace {
+#include "idlc/gen_cion/java_cion_gen_cb.h"
+#include "idlc/gen_cion/java_cion_stub_gen_cb.h"
+}
namespace tidl {
: 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<Interface&>(*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<ArrayList<ConnectedPeer>> connectedPeerLiveData;"
- << NLine(1);
- stream << Tab(1) << "private LiveData<String> logsLiveData;" << NLine(1);
- stream << Tab(1)
- << "private LiveData<ReceivedPayloadInfo> receivedPayloadLiveData;"
- << NLine(1);
- stream << Tab(1)
- << "private LiveData<ReceivedDataInfo> receivedDataLiveData;"
- << NLine(1);
- stream << Tab(1)
- << "private " << GetServiceBaseClassName(iface.GetID()) << " service;"
- << NLine(1);
- stream << NLine(1);
+ stream << ReplaceAll(CB_DATA_MEMBERS, "<VERSION>", 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
* 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 <memory>
#include <string>
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
--- /dev/null
+/*
+ * 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<ServiceBase> _services = new LinkedList<ServiceBase>();
+ private Class<?> _serviceType;
+ private static final String _tidlVersion = "<VERSION>";
+)__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;
+
+ /// <summary>
+ /// The name of service
+ /// </summary>
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ /// <summary>
+ /// The display name of service
+ /// </summary>
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ /// <summary>
+ /// The PeerInfo of client
+ /// </summary>
+ public PeerInfo getClient() {
+ return client;
+ }
+
+ protected ServiceBase() {}
+
+ /// <summary>
+ /// Disconnects from the client app
+ /// </summary>
+ /// <exception cref="System.InvalidOperationException">
+ /// Thrown when an internal IO error occurrs.
+ /// </exception>
+ public void disconnect() {
+ if (client != null)
+ serverBase.disconnect(client);
+ }
+
+ /// <summary>
+ /// Accepts the connection request from the client.
+ /// </summary>
+ public void accept() {
+ if (connectionRequestClient != null)
+ serverBase.accept(connectionRequestClient);
+ }
+
+ /// <summary>
+ /// Rejects the connection request from the client.
+ /// </summary>
+ /// <param name="reason">The reason why reject the connection request.</param>
+ public void reject(String reason) {
+ if (connectionRequestClient != null)
+ serverBase.reject(connectionRequestClient, reason);
+ }
+
+ /// <summary>
+ /// This method will be called when connection requested from the client
+ /// </summary>
+ public abstract void onConnectionRequest();
+
+ /// <summary>
+ /// This method will be called when received file payload.
+ /// </summary>
+ public abstract void onFilePayloadReceived(FilePayload file, PayloadTransferStatus status);
+
+ /// <summary>
+ /// This method will be called when the client is disconnected
+ /// </summary>
+ public abstract void onTerminate();
+
+ /// <summary>
+ /// This method will be called when the client is connected
+ /// </summary>
+ 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(
+ /// <summary>
+ /// Listens to client apps
+ /// </summary>
+ /// <param name="serviceType">The type object for making service instances</param>
+ /// <exception cref="InvalidIOException">
+ /// Thrown when internal I/O error happen.
+ /// </exception>
+ /// <exception cref="ArgumentException">
+ /// Thrown when serviceType is invalid.
+ /// </exception>
+ /// <exception cref="InvalidOperationException">
+ /// Thrown when the listen operation is already in progress.
+ /// </exception>
+ /// <exception cref="UnauthorizedAccessException">
+ /// Thrown when an application does not have the privilege to access this method.
+ /// </exception>
+ /// <privilege>http://tizen.org/privilege/d2d.datasharing</privilege>
+ /// <privilege>http://tizen.org/privilege/internet</privilege>
+ public void listen(Class<?> serviceType) {
+ _serviceType = serviceType;
+ super.listen();
+ }
+
+ /// <summary>
+ /// Stops the listen operation.
+ /// </summary>
+ /// <exception cref="InvalidOperationException">Thrown when the server is not listening.</exception>
+ public void stop() {
+ super.stop();
+ _services.clear();
+ }
+
+ /// <summary>
+ /// Gets service objects which are connected
+ /// </summary>
+ /// <returns>The enumerable service objects which are connected</returns>
+ public List<ServiceBase> 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_
}
void JavaCionStubRepoGen::OnInitGen(std::ofstream& stream) {
- std::string fname = MakeDir(FileName, "/data");
+ std::string fname = MakeDir(FileName, "/server");
if (fname.empty())
return;
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();
}
}
}
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();
}
#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<tidl::Options> options,
tidl::Parser& ps) {
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;
}
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;
}