From 1e43020ef8648f7e93ace0506b472423ada4a993 Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Mon, 4 Apr 2022 13:02:16 +0900 Subject: [PATCH] Adjust plugin structure for type java Change-Id: I734986e3452c82ac55fc624915e4efb7d554df8d Signed-off-by: Ilho Kim --- idlc/gen_cion/default_java_transportable.cc | 229 ++++++++++++++++++++++++++++ idlc/gen_cion/default_java_transportable.h | 66 ++++++++ idlc/gen_cion/java_cion_gen_base.cc | 7 +- idlc/gen_cion/java_cion_gen_base.h | 4 +- idlc/gen_cion/java_cion_gen_cb.h | 81 +++++----- idlc/gen_cion/java_cion_group_gen.cc | 13 +- idlc/gen_cion/java_cion_group_gen_cb.h | 6 +- idlc/gen_cion/java_cion_group_repo_gen.cc | 12 +- idlc/gen_cion/java_cion_proxy_gen.cc | 8 +- idlc/gen_cion/java_cion_proxy_gen_cb.h | 6 +- idlc/gen_cion/java_cion_proxy_repo_gen.cc | 19 ++- idlc/gen_cion/java_cion_stub_gen.cc | 59 ++++++- idlc/gen_cion/java_cion_stub_gen_cb.h | 32 ++-- idlc/gen_cion/java_cion_stub_repo_gen.cc | 15 +- idlc/gen_cion/java_transportable.h | 33 ++++ idlc/gen_cion/plugin_loader.cc | 3 +- 16 files changed, 504 insertions(+), 89 deletions(-) create mode 100644 idlc/gen_cion/default_java_transportable.cc create mode 100644 idlc/gen_cion/default_java_transportable.h diff --git a/idlc/gen_cion/default_java_transportable.cc b/idlc/gen_cion/default_java_transportable.cc new file mode 100644 index 0000000..c9005be --- /dev/null +++ b/idlc/gen_cion/default_java_transportable.cc @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "idlc/gen_cion/default_java_transportable.h" + +#include + +#include "idlc/gen/replace_all.h" + +namespace { + +constexpr const char __SERVER_ACCEPT[] = ".acceptRequest(peerInfo);"; + +constexpr const char __SERVER_STOP[] = ".stop();"; + +constexpr const char __SERVER_REJECT[] = + ".rejectRequest(, );"; + +constexpr const char __CLIENT_TRY_CONNECT[] = + ".tryConnect(, this);"; + +constexpr const char __CLIENT_DISCONNECT[] = + ".disconnect();"; + +constexpr const char __CLIENT_TRY_DISCOVERY[] = + ".tryDiscovery(this);"; + +constexpr const char __CLIENT_STOP_DISCOVERY[] = + ".stopDiscovery();"; + +constexpr const char __CLIENT_SEND_ASYNC[] = + ".sendPayloadAsync(, this);"; + +constexpr const char __CLIENT_SEND[] = +R"__java_cb(try { + return .sendData(, ); + } catch (SocketTimeoutException e) { + e.printStackTrace(); + } + return null;)__java_cb"; + +constexpr const char __SERVER_SEND_ASYNC[] = + ".sendPayloadAsync(, this);"; + +constexpr const char __GROUP_PUBLISH[] = ".publish();"; + +constexpr const char __GROUP_SUBSCRIBE[] = ".subscribe(this);"; + +constexpr const char __GROUP_UNSUBSCRIBE[] = ".unsubscribe();"; + +constexpr const char __SERVER_LISTEN[] = + ".listen(this);"; + +constexpr const char __SERVER_DISCONNECT[] = ".disconnect();"; + +constexpr const char __PEER_INFO_GET_APPID[] = + ".getAppId()"; + +constexpr const char __PEER_INFO_GET_UUID[] = + ".getUuid()"; + +} // namespace + +namespace tidl { + +std::string DefaultJavaTransportable::GenInclude() const { + return "import org.tizen.cion.*;"; +} + +std::string DefaultJavaTransportable::GenClientChannel() const { + return "ClientChannel"; +} + +std::string DefaultJavaTransportable::GenServerChannel() const { + return "ServerChannel"; +} + +std::string DefaultJavaTransportable::GenGroupChannel() const { + return "GroupChannel"; +} + +std::string DefaultJavaTransportable::GenClientSendAsync(std::string client, + std::string payload) const { + return std::string(ReplaceAll(__CLIENT_SEND_ASYNC, { + { "", client }, + { "", payload} })); +} + +std::string DefaultJavaTransportable::GenClientSend(std::string client, + std::string data, std::string data_size) const { + return std::string(ReplaceAll(__CLIENT_SEND, { + { "", client }, + { "", data}, + { "", data_size} })); +} + +std::string DefaultJavaTransportable::GenServerSendAsync(std::string server, + std::string payload) const { + return std::string(ReplaceAll(__SERVER_SEND_ASYNC, { + { "", server }, + { "", payload} })); +} + +std::string DefaultJavaTransportable::GenPeerInfoType() const { + return "PeerInfo"; +} + +std::string DefaultJavaTransportable::GenSecurityType() const { + return "SecurityInfo"; +} + +std::string DefaultJavaTransportable::GenClientTryConnect(std::string client, + std::string peer) const { + return std::string(ReplaceAll(__CLIENT_TRY_CONNECT, { + { "", client }, + { "", peer } })); +} + +std::string DefaultJavaTransportable::GenClientDisconnect( + std::string client) const { + return std::string(ReplaceAll(__CLIENT_DISCONNECT, { + { "", client } })); +} + +std::string DefaultJavaTransportable::GenClientTryDiscovery( + std::string client) const { + return std::string(ReplaceAll(__CLIENT_TRY_DISCOVERY, { + { "", client } })); +} + +std::string DefaultJavaTransportable::GenClientStopDiscovery( + std::string client) const { + return std::string(ReplaceAll(__CLIENT_STOP_DISCOVERY, { + { "", client } })); +} + +std::string DefaultJavaTransportable::GenClientExtraHeader() const { + return ""; +} + +std::string DefaultJavaTransportable::GenClientExtraBody() const { + return ""; +} + +std::string DefaultJavaTransportable::GenServerExtraHeader() const { + return ""; +} + +std::string DefaultJavaTransportable::GenServerExtraBody() const { + return ""; +} + +std::string DefaultJavaTransportable::GenServerAccept( + std::string server) const { + return std::string(ReplaceAll(__SERVER_ACCEPT, { + { "", server } })); +} + +std::string DefaultJavaTransportable::GenServerStop( + std::string server) const { + return std::string(ReplaceAll(__SERVER_STOP, { + { "", server } })); +} + +std::string DefaultJavaTransportable::GenServerReject(std::string server, + std::string peer, std::string reason) const { + return std::string(ReplaceAll(__SERVER_REJECT, { + { "", server }, + { "", peer }, + { "", reason } })); +} + +std::string DefaultJavaTransportable::GenGroupPublish( + std::string group, std::string data) const { + return std::string(ReplaceAll(__GROUP_PUBLISH, { + { "", group }, + { "", data } })); +} + +std::string DefaultJavaTransportable::GenGroupSubscribe( + std::string group) const { + return std::string(ReplaceAll(__GROUP_SUBSCRIBE, { + { "", group } })); +} + +std::string DefaultJavaTransportable::GenGroupUnsubscribe( + std::string group) const { + return std::string(ReplaceAll(__GROUP_UNSUBSCRIBE, { + { "", group } })); +} + +std::string DefaultJavaTransportable::GenServerListen(std::string server) const { + return std::string(ReplaceAll(__SERVER_LISTEN, { + {"", server} })); +} + +std::string DefaultJavaTransportable::GenServerDisconnect(std::string server, + std::string peer) const { + return std::string(ReplaceAll(__SERVER_DISCONNECT, { + { "", server }, + { "", peer } })); +} + +std::string DefaultJavaTransportable::GenPeerInfoGetAppID( + std::string peer) const { + return std::string(ReplaceAll(__PEER_INFO_GET_APPID, { + { "", peer} })); +} + +std::string DefaultJavaTransportable::GenPeerInfoGetUUID( + std::string peer) const { + return std::string(ReplaceAll(__PEER_INFO_GET_UUID, { + { "", peer} })); +} + +} // namespace tidl diff --git a/idlc/gen_cion/default_java_transportable.h b/idlc/gen_cion/default_java_transportable.h new file mode 100644 index 0000000..f49bc28 --- /dev/null +++ b/idlc/gen_cion/default_java_transportable.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IDLC_GEN_CION_DEFAULT_JAVA_TRANSPORTABLE_H_ +#define IDLC_GEN_CION_DEFAULT_JAVA_TRANSPORTABLE_H_ + +#include + +#include "idlc/gen_cion/java_transportable.h" + +namespace tidl { + +class DefaultJavaTransportable : public JavaTransportable { + public: + virtual ~DefaultJavaTransportable() = default; + std::string GenInclude() const override; + std::string GenClientChannel() const override; + std::string GenServerChannel() const override; + std::string GenGroupChannel() const override; + std::string GenClientSendAsync(std::string client, + std::string payload) const override; + std::string GenClientSend(std::string client, std::string data, + std::string data_size) const override; + std::string GenServerSendAsync(std::string server, + std::string payload) const override; + std::string GenPeerInfoType() const override; + std::string GenSecurityType() const override; + std::string GenClientTryConnect(std::string client, + std::string peer) const override; + std::string GenClientDisconnect(std::string client) const override; + std::string GenClientTryDiscovery(std::string client) const override; + std::string GenClientStopDiscovery(std::string client) const override; + std::string GenClientExtraHeader() const override; + std::string GenClientExtraBody() const override; + std::string GenServerExtraHeader() const override; + std::string GenServerExtraBody() const override; + std::string GenServerAccept(std::string server) const override; + std::string GenServerStop(std::string server) const override; + std::string GenServerReject(std::string server, + std::string peer, std::string reason) const override; + std::string GenGroupPublish(std::string group, std::string data) const override; + std::string GenGroupSubscribe(std::string group) const override; + std::string GenGroupUnsubscribe(std::string group) const override; + std::string GenServerListen(std::string server) const override; + std::string GenServerDisconnect(std::string server, + std::string peer) const override; + std::string GenPeerInfoGetAppID(std::string peer) const override; + std::string GenPeerInfoGetUUID(std::string peer) const override; +}; + +} // namespace tidl + +#endif // IDLC_GEN_CION_DEFAULT_JAVA_TRANSPORTABLE_H_ diff --git a/idlc/gen_cion/java_cion_gen_base.cc b/idlc/gen_cion/java_cion_gen_base.cc index dd3c20f..43f5aec 100644 --- a/idlc/gen_cion/java_cion_gen_base.cc +++ b/idlc/gen_cion/java_cion_gen_base.cc @@ -30,7 +30,7 @@ namespace tidl { JavaCionGeneratorBase::JavaCionGeneratorBase(std::shared_ptr doc) - : Generator(doc) { + : CionPluginBase(std::move(doc)) { type_map_ = { {"char", "byte"}, {"int", "int"}, {"short", "short"}, {"long", "long"}, {"string", "String"}, {"bool", "boolean"}, @@ -440,7 +440,10 @@ void JavaCionGeneratorBase::GenCallbackProxy(std::ofstream& stream, void JavaCionGeneratorBase::GenCallbackStub(std::ofstream& stream, const Declaration& decl, const std::string& id) { std::string str; - str = ReplaceAll(CB_CALLBACK_CLASS_STUB, "", decl.GetID()); + str = ReplaceAll(CB_CALLBACK_CLASS_STUB, { + { "", decl.GetID() }, + { "", GetTransportable().Java().GenPeerInfoType() } + }); str = ReplaceAll(str, "", GetParameters(decl.GetParameters())); str = ReplaceAll(str, "",id); diff --git a/idlc/gen_cion/java_cion_gen_base.h b/idlc/gen_cion/java_cion_gen_base.h index 46cb539..0e7700b 100644 --- a/idlc/gen_cion/java_cion_gen_base.h +++ b/idlc/gen_cion/java_cion_gen_base.h @@ -23,11 +23,11 @@ #include "idlc/ast/type.h" #include "idlc/ast/structure.h" -#include "idlc/gen/generator.h" +#include "idlc/gen_cion/cion_plugin_base.h" namespace tidl { -class JavaCionGeneratorBase : public Generator { +class JavaCionGeneratorBase : public CionPluginBase { public: explicit JavaCionGeneratorBase(std::shared_ptr doc); virtual ~JavaCionGeneratorBase() = default; diff --git a/idlc/gen_cion/java_cion_gen_cb.h b/idlc/gen_cion/java_cion_gen_cb.h index 0800c1d..6f50581 100644 --- a/idlc/gen_cion/java_cion_gen_cb.h +++ b/idlc/gen_cion/java_cion_gen_cb.h @@ -22,7 +22,7 @@ const char DEFAULT_PROXY_REPO[] = R"__java_cb( import android.content.Context; -import org.tizen.cion.*; + import java.net.SocketTimeoutException; @@ -31,7 +31,7 @@ import java.net.SocketTimeoutException; */ public abstract class ClientBase implements DiscoveryCallback, ClientConnectionLifecycleCallback, PayloadAsyncResultCallback { - private ClientChannel mClient; + private mClient; private Context mContext; @@ -41,7 +41,7 @@ public abstract class ClientBase implements DiscoveryCallback, * @param serviceName Service name */ public ClientBase(Context mContext, String serviceName) { - mClient = new ClientChannel(mContext, serviceName); + mClient = new (mContext, serviceName); this.mContext = mContext; } @@ -51,8 +51,8 @@ public abstract class ClientBase implements DiscoveryCallback, * @param serviceName Service name * @param sec Security information */ - public ClientBase(Context mContext, String serviceName, SecurityInfo sec) { - mClient = new ClientChannel(mContext, serviceName, sec); + public ClientBase(Context mContext, String serviceName, sec) { + mClient = new (mContext, serviceName, sec); this.mContext = mContext; } @@ -60,29 +60,29 @@ public abstract class ClientBase implements DiscoveryCallback, * Disconnects server */ public void disconnect() { - mClient.disconnect(); + } /** * Connects the server * @param peer Server information */ - public void tryConnect(PeerInfo peer) { - mClient.tryConnect(peer, this); + public void tryConnect( peer) { + } /** * Finds available servers */ public void tryDiscovery() { - mClient.tryDiscovery(this); + } /** * Stops finding servers */ public void stopDiscovery() { - mClient.stopDiscovery(); + } /** @@ -90,7 +90,7 @@ public abstract class ClientBase implements DiscoveryCallback, * @param payload Data payload */ public void sendAsync(DataPayload payload) { - mClient.sendPayloadAsync(payload, this); + } /** @@ -98,7 +98,7 @@ public abstract class ClientBase implements DiscoveryCallback, * @param payload File payload */ public void sendAsync(FilePayload payload) { - mClient.sendPayloadAsync(payload, this); + } /** @@ -107,16 +107,11 @@ public abstract class ClientBase implements DiscoveryCallback, * @return Received data */ public byte[] sendData(byte[] data) { - try { - return mClient.sendData(data, 5000); - } catch (SocketTimeoutException e) { - e.printStackTrace(); - } - return null; + } @Override - public final void onLost(PeerInfo peerInfo) { + public final void onLost( peerInfo) { } } @@ -126,14 +121,14 @@ const char DEFAULT_STUB_REPO[] = R"__java_cb( import android.content.Context; -import org.tizen.cion.*; + /** * Abstract class for making a server */ public abstract class ServerBase implements ServerConnectionLifecycleCallback, PayloadAsyncResultCallback { - private ServerChannel mServer; + private mServer; private Context mContext; @@ -148,7 +143,7 @@ public abstract class ServerBase implements ServerConnectionLifecycleCallback, * @param mDisplayName Display name */ public ServerBase(Context mContext, String mServiceName, String mDisplayName) { - mServer = new ServerChannel(mContext, mServiceName, mDisplayName); + mServer = new (mContext, mServiceName, mDisplayName); this.mContext = mContext; this.mServiceName = mServiceName; this.mDisplayName = mDisplayName; @@ -161,8 +156,8 @@ public abstract class ServerBase implements ServerConnectionLifecycleCallback, * @param mDisplayName Display name * @param sec Security information */ - public ServerBase(Context mContext, String mServiceName, String mDisplayName, SecurityInfo sec) { - mServer = new ServerChannel(mContext, mServiceName, mDisplayName, sec); + public ServerBase(Context mContext, String mServiceName, String mDisplayName, sec) { + mServer = new (mContext, mServiceName, mDisplayName, sec); this.mContext = mContext; this.mServiceName = mServiceName; this.mDisplayName = mDisplayName; @@ -196,30 +191,30 @@ public abstract class ServerBase implements ServerConnectionLifecycleCallback, * Waits clients */ public void listen() { - mServer.listen(this); + } /** * Stops waiting clients */ public void stop() { - mServer.stop(); + } /** * Disconnects the connected client * @param peerInfo Client information */ - public void disconnect(PeerInfo peerInfo) { - mServer.disconnect(peerInfo); + public void disconnect( peerInfo) { + } /** * Accepts the client * @param peerInfo Client information */ - public void accept(PeerInfo peerInfo) { - mServer.acceptRequest(peerInfo); + public void accept( peerInfo) { + } /** @@ -227,8 +222,8 @@ public abstract class ServerBase implements ServerConnectionLifecycleCallback, * @param peerInfo Client information * @param reason The reason for rejecting the client */ - public void reject(PeerInfo peerInfo, String reason) { - mServer.rejectRequest(peerInfo, reason); + public void reject( peerInfo, String reason) { + } /** @@ -236,7 +231,7 @@ public abstract class ServerBase implements ServerConnectionLifecycleCallback, * @param payload Data */ public void sendPayloadAsync(IPayload payload) { - mServer.sendPayloadAsync(payload, this); + } } @@ -246,7 +241,7 @@ const char DEFAULT_GROUP_REPO[] = R"__java_cb( import android.content.Context; -import org.tizen.cion.*; + import java.net.SocketTimeoutException; @@ -254,7 +249,7 @@ import java.net.SocketTimeoutException; * Abstract class for making a group */ public abstract class GroupBase implements GroupConnectionLifecycleCallback{ - private GroupChannel mGroup; + private mGroup; private Context mContext; @@ -264,7 +259,7 @@ public abstract class GroupBase implements GroupConnectionLifecycleCallback{ * @param topicName Topic name */ public GroupBase(Context mContext, String topicName) { - mGroup = new GroupChannel(mContext, topicName); + mGroup = new (mContext, topicName); this.mContext = mContext; } @@ -274,8 +269,8 @@ public abstract class GroupBase implements GroupConnectionLifecycleCallback{ * @param topicName Topic name * @param sec Security information */ - public GroupBase(Context mContext, String topicName, SecurityInfo sec) { - mGroup = new GroupChannel(mContext, topicName, sec); + public GroupBase(Context mContext, String topicName, sec) { + mGroup = new (mContext, topicName, sec); this.mContext = mContext; } @@ -283,14 +278,14 @@ public abstract class GroupBase implements GroupConnectionLifecycleCallback{ * Subscribes the topic. */ public void subscribe() { - mGroup.subscribe(this); + } /** * Unsubscribes the topic. */ public void unsubscribe() { - mGroup.unsubscribe(); + } /** @@ -298,7 +293,7 @@ public abstract class GroupBase implements GroupConnectionLifecycleCallback{ * @param data Data payload */ public void publish(IPayload data) { - mGroup.publish(data); + } } @@ -460,7 +455,7 @@ R"__java_cb( const char CB_CALLBACK_CLASS_STUB[] = R"__java_cb( public static final class extends DelegatorBase { - private PeerInfo mPeerInfo; + private mPeerInfo; private WeakReference mService; @@ -468,7 +463,7 @@ R"__java_cb( private mServerBase; - public (PeerInfo info, WeakReference service) { + public ( info, WeakReference service) { super(DelegatorBase.___, false); this.mPeerInfo = info; this.mService = service; diff --git a/idlc/gen_cion/java_cion_group_gen.cc b/idlc/gen_cion/java_cion_group_gen.cc index 26c8a35..8901b11 100644 --- a/idlc/gen_cion/java_cion_group_gen.cc +++ b/idlc/gen_cion/java_cion_group_gen.cc @@ -41,7 +41,7 @@ void JavaCionGroupGen::OnInitGen(std::ofstream& stream) { stream << std::endl; stream << "import org.tizen.gen." << FileName + ".common.*;" << NLine(2); - stream << "import org.tizen.cion.*;" << NLine(1) + stream << GetTransportable().Java().GenInclude() << NLine(1) << "import android.content.Context;" << NLine(1) << "import java.util.ArrayList;" << NLine(1) << "import java.util.LinkedList;" << NLine(1) @@ -72,7 +72,8 @@ void JavaCionGroupGen::GenInterface(std::ofstream& stream, const Interface& ifac } void JavaCionGroupGen::GenEvents(std::ofstream& stream, const Interface& iface) { - stream << CB_EVENT_METHODS << NLine(1); + stream << ReplaceAll(CB_EVENT_METHODS, + "", GetTransportable().Java().GenPeerInfoType()) << NLine(1); for (const auto& decl : iface.GetDeclarations()) GenEvent(stream, iface, *decl); @@ -88,7 +89,7 @@ void JavaCionGroupGen::GenEvent(std::ofstream& stream, const Interface& iface, << decl.GetID() << " request is delivered." << NLine(1) << Tab(1) << "*/" << NLine(1); - stream << Tab(1) << "public abstract void On" << decl.GetID() << "(PeerInfo peerInfo, "; + stream << Tab(1) << "public abstract void On" << decl.GetID() << "(" << GetTransportable().Java().GenPeerInfoType() << " peerInfo, "; GenParameters(stream, decl.GetParameters()); stream << ");" << NLine(1); } @@ -97,7 +98,8 @@ void JavaCionGroupGen::GenCtor(std::ofstream& stream, const Interface& iface) { bool securityCheck = false; std::string m = "public $$(Context context, String topicName) {\n"; - m += Tab(1) + "super(context, topicName, new SecurityInfo("; + m += Tab(1) + "super(context, topicName, new " + + GetTransportable().Java().GenSecurityType() + "("; for (const auto& attr : iface.GetAttributes()) { if (attr->GetKey() == "ca_path") { @@ -152,7 +154,8 @@ void JavaCionGroupGen::GenMethods(std::ofstream& stream, const Interface& iface) void JavaCionGroupGen::GenCionPayloadReceivedEvent(std::ofstream& stream, const Interface& iface) { - stream << CB_ON_PAYLOAD_RECEIVED_FRONT; + stream << ReplaceAll(CB_ON_PAYLOAD_RECEIVED_FRONT, + "", GetTransportable().Java().GenPeerInfoType()); for (const auto& i : iface.GetDeclarations()) { if (i->GetMethodType() == Declaration::MethodType::DELEGATE || diff --git a/idlc/gen_cion/java_cion_group_gen_cb.h b/idlc/gen_cion/java_cion_group_gen_cb.h index a27d653..cf1cf5a 100644 --- a/idlc/gen_cion/java_cion_group_gen_cb.h +++ b/idlc/gen_cion/java_cion_group_gen_cb.h @@ -34,20 +34,20 @@ R"__java_cb( * This method will be invoked when another peer left from the current group. */ @Override - public void onLeft(PeerInfo peerInfo) { + public void onLeft( peerInfo) { } /** * This method will be invoked when another peer joined from the current group. */ @Override - public void onJoined(PeerInfo peerInfo) { + public void onJoined( peerInfo) { } )__java_cb"; const char CB_ON_PAYLOAD_RECEIVED_FRONT[] = R"__java_cb( @Override - public final void onPayloadReceived(PeerInfo peerInfo, IPayload payload) { + public final void onPayloadReceived( peerInfo, IPayload payload) { if(payload.getType() == IPayload.PayloadType.PAYLOAD_FILE) { return; } diff --git a/idlc/gen_cion/java_cion_group_repo_gen.cc b/idlc/gen_cion/java_cion_group_repo_gen.cc index 2e8a4f9..10626d7 100644 --- a/idlc/gen_cion/java_cion_group_repo_gen.cc +++ b/idlc/gen_cion/java_cion_group_repo_gen.cc @@ -40,7 +40,17 @@ void JavaCionGroupRepoGen::OnInitGen(std::ofstream& stream) { stream.open(fname + "/GroupBase.java"); stream << "package org.tizen.gen." << FileName + ".group;" << NLine(2); - stream << DEFAULT_GROUP_REPO; + stream << ReplaceAll(DEFAULT_GROUP_REPO, { + { "", GetTransportable().Java().GenInclude() }, + { "", GetTransportable().Java().GenGroupChannel() }, + { "", + GetTransportable().Java().GenGroupSubscribe("mGroup") }, + { "", + GetTransportable().Java().GenGroupUnsubscribe("mGroup") }, + { "", + GetTransportable().Java().GenGroupPublish("mGroup", "data") }, + { "", GetTransportable().Java().GenSecurityType() } + }); stream.close(); } } diff --git a/idlc/gen_cion/java_cion_proxy_gen.cc b/idlc/gen_cion/java_cion_proxy_gen.cc index 5ec4ffc..6172e7b 100644 --- a/idlc/gen_cion/java_cion_proxy_gen.cc +++ b/idlc/gen_cion/java_cion_proxy_gen.cc @@ -41,7 +41,7 @@ void JavaCionProxyGen::OnInitGen(std::ofstream& stream) { stream << std::endl; stream << "import org.tizen.gen." << FileName + ".common.*;" << NLine(2); - stream << "import org.tizen.cion.*;" << NLine(1) + stream << GetTransportable().Java().GenInclude() << NLine(1) << "import android.content.Context;" << NLine(1) << "import java.util.ArrayList;" << NLine(1) << "import java.util.LinkedList;" << NLine(1) @@ -64,7 +64,8 @@ void JavaCionProxyGen::GenInterface(std::ofstream& stream, const Interface& ifac GenCallbacks(stream, iface, true); GenDelegateId(stream, iface); GenMethodId(stream, iface); - stream << CB_EVENT_METHODS; + stream << ReplaceAll(CB_EVENT_METHODS, + "", GetTransportable().Java().GenPeerInfoType()); GenSerializer(stream); GenListSerializer(stream); GenShareFile(stream, iface, true); @@ -78,7 +79,8 @@ 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("; + m += Tab(1) + "super(context, serviceName, new " + + GetTransportable().Java().GenSecurityType() + "("; for (const auto& attr : iface.GetAttributes()) { if (attr->GetKey() == "ca_path") { diff --git a/idlc/gen_cion/java_cion_proxy_gen_cb.h b/idlc/gen_cion/java_cion_proxy_gen_cb.h index 628b150..21e560f 100644 --- a/idlc/gen_cion/java_cion_proxy_gen_cb.h +++ b/idlc/gen_cion/java_cion_proxy_gen_cb.h @@ -54,7 +54,7 @@ R"__java_cb( * @param result Connection result */ @Override - public void onConnectionResult(PeerInfo peerInfo, ConnectionResult result) { + public void onConnectionResult( peerInfo, ConnectionResult result) { if (result.status == ConnectionResult.ConnectionStatus.CONNECTION_OK) { mOnline = true; } @@ -65,7 +65,7 @@ R"__java_cb( * @param peerInfo Server information */ @Override - public void onDisconnected(PeerInfo peerInfo) { + public void onDisconnected( peerInfo) { mOnline = false; } @@ -74,7 +74,7 @@ R"__java_cb( * @param peerInfo Server information */ @Override - public void onDiscovered(PeerInfo peerInfo) { + public void onDiscovered( peerInfo) { } @Override diff --git a/idlc/gen_cion/java_cion_proxy_repo_gen.cc b/idlc/gen_cion/java_cion_proxy_repo_gen.cc index 78accc2..b74a3e8 100644 --- a/idlc/gen_cion/java_cion_proxy_repo_gen.cc +++ b/idlc/gen_cion/java_cion_proxy_repo_gen.cc @@ -40,7 +40,24 @@ void JavaCionProxyRepoGen::OnInitGen(std::ofstream& stream) { stream.open(fname + "/ClientBase.java"); stream << "package org.tizen.gen." << FileName + ".client;" << NLine(2); - stream << DEFAULT_PROXY_REPO; + stream << ReplaceAll(DEFAULT_PROXY_REPO, { + { "", GetTransportable().Java().GenInclude() }, + { "", GetTransportable().Java().GenPeerInfoType() }, + { "", GetTransportable().Java().GenClientChannel() }, + { "", GetTransportable().Java() + .GenClientSendAsync("mClient", "payload") }, + { "", GetTransportable().Java() + .GenClientSend("mClient", "data", "5000") }, + { "", GetTransportable().Java() + .GenClientDisconnect("mClient") }, + { "", GetTransportable().Java() + .GenClientTryConnect("mClient", "peer") }, + { "", GetTransportable().Java() + .GenClientTryDiscovery("mClient") }, + { "", GetTransportable().Java() + .GenClientStopDiscovery("mClient") }, + { "", GetTransportable().Java().GenSecurityType() } + }); stream.close(); } } diff --git a/idlc/gen_cion/java_cion_stub_gen.cc b/idlc/gen_cion/java_cion_stub_gen.cc index d26a48e..05129cf 100644 --- a/idlc/gen_cion/java_cion_stub_gen.cc +++ b/idlc/gen_cion/java_cion_stub_gen.cc @@ -42,7 +42,7 @@ void JavaCionStubGen::OnInitGen(std::ofstream& stream) { stream << std::endl; stream << "import org.tizen.gen." << FileName + ".common.*;" << NLine(2); - stream << "import org.tizen.cion.*;" << NLine(1) + stream << GetTransportable().Java().GenInclude() << NLine(1) << "import android.content.Context;" << NLine(1) << "import java.lang.ref.WeakReference;" << NLine(1) << "import java.util.ArrayList;" << NLine(1) @@ -78,7 +78,8 @@ void JavaCionStubGen::GenInterface(std::ofstream& stream, const Interface& iface } void JavaCionStubGen::GenServiceBase(std::ofstream& stream, const Interface& iface) { - stream << CB_SERVICE_BASE_FRONT; + stream << ReplaceAll(CB_SERVICE_BASE_FRONT, + "", GetTransportable().Java().GenPeerInfoType()); GenDeclarations(stream, iface.GetDeclarations()); stream << AddIndent(TAB_SIZE * 1, "}\n"); } @@ -98,7 +99,17 @@ void JavaCionStubGen::GenDeclarations(std::ofstream& stream, void JavaCionStubGen::GenReceivedSyncEvent(std::ofstream& stream, const Interface& iface) { - stream << CB_ON_RECEIVED_SYNC_EVENT_FRONT; + stream << ReplaceAll(CB_ON_RECEIVED_SYNC_EVENT_FRONT, { + { "", GetTransportable().Java().GenPeerInfoType() }, + { "", + GetTransportable().Java().GenPeerInfoGetAppID("i.mClient") }, + { "", + GetTransportable().Java().GenPeerInfoGetAppID("info") }, + { "", + GetTransportable().Java().GenPeerInfoGetUUID("i.mClient") }, + { "", + GetTransportable().Java().GenPeerInfoGetUUID("info") }, + }); for (const auto& i : iface.GetDeclarations()) { if (i->GetMethodType() != Declaration::MethodType::SYNC) continue; @@ -113,7 +124,17 @@ void JavaCionStubGen::GenReceivedSyncEvent(std::ofstream& stream, void JavaCionStubGen::GenReceivedAsyncEvent(std::ofstream& stream, const Interface& iface) { - stream << CB_ON_RECEIVED_ASYNC_EVENT_FRONT; + stream << ReplaceAll(CB_ON_RECEIVED_ASYNC_EVENT_FRONT, { + { "", GetTransportable().Java().GenPeerInfoType() }, + { "", + GetTransportable().Java().GenPeerInfoGetAppID("i.mClient") }, + { "", + GetTransportable().Java().GenPeerInfoGetAppID("info") }, + { "", + GetTransportable().Java().GenPeerInfoGetUUID("i.mClient") }, + { "", + GetTransportable().Java().GenPeerInfoGetUUID("info") }, + }); for (const auto& i : iface.GetDeclarations()) { if (i->GetMethodType() != Declaration::MethodType::ASYNC) continue; @@ -219,21 +240,43 @@ bool JavaCionStubGen::GenAsyncInvocation(std::ofstream& stream, const Declaratio } void JavaCionStubGen::GenConnectionRequestedEvent(std::ofstream& stream) { - stream << CB_ON_CONNECTIONREQUESTED_EVENT; + stream << ReplaceAll(CB_ON_CONNECTIONREQUESTED_EVENT, + "", GetTransportable().Java().GenPeerInfoType()); } void JavaCionStubGen::GenConnectedEvent(std::ofstream& stream) { - stream << CB_ON_CONNECTED_EVENT; + stream << ReplaceAll(CB_ON_CONNECTED_EVENT, { + { "", GetTransportable().Java().GenPeerInfoType() }, + { "", GetTransportable().Java() + .GenPeerInfoGetAppID("i.mConnectionRequestClient") }, + { "", GetTransportable().Java() + .GenPeerInfoGetAppID("peerInfo") }, + { "", GetTransportable().Java() + .GenPeerInfoGetUUID("i.mConnectionRequestClient") }, + { "", GetTransportable().Java() + .GenPeerInfoGetUUID("peerInfo") }, + }); } void JavaCionStubGen::GenDisconnectedEvent(std::ofstream& stream) { - stream << CB_ON_DISCONNECTED_EVENT; + stream << ReplaceAll(CB_ON_DISCONNECTED_EVENT, { + { "", GetTransportable().Java().GenPeerInfoType() }, + { "", + GetTransportable().Java().GenPeerInfoGetAppID("i.mClient") }, + { "", + GetTransportable().Java().GenPeerInfoGetAppID("peerInfo") }, + { "", + GetTransportable().Java().GenPeerInfoGetUUID("i.mClient") }, + { "", + GetTransportable().Java().GenPeerInfoGetUUID("peerInfo") }, + }); } void JavaCionStubGen::GenCtor(std::ofstream& stream, const Interface& iface) { bool securityCheck = false; std::string m = "public $$(Context context, String serviceName, String displayName) {\n"; - m += Tab(1) + "super(context, serviceName, displayName, new SecurityInfo("; + m += Tab(1) + "super(context, serviceName, displayName, new " + + GetTransportable().Java().GenSecurityType() + "("; for (const auto& attr : iface.GetAttributes()) { if (attr->GetKey() == "ca_path") { diff --git a/idlc/gen_cion/java_cion_stub_gen_cb.h b/idlc/gen_cion/java_cion_stub_gen_cb.h index 3fc899b..381b48a 100644 --- a/idlc/gen_cion/java_cion_stub_gen_cb.h +++ b/idlc/gen_cion/java_cion_stub_gen_cb.h @@ -36,9 +36,9 @@ R"__java_cb( private String mDisplayName; - private PeerInfo mClient; + private mClient; - private PeerInfo mConnectionRequestClient; + private mConnectionRequestClient; private ServerBase mServerBase; @@ -70,7 +70,7 @@ R"__java_cb( * Gets client information * @return Client information */ - public PeerInfo getClient() { + public getClient() { return mClient; } @@ -128,7 +128,7 @@ R"__java_cb( const char CB_ON_RECEIVED_ASYNC_EVENT_FRONT[] = R"__java_cb( @Override - public final void onPayloadReceived(PeerInfo info, IPayload data, PayloadTransferStatus status) { + public final void onPayloadReceived( info, IPayload data, PayloadTransferStatus status) { try { CionParcel p; ServiceBase b = null; @@ -137,8 +137,8 @@ R"__java_cb( if (i.mClient == null) continue; - if (i.mClient.getAppId().equals(info.getAppId()) && - i.mClient.getUuid().equals(info.getUuid())) { + if (.equals() && + .equals()) { b = i; break; } @@ -173,7 +173,7 @@ R"__java_cb( const char CB_ON_RECEIVED_SYNC_EVENT_FRONT[] = R"__java_cb( @Override - public final byte[] onDataReceived(PeerInfo info, byte[] data) { + public final byte[] onDataReceived( info, byte[] data) { CionParcel p; byte[] returnData = new byte[0]; @@ -185,8 +185,8 @@ R"__java_cb( if (i.mClient == null) continue; - if (i.mClient.getAppId().equals(info.getAppId()) && - i.mClient.getUuid().equals(info.getUuid())) { + if (.equals() && + .equals()) { b = i; break; } @@ -219,7 +219,7 @@ R"__java_cb( const char CB_ON_CONNECTIONREQUESTED_EVENT[] = R"__java_cb( @Override - public void onConnectionRequest(PeerInfo peerInfo) { + public void onConnectionRequest( peerInfo) { ServiceBase s; try { final Object o = mServiceType.newInstance(); @@ -241,13 +241,13 @@ R"__java_cb( const char CB_ON_CONNECTED_EVENT[] = R"__java_cb( @Override - public void onConnectionResult(PeerInfo peerInfo, ConnectionResult result) { + public void onConnectionResult( peerInfo, ConnectionResult result) { for (ServiceBase i : mServices) { if (i.mConnectionRequestClient == null) continue; - if (i.mConnectionRequestClient.getAppId().equals(peerInfo.getAppId()) && - i.mConnectionRequestClient.getUuid().equals(peerInfo.getUuid())) { + if (.equals() && + .equals()) { if (result.status == ConnectionResult.ConnectionStatus.CONNECTION_OK) { i.mClient = i.mConnectionRequestClient; i.mConnectionRequestClient = null; @@ -265,13 +265,13 @@ R"__java_cb( const char CB_ON_DISCONNECTED_EVENT[] = R"__java_cb( @Override - public void onDisconnected(PeerInfo peerInfo) { + public void onDisconnected( peerInfo) { for (ServiceBase i : mServices) { if (i.mClient == null) continue; - if (i.mClient.getAppId().equals(peerInfo.getAppId()) && - i.mClient.getUuid().equals(peerInfo.getUuid())) { + if (.equals() && + .equals()) { i.onTerminate(); mServices.remove(i); break; diff --git a/idlc/gen_cion/java_cion_stub_repo_gen.cc b/idlc/gen_cion/java_cion_stub_repo_gen.cc index fba2945..513e1e9 100644 --- a/idlc/gen_cion/java_cion_stub_repo_gen.cc +++ b/idlc/gen_cion/java_cion_stub_repo_gen.cc @@ -40,7 +40,20 @@ void JavaCionStubRepoGen::OnInitGen(std::ofstream& stream) { stream.open(fname + "/ServerBase.java"); stream << "package org.tizen.gen." << FileName << ".server;" << NLine(2); - stream << DEFAULT_STUB_REPO << NLine(1); + stream << ReplaceAll(DEFAULT_STUB_REPO, { + { "", GetTransportable().Java().GenInclude() }, + { "", GetTransportable().Java().GenPeerInfoType() }, + { "", GetTransportable().Java().GenServerChannel() }, + { "", GetTransportable().Java().GenServerSendAsync("mServer", "payload") }, + { "", GetTransportable().Java().GenServerListen("mServer") }, + { "", GetTransportable().Java().GenServerAccept("mServer") }, + { "", GetTransportable().Java().GenServerStop("mServer") }, + { "", GetTransportable().Java() + .GenServerDisconnect("mServer", "peerInfo") }, + { "", GetTransportable().Java() + .GenServerReject("mServer", "peerInfo", "reason") }, + { "", GetTransportable().Java().GenSecurityType() } + }) << NLine(1); stream.close(); } } diff --git a/idlc/gen_cion/java_transportable.h b/idlc/gen_cion/java_transportable.h index a46b36e..ec23311 100644 --- a/idlc/gen_cion/java_transportable.h +++ b/idlc/gen_cion/java_transportable.h @@ -24,6 +24,39 @@ namespace tidl { class JavaTransportable { public: virtual ~JavaTransportable() = default; + virtual std::string GenInclude() const = 0; + virtual std::string GenClientChannel() const = 0; + virtual std::string GenServerChannel() const = 0; + virtual std::string GenGroupChannel() const = 0; + virtual std::string GenClientSendAsync(std::string client, + std::string payload) const = 0; + virtual std::string GenClientSend(std::string client, std::string data, + std::string data_size) const = 0; + virtual std::string GenServerSendAsync(std::string server, + std::string payload) const = 0; + virtual std::string GenPeerInfoType() const = 0; + virtual std::string GenSecurityType() const = 0; + virtual std::string GenClientTryConnect(std::string client, + std::string peer) const = 0; + virtual std::string GenClientDisconnect(std::string client) const = 0; + virtual std::string GenClientTryDiscovery(std::string client) const = 0; + virtual std::string GenClientStopDiscovery(std::string client) const = 0; + virtual std::string GenClientExtraHeader() const = 0; + virtual std::string GenClientExtraBody() const = 0; + virtual std::string GenServerExtraHeader() const = 0; + virtual std::string GenServerExtraBody() const = 0; + virtual std::string GenServerAccept(std::string server) const = 0; + virtual std::string GenServerStop(std::string server) const = 0; + virtual std::string GenServerReject(std::string server, + std::string peer, std::string reason) const = 0; + virtual std::string GenGroupPublish(std::string group, std::string data) const = 0; + virtual std::string GenGroupSubscribe(std::string group) const = 0; + virtual std::string GenGroupUnsubscribe(std::string group) const = 0; + virtual std::string GenServerListen(std::string server) const = 0; + virtual std::string GenServerDisconnect(std::string server, + std::string peer) const = 0; + virtual std::string GenPeerInfoGetAppID(std::string peer) const = 0; + virtual std::string GenPeerInfoGetUUID(std::string peer) const = 0; }; } // namespace tidl diff --git a/idlc/gen_cion/plugin_loader.cc b/idlc/gen_cion/plugin_loader.cc index 2372a70..7b7a6d2 100644 --- a/idlc/gen_cion/plugin_loader.cc +++ b/idlc/gen_cion/plugin_loader.cc @@ -18,6 +18,7 @@ #include "idlc/gen_cion/default_c_transportable.h" #include "idlc/gen_cion/default_cpp_transportable.h" +#include "idlc/gen_cion/default_java_transportable.h" namespace tidl { @@ -26,7 +27,7 @@ PluginLoader::PluginLoader(const std::string& plugin_path) { C_.reset(new DefaultCTransportable()); Cpp_.reset(new DefaultCppTransportable()); // Cs_.reset(new DefaultCsTransportable()); - // Java_.reset(new DefaultJavaTransportable()); + Java_.reset(new DefaultJavaTransportable()); } else { // TODO } -- 2.7.4