From: jh9216.park Date: Wed, 20 Oct 2021 11:37:00 +0000 (-0400) Subject: Refactor java generator X-Git-Tag: submit/tizen/20211028.054746~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9ab1eff145b2e19a8e08b5cc3ef32ae5e797236b;p=platform%2Fcore%2Fappfw%2Ftidl.git Refactor java generator - Add API descriptions in generated classes - Add missed methods Change-Id: I179192707910b1ff503fa2b09debbca28e53a4b0 Signed-off-by: jh9216.park --- diff --git a/idlc/gen_cion/java_cion_gen_base.cc b/idlc/gen_cion/java_cion_gen_base.cc index b0eda5db..3ba497a5 100644 --- a/idlc/gen_cion/java_cion_gen_base.cc +++ b/idlc/gen_cion/java_cion_gen_base.cc @@ -69,16 +69,15 @@ JavaCionGeneratorBase::JavaCionGeneratorBase(std::shared_ptr doc) void JavaCionGeneratorBase::GenMethodId(std::ofstream& stream, const Interface& iface) { int cnt = 2; - stream << Tab(1) << "public static final int __RESULT = 0;" << NLine(1); - stream << Tab(1) << "public static final int __CALLBACK = 1;" << NLine(1); + stream << Tab(1) << "public static final int __RESULT = 0;" << NLine(2); + stream << Tab(1) << "public static final int __CALLBACK = 1;" << NLine(2); for (auto& i : iface.GetDeclarations().GetDecls()) { if (i->GetMethodType() == Declaration::MethodType::DELEGATE) continue; stream << Tab(1) << "public static final int __" - << i->GetID() << " = " << cnt++ << ";" << NLine(1); + << i->GetID() << " = " << cnt++ << ";" << NLine(2); } - stream << NLine(1); } void JavaCionGeneratorBase::GenDeclaration(std::ofstream& stream, @@ -613,9 +612,8 @@ void JavaCionGeneratorBase::GenDelegateId(std::ofstream& stream, if (i->GetMethodType() != Declaration::MethodType::DELEGATE) continue; stream << Tab(1) << "private static final int __" - << i->GetID() << " = " << cnt++ << ";" << NLine(1); + << i->GetID() << " = " << cnt++ << ";" << NLine(2); } - stream << NLine(1); } void JavaCionGeneratorBase::GenShareFile(std::ofstream& stream, diff --git a/idlc/gen_cion/java_cion_gen_cb.h b/idlc/gen_cion/java_cion_gen_cb.h index d9cb032c..59dba9e8 100644 --- a/idlc/gen_cion/java_cion_gen_cb.h +++ b/idlc/gen_cion/java_cion_gen_cb.h @@ -20,58 +20,104 @@ const char DEFAULT_PROXY_REPO[] = R"__java_cb( - import android.content.Context; -import androidx.lifecycle.MutableLiveData; import org.tizen.cion.*; import java.net.SocketTimeoutException; -import java.util.ArrayList; +/** + * Abstract class for making a client + */ public abstract class ClientBase implements DiscoveryCallback, ClientConnectionLifecycleCallback, PayloadAsyncResultCallback { - private ClientChannel client; - private Context context; - - public ClientBase(Context context, String serviceName) { - client = new ClientChannel(context, serviceName); - this.context = context; - } - - public ClientBase(Context context, String serviceName, SecurityInfo sec) { - client = new ClientChannel(context, serviceName, sec); - this.context = context; - } - + private ClientChannel mClient; + + private Context mContext; + + /** + * Constructor + * @param mContext The Context + * @param serviceName Service name + */ + public ClientBase(Context mContext, String serviceName) { + mClient = new ClientChannel(mContext, serviceName); + this.mContext = mContext; + } + + /** + * Constructor with security information + * @param mContext The context + * @param serviceName Service name + * @param sec Security information + */ + public ClientBase(Context mContext, String serviceName, SecurityInfo sec) { + mClient = new ClientChannel(mContext, serviceName, sec); + this.mContext = mContext; + } + + /** + * Disconnects server + */ public void disconnect() { - client.disconnect(); + mClient.disconnect(); } + /** + * Connects the server + * @param peer Server information + */ public void tryConnect(PeerInfo peer) { - client.tryConnect(peer, this); + mClient.tryConnect(peer, this); } + /** + * Finds available servers + */ public void tryDiscovery() { - client.tryDiscovery(this); + mClient.tryDiscovery(this); + } + + /** + * Stops finding servers + */ + public void stopDiscovery() { + mClient.stopDiscovery(); } + /** + * Sends data payload asynchronously to the connected server + * @param payload Data payload + */ public void sendAsync(DataPayload payload) { - client.sendPayloadAsync(payload, this); + mClient.sendPayloadAsync(payload, this); } + /** + * Sends file payload asynchronously to the connected server + * @param payload File payload + */ public void sendAsync(FilePayload payload) { - client.sendPayloadAsync(payload, this); + mClient.sendPayloadAsync(payload, this); } + /** + * Sends data synchronously to the connected server + * @param data Data to send + * @return Received data + */ public byte[] sendData(byte[] data) { try { - return client.sendData(data, 5000); + return mClient.sendData(data, 5000); } catch (SocketTimeoutException e) { e.printStackTrace(); } return null; } + + @Override + public final void onLost(PeerInfo peerInfo) { + } } )__java_cb"; @@ -80,64 +126,109 @@ const char DEFAULT_STUB_REPO[] = R"__java_cb( import android.content.Context; -import androidx.lifecycle.LiveData; -import androidx.lifecycle.MutableLiveData; - import org.tizen.cion.*; -import java.util.ArrayList; -import java.util.concurrent.BlockingDeque; -import java.util.concurrent.TimeUnit; - -public abstract class ServerBase implements ServerConnectionLifecycleCallback { - private ServerChannel server; - private Context context; - 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; - } - +/** + * Abstract class for making a server + */ +public abstract class ServerBase implements ServerConnectionLifecycleCallback, + PayloadAsyncResultCallback { + private ServerChannel mServer; + + private Context mContext; + + private String mServiceName; + + private String mDisplayName; + + /** + * Constructor + * @param mContext Context + * @param mServiceName Service name + * @param mDisplayName Display name + */ + public ServerBase(Context mContext, String mServiceName, String mDisplayName) { + mServer = new ServerChannel(mContext, mServiceName, mDisplayName); + this.mContext = mContext; + this.mServiceName = mServiceName; + this.mDisplayName = mDisplayName; + } + + /** + * Constructor with security information + * @param mContext Context + * @param mServiceName Service name + * @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); + this.mContext = mContext; + this.mServiceName = mServiceName; + this.mDisplayName = mDisplayName; + } + + /** + * Gets service name + * @return Service name + */ public String getServiceName() { - return serviceName; + return mServiceName; } + /** + * Gets display name + * @return Display name + */ public String getDisplayName() { - return displayName; + return mDisplayName; } + /** + * Waits clients + */ public void listen() { - server.listen(this); + mServer.listen(this); } + /** + * Stops waiting clients + */ public void stop() { - server.stop(); + mServer.stop(); } + /** + * Disconnects the connected client + * @param peerInfo Client information + */ public void disconnect(PeerInfo peerInfo) { - server.disconnect(peerInfo); - } - - public void sendPayloadAsync(IPayload payload) { + mServer.disconnect(peerInfo); } + /** + * Accepts the client + * @param peerInfo Client information + */ public void accept(PeerInfo peerInfo) { - server.acceptRequest(peerInfo); + mServer.acceptRequest(peerInfo); } + /** + * Rejects the client + * @param peerInfo Client information + * @param reason The reason for rejecting the client + */ public void reject(PeerInfo peerInfo, String reason) { - server.rejectRequest(peerInfo, reason); + mServer.rejectRequest(peerInfo, reason); + } + + /** + * Sends data asynchronously to the all connected clients + * @param payload Data + */ + public void sendPayloadAsync(IPayload payload) { + mServer.sendPayloadAsync(payload, this); } } @@ -188,46 +279,79 @@ R"__java_cb( import org.tizen.cion.CionParcel; +/** + * Abstract class for making delegator + */ public abstract class DelegatorBase { - private int id; - private int seqId; - private boolean once; - private static int _seqNum = 0; + private int mId; + + private int mSeqId; + + private boolean mOnce; + + private static int sSeqNum = 0; + + /** + * Constructor + * @param delegateId Delegate ID + * @param once Use only once + */ public DelegatorBase(int delegateId, boolean once) { - this.id = delegateId; - this.seqId = _seqNum++; - this.once = once; + this.mId = delegateId; + this.mSeqId = sSeqNum++; + this.mOnce = once; } + + /** + * This method will be invoked when the remote callback is called + * @param parcel Data + */ public abstract void onInvoked(CionParcel parcel); + /** + * Gets sequence ID + * @return Sequence ID + */ public int getDelegateId() { - return id; + return mId; } + /** + * Gets sequence ID + * @return Sequence ID + */ public int getSequenceId() { - return seqId; + return mSeqId; } + /** + * Gets once flag + * @return Once flag + */ public boolean isOnce() { - return once; + return mOnce; } public static void serialize(CionParcel h, DelegatorBase from) { - h.write(from.id); - h.write(from.seqId); - h.write(from.once); + h.write(from.mId); + h.write(from.mSeqId); + h.write(from.mOnce); } public static void deserialize(CionParcel h, DelegatorBase to) { - to.id = h.readInt(); - to.seqId = h.readInt(); - to.once = h.readBoolean(); + to.mId = h.readInt(); + to.mSeqId = h.readInt(); + to.mOnce = h.readBoolean(); } + /** + * Gets once flag + * @return Once flag + */ public String getTag() { - return (new Integer(id).toString()) + "_" + (new Integer(seqId).toString()); + return (new Integer(mId).toString()) + "_" + (new Integer(mSeqId).toString()); } } @@ -235,21 +359,30 @@ public abstract class DelegatorBase { const char CB_CALLBACK_CLASS_PROXY[] = R"__java_cb( - public static final class extends DelegatorBase { + public static class extends DelegatorBase { + /** + * Constructor + */ public (boolean once) { super(DelegatorBase.___, once); } + /** + * Constructor + */ public () { super(DelegatorBase.___, false); } @Override - public void onInvoked(CionParcel parcel) { + public final void onInvoked(CionParcel parcel) { } + /** + * This method will be invoked when remote callback is called + */ public void onInvoked() {} } )__java_cb"; @@ -257,25 +390,31 @@ R"__java_cb( const char CB_CALLBACK_CLASS_STUB[] = R"__java_cb( public static final class extends DelegatorBase { - private PeerInfo peerInfo; - private WeakReference service; - private boolean valid = true; - private serverBase; + private PeerInfo mPeerInfo; + + private WeakReference mService; + + private boolean mValid = true; + + private mServerBase; public (PeerInfo info, WeakReference service) { super(DelegatorBase.___, false); - this.peerInfo = info; - this.service = service; - this.serverBase = () service.get().serverBase; + this.mPeerInfo = info; + this.mService = service; + this.mServerBase = () service.get().mServerBase; } @Override - public void onInvoked(CionParcel parcel) {} + public final void onInvoked(CionParcel parcel) {} + /** + * Invokes a remote callback + */ public void Invoke() { - if (service.get() == null) + if (mService.get() == null) throw new InvalidProtocolException(); - if (isOnce() && !valid) + if (isOnce() && !mValid) throw new InvalidCallbackException(); CionParcel p = new CionParcel(); @@ -285,8 +424,8 @@ R"__java_cb( // Send DataPayload dp = new DataPayload(p.toByteArray()); - serverBase.sendPayloadAsync(dp); - valid = false; + mServerBase.sendPayloadAsync(dp); + mValid = false; } } diff --git a/idlc/gen_cion/java_cion_proxy_gen.cc b/idlc/gen_cion/java_cion_proxy_gen.cc index 19029c40..adc9529b 100644 --- a/idlc/gen_cion/java_cion_proxy_gen.cc +++ b/idlc/gen_cion/java_cion_proxy_gen.cc @@ -153,15 +153,15 @@ void JavaCionProxyGen::GenInvocation(std::ofstream& stream, const Declaration& d id += ".get()"; m += ConvertTypeToSerializer(pt.GetBaseType(), id, "p"); if (IsDelegateType(pt.GetBaseType())) { - l += "_delegateList.add(" + id + ");\n"; + l += "mDelegateList.add(" + id + ");\n"; } } st += AddIndent(TAB_SIZE * 2, m) + NLine(1); - st += Tab(2) + "synchronized (_lock) {" + NLine(1); + st += Tab(2) + "synchronized (mLock) {" + NLine(1); if (!l.empty()) - st += AddIndent(TAB_SIZE * 2, l) + NLine(1); + st += AddIndent(TAB_SIZE * 3, l) + NLine(1); // Deserialize if (decl.GetMethodType() == Declaration::MethodType::ASYNC) { @@ -205,15 +205,15 @@ void JavaCionProxyGen::GenInvocation(std::ofstream& stream, const Declaration& d c += i->GetID() + ".set(" + i->GetID() + "_raw);" + NLine(1); if (c != "") - st += AddIndent(TAB_SIZE * 2, c); + st += AddIndent(TAB_SIZE * 3, c); } if (decl.GetType().ToString() != "void") { - st += AddIndent(TAB_SIZE * 2, ConvertTypeToDeserializer(decl.GetType(), + st += AddIndent(TAB_SIZE * 3, ConvertTypeToDeserializer(decl.GetType(), "ret", "parcelReceived")); } - st += NLine(1) + Tab(2) + "return ret;" + NLine(1); + st += NLine(1) + Tab(3) + "return ret;" + NLine(1); st += Tab(2) + "}"; return st; diff --git a/idlc/gen_cion/java_cion_proxy_gen_cb.h b/idlc/gen_cion/java_cion_proxy_gen_cb.h index d9ef4d2b..628b1509 100644 --- a/idlc/gen_cion/java_cion_proxy_gen_cb.h +++ b/idlc/gen_cion/java_cion_proxy_gen_cb.h @@ -21,10 +21,14 @@ const char CB_DATA_MEMBERS[] = R"__java_cb( public String serviceName; - private static final String _tidlVersion = ""; - private boolean _online = false; - private Object _lock = new Object(); - private List _delegateList = new LinkedList(); + + private static final String sTidlVersion = ""; + + private boolean mOnline = false; + + private Object mLock = new Object(); + + private List mDelegateList = new LinkedList(); )__java_cb"; const char CB_EVENT_METHODS[] = @@ -34,42 +38,51 @@ R"__java_cb( int seqId = parcel.readInt(); boolean once = parcel.readBoolean(); - for (DelegatorBase i : _delegateList) { + for (DelegatorBase i : mDelegateList) { if (i.getDelegateId() == id && i.getSequenceId() == seqId) { i.onInvoked(parcel); if (i.isOnce()) - _delegateList.remove(i); + mDelegateList.remove(i); break; } } } + /** + * This method will be invoked when this client gets the response from the server + * @param peerInfo Server information + * @param result Connection result + */ @Override public void onConnectionResult(PeerInfo peerInfo, ConnectionResult result) { if (result.status == ConnectionResult.ConnectionStatus.CONNECTION_OK) { - _online = true; + mOnline = true; } } + /** + * This method will be invoked when this client is disconnected from the server + * @param peerInfo Server information + */ @Override public void onDisconnected(PeerInfo peerInfo) { - _online = false; + mOnline = false; } + /** + * This method will be invoked when an available server is discovered + * @param peerInfo Server information + */ @Override public void onDiscovered(PeerInfo peerInfo) { } @Override - public void onLost(PeerInfo peerInfo) { - } - - @Override - public void onResultReceived(PayloadAsyncResult payloadAsyncResult) { + public final void onResultReceived(PayloadAsyncResult payloadAsyncResult) { } @Override - public void onPayloadReceived(IPayload payload, PayloadTransferStatus status) { + public final void onPayloadReceived(IPayload payload, PayloadTransferStatus status) { if(payload.getType() == IPayload.PayloadType.PAYLOAD_FILE) { onFileReceived((FilePayload)payload, status); } else { @@ -84,52 +97,25 @@ R"__java_cb( } } + /** + * This method will be invoked when data for a file is received from the server + * @param payload File data + * @param status Status + */ public void onFileReceived(FilePayload payload, PayloadTransferStatus status) {} )__java_cb"; const char CB_CONNECT_METHOD[] = R"__java_cb( - /// - /// Starts discovering cion servers. - /// - /// Thrown when the discovery operation is already in progress. - @Override - public void tryDiscovery() { - super.tryDiscovery(); - } - - /// - /// Connects to the stub app. - /// - /// The peer to connect. - /// http://tizen.org/privilege/d2d.datasharing - /// http://tizen.org/privilege/internet - /// - /// Thrown when the permission is denied. - /// - /// If you want to use this method, you must add privileges. - @Override - public void tryConnect(PeerInfo peer) { - super.tryConnect(peer); - } - - /// - /// Disconnects from the stub app. - /// - @Override - public void disconnect() { - super.disconnect(); - } - - /// - /// Disposes delegate objects in this interface - /// - /// The tag string from delegate object + /** + * Disposes delegate objects in this interface + * @param tag String handle + */ public void disposeCallback(String tag) { - for (DelegatorBase i : _delegateList) { + for (DelegatorBase i : mDelegateList) { if (i.getTag().equals(tag)) { - _delegateList.remove(i); + mDelegateList.remove(i); return; } } @@ -137,7 +123,7 @@ R"__java_cb( )__java_cb"; const char CB_INVOCATION_PRE[] = -R"__java_cb( if (!_online) +R"__java_cb( if (!mOnline) throw new NotConnectedSocketException(); CionParcel p = new CionParcel(); @@ -146,28 +132,28 @@ $$ const char CB_SHARE_FILE[] = R"__java_cb( - try { + try { $$ - } catch (InvalidArgumentException e) { - } + } catch (InvalidArgumentException e) { + } )__java_cb"; const char CB_ASYNC_INVOCATION_MID[] = R"__java_cb( - // Send - DataPayload dp = new DataPayload(p.toByteArray()); - super.sendAsync(dp); + // 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()); + // Send + byte[] dataReceived = sendData(p.toByteArray()); - CionParcel parcelReceived = new CionParcel(dataReceived); + CionParcel parcelReceived = new CionParcel(dataReceived); - int cmd = parcelReceived.readInt(); - if (cmd != __RESULT) - throw new InvalidProtocolException(); + int cmd = parcelReceived.readInt(); + if (cmd != __RESULT) + throw new InvalidProtocolException(); )__java_cb"; #endif // IDLC_JAVA_CION_GEN_JAVA_PROXY_GEN_CB_H_ diff --git a/idlc/gen_cion/java_cion_structure_gen.cc b/idlc/gen_cion/java_cion_structure_gen.cc index 439470d6..a61f3f9b 100644 --- a/idlc/gen_cion/java_cion_structure_gen.cc +++ b/idlc/gen_cion/java_cion_structure_gen.cc @@ -56,19 +56,11 @@ void JavaCionStructureGen::GenStructure(std::ofstream& stream, stream << NLine(1); stream << "public final class " << st.GetID() << " "; GenBrace(stream, 0, [&]() { - stream << NLine(1); - for (auto& i : st.GetElements().GetElms()) { - GenSetter(stream, *i); - GenGetter(stream, *i); - stream << NLine(1); - } - - stream << NLine(1); GenTemplate(variable, stream, [&]()->std::string { std::string str; for (auto& i : st.GetElements().GetElms()) { - str += NLine(1) + Tab(1); + str += NLine(1) + Tab(1) + "private "; if (i->GetType().GetMetaType() == nullptr) { str += ConvertTypeToString(i->GetType()) + " " + i->GetID() + "_;"; @@ -77,10 +69,17 @@ void JavaCionStructureGen::GenStructure(std::ofstream& stream, + i->GetID() + "_ = new " + ConvertTypeToString(i->GetType()) + "();"; } + str += NLine(1); } - str += NLine(1); + return str; }); + + for (auto& i : st.GetElements().GetElms()) { + GenSetter(stream, *i); + GenGetter(stream, *i); + stream << NLine(1); + } }, false, false); stream << NLine(1); } diff --git a/idlc/gen_cion/java_cion_stub_gen_cb.h b/idlc/gen_cion/java_cion_stub_gen_cb.h index e7bed248..1e3eeb19 100644 --- a/idlc/gen_cion/java_cion_stub_gen_cb.h +++ b/idlc/gen_cion/java_cion_stub_gen_cb.h @@ -18,89 +18,101 @@ #define IDLC_JAVA_CION_GEN_JAVA_STUB_GEN_CB_H_ const char CB_DATA_MEMBERS[] = -R"__java_cb( private List _services = new LinkedList(); - private Class _serviceType; - private static final String _tidlVersion = ""; +R"__java_cb( private List mServices = new LinkedList(); + + private Class mServiceType; + + private static final String sTidlVersion = ""; + )__java_cb"; const char CB_SERVICE_BASE_FRONT[] = R"__java_cb( + /** + * Abstract class for making a service + */ public abstract class ServiceBase { - String serviceName; - String displayName; - PeerInfo client; - PeerInfo connectionRequestClient; - ServerBase serverBase; - - /// - /// The name of service - /// - public String getServiceName() { - return serviceName; + private String mServiceName; + + private String mDisplayName; + + private PeerInfo mClient; + + private PeerInfo mConnectionRequestClient; + + private ServerBase mServerBase; + + /** + * Gets service name + * @return Service name + */ + public String getmServiceName() { + return mServiceName; } - /// - /// The display name of service - /// - public String getDisplayName() { - return displayName; + /** + * Gets display name + * @return Display name + */ + public String getmDisplayName() { + return mDisplayName; } - /// - /// The PeerInfo of client - /// - public PeerInfo getClient() { - return client; + /** + * Gets client information + * @return Client information + */ + public PeerInfo getmClient() { + return mClient; } protected ServiceBase() {} - /// - /// Disconnects from the client app - /// - /// - /// Thrown when an internal IO error occurrs. - /// + /** + * Disconnects from the client app + */ public void disconnect() { - if (client != null) - serverBase.disconnect(client); + if (mClient != null) + mServerBase.disconnect(mClient); } - /// - /// Accepts the connection request from the client. - /// + /** + * Accepts the connection request from the client + */ public void accept() { - if (connectionRequestClient != null) - serverBase.accept(connectionRequestClient); + if (mConnectionRequestClient != null) + mServerBase.accept(mConnectionRequestClient); } - /// - /// Rejects the connection request from the client. - /// - /// The reason why reject the connection request. + /** + * Rejects the connection request from the client + * @param reason The season + */ public void reject(String reason) { - if (connectionRequestClient != null) - serverBase.reject(connectionRequestClient, reason); + if (mConnectionRequestClient != null) + mServerBase.reject(mConnectionRequestClient, reason); } - /// - /// This method will be called when connection requested from the client - /// + /** + * This method will be called when connection requested from the client + */ public abstract void onConnectionRequest(); - /// - /// This method will be called when received file payload. - /// + /** + * This method will be called when received file payload + * @param file File information + * @param status The status + */ public abstract void onFilePayloadReceived(FilePayload file, PayloadTransferStatus status); - /// - /// This method will be called when the client is disconnected - /// + /** + * This method will be called when the client is disconnected + */ public abstract void onTerminate(); - /// - /// This method will be called when the client is connected - /// + /** + * This method will be called when the client is connected + */ public abstract void onConnected(); )__java_cb"; @@ -108,17 +120,17 @@ R"__java_cb( const char CB_ON_RECEIVED_ASYNC_EVENT_FRONT[] = R"__java_cb( @Override - public void onPayloadReceived(PeerInfo info, IPayload data, PayloadTransferStatus status) { + public final void onPayloadReceived(PeerInfo info, IPayload data, PayloadTransferStatus status) { try { CionParcel p; ServiceBase b = null; - for (ServiceBase i : _services) { - if (i.client == null) + for (ServiceBase i : mServices) { + if (i.mClient == null) continue; - if (i.client.getAppId().equals(info.getAppId()) && - i.client.getUuid().equals(info.getUuid())) { + if (i.mClient.getAppId().equals(info.getAppId()) && + i.mClient.getUuid().equals(info.getUuid())) { b = i; break; } @@ -152,7 +164,7 @@ R"__java_cb( const char CB_ON_RECEIVED_SYNC_EVENT_FRONT[] = R"__java_cb( @Override - public byte[] onDataReceived(PeerInfo info, byte[] data) { + public final byte[] onDataReceived(PeerInfo info, byte[] data) { CionParcel p; byte[] returnData = new byte[0]; @@ -160,12 +172,12 @@ R"__java_cb( try { ServiceBase b = null; - for (ServiceBase i : _services) { - if (i.client == null) + for (ServiceBase i : mServices) { + if (i.mClient == null) continue; - if (i.client.getAppId().equals(info.getAppId()) && - i.client.getUuid().equals(info.getUuid())) { + if (i.mClient.getAppId().equals(info.getAppId()) && + i.mClient.getUuid().equals(info.getUuid())) { b = i; break; } @@ -200,18 +212,18 @@ R"__java_cb( public void onConnectionRequest(PeerInfo peerInfo) { ServiceBase s; try { - final Object o = _serviceType.newInstance(); + final Object o = mServiceType.newInstance(); s = (ServiceBase) o; } catch (Exception e) { return; } - s.serviceName = getServiceName(); - s.displayName = getDisplayName(); - s.connectionRequestClient = peerInfo; - s.serverBase = this; + s.mServiceName = getServiceName(); + s.mDisplayName = getDisplayName(); + s.mConnectionRequestClient = peerInfo; + s.mServerBase = this; s.onConnectionRequest(); - _services.add(s); + mServices.add(s); } )__java_cb"; @@ -219,18 +231,18 @@ 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) + for (ServiceBase i : mServices) { + if (i.mConnectionRequestClient == null) continue; - if (i.connectionRequestClient.getAppId().equals(peerInfo.getAppId()) && - i.connectionRequestClient.getUuid().equals(peerInfo.getUuid())) { + if (i.mConnectionRequestClient.getAppId().equals(peerInfo.getAppId()) && + i.mConnectionRequestClient.getUuid().equals(peerInfo.getUuid())) { if (result.status == ConnectionResult.ConnectionStatus.CONNECTION_OK) { - i.client = i.connectionRequestClient; - i.connectionRequestClient = null; + i.mClient = i.mConnectionRequestClient; + i.mConnectionRequestClient = null; i.onConnected(); } else { - _services.remove(i); + mServices.remove(i); } break; } @@ -243,14 +255,14 @@ const char CB_ON_DISCONNECTED_EVENT[] = R"__java_cb( @Override public void onDisconnected(PeerInfo peerInfo) { - for (ServiceBase i : _services) { - if (i.client == null) + for (ServiceBase i : mServices) { + if (i.mClient == null) continue; - if (i.client.getAppId().equals(peerInfo.getAppId()) && - i.client.getUuid().equals(peerInfo.getUuid())) { + if (i.mClient.getAppId().equals(peerInfo.getAppId()) && + i.mClient.getUuid().equals(peerInfo.getUuid())) { i.onTerminate(); - _services.remove(i); + mServices.remove(i); break; } } @@ -259,45 +271,36 @@ R"__java_cb( const char CB_COMMON_METHODS[] = R"__java_cb( - /// - /// Listens to client apps - /// - /// The type object for making service instances - /// - /// Thrown when internal I/O error happen. - /// - /// - /// Thrown when serviceType is invalid. - /// - /// - /// Thrown when the listen operation is already in progress. - /// - /// - /// Thrown when an application does not have the privilege to access this method. - /// - /// http://tizen.org/privilege/d2d.datasharing - /// http://tizen.org/privilege/internet + @Override + public final void onResultReceived(PayloadAsyncResult payloadAsyncResult) { + } + + /** + * Waits clients + * @param serviceType Service class type + */ public void listen(Class serviceType) { - _serviceType = serviceType; + mServiceType = serviceType; super.listen(); } - /// - /// Stops the listen operation. - /// - /// Thrown when the server is not listening. + /** + * Stops the listen operation + */ + @Override public void stop() { super.stop(); - _services.clear(); + mServices.clear(); } - /// - /// Gets service objects which are connected - /// - /// The enumerable service objects which are connected + /** + * Gets service objects which are connected + * @return Service objects which are connected + */ public List getServices() { - return _services; + return mServices; } + )__java_cb";