namespace tidl {
CsCionGeneratorBase::CsCionGeneratorBase(std::shared_ptr<Document> doc)
- : Generator(doc) {
+ : CionPluginBase(std::move(doc)) {
type_map_ = {
{"char", "byte"}, {"int", "int"}, {"short", "short"},
{"long", "long"}, {"string", "string"}, {"bool", "bool"},
if (hasFile == false)
return;
- stream << CB_SHARE_FILE_DEF << NLine(1);
+ ReplaceAll(CB_SHARE_FILE_DEF)
+ .Change("<SHARE_FILE>", GetTransportable().Cs().GenFileSend("path"))
+ .Out(stream);
}
void CsCionGeneratorBase::AddSerializerList(const BaseType& type) {
#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 CsCionGeneratorBase : public Generator {
+class CsCionGeneratorBase : public CionPluginBase {
public:
explicit CsCionGeneratorBase(std::shared_ptr<Document> doc);
virtual ~CsCionGeneratorBase() = default;
private void TryShareFile(string path)
{
- if (path == null)
- throw new ArgumentException("Invalid path");
-
- FilePayload fp = new FilePayload(path);
- base.SendPayloadAsync(fp);
+ <SHARE_FILE>
}
)__cs_cb";
void CsCionGroupGen::OnInitGen(std::ofstream& stream) {
GenVersion(stream);
- stream << "using System;" << NLine(1)
- << "using System.Collections.Generic;" << NLine(1)
- << "using System.Threading;" << NLine(1)
- << "using Tizen.Applications;" << NLine(1)
- << "using Tizen.Applications.RPCPort;" << NLine(1)
- << "using Tizen.Applications.Cion;" << NLine(1);
+ stream << GetTransportable().Cs().GenInclude();
GenNamespace(stream);
}
stream << Tab(2) << "public class " << iface.GetID()
<< " : GroupBase" << NLine(1);
GenBrace(stream, TAB_SIZE * 2, [&]() {
- stream << ReplaceAll(CB_DATA_MEMBERS, "<VERSION>", FULLVER);
+ ReplaceAll(CB_DATA_MEMBERS)
+ .Change("<PEER_INFO_T>", GetTransportable().Cs().GenPeerInfoType())
+ .Out(stream);
GenEvents(stream, iface);
stream << NLine(1);
GenMethodId(stream, iface, true);
- stream << CB_EVENT_METHODS;
+ ReplaceAll(CB_EVENT_METHODS)
+ .Change("<PEER_INFO_T>", GetTransportable().Cs().GenPeerInfoType())
+ .Out(stream);
GenSerializer(stream);
GenListSerializer(stream);
GenCtor(stream, iface);
void CsCionGroupGen::GenCionPayloadReceivedEvent(std::ofstream& stream,
const Interface& iface) {
- stream << CB_ON_PAYLOAD_RECEIVED_FRONT;
+ ReplaceAll(CB_ON_PAYLOAD_RECEIVED_FRONT)
+ .Change("<PEER_INFO_T>", GetTransportable().Cs().GenPeerInfoType())
+ .Change("<PAYLOAD_T>", GetTransportable().Cs().GenPayloadType())
+ .Out(stream);
for (const auto& i : iface.GetDeclarations()) {
if (i->GetMethodType() == Declaration::MethodType::DELEGATE ||
* <VERSION> Version of TIDL Compiler.
*/
const char CB_DATA_MEMBERS[] =
-R"__cs_cb( public delegate void JoinedHandler(object sender, PeerInfo peerInfo);
- public delegate void LeftHandler(object sender, PeerInfo peerInfo);
+R"__cs_cb( public delegate void JoinedHandler(object sender, <PEER_INFO_T> peerInfo);
+ public delegate void LeftHandler(object sender, <PEER_INFO_T> peerInfo);
/// <summary>
/// This event will be invoked when the peer group app is joined to the topic.
const char CB_EVENT_METHODS[] =
R"__cs_cb(
- protected override void OnJoined(PeerInfo peerInfo)
+ protected override void OnJoined(<PEER_INFO_T> peerInfo)
{
Joined?.Invoke(this, peerInfo);
}
- protected override void OnLeft(PeerInfo peerInfo)
+ protected override void OnLeft(<PEER_INFO_T> peerInfo)
{
Left?.Invoke(this, peerInfo);
}
const char CB_ON_PAYLOAD_RECEIVED_FRONT[] =
R"__cs_cb(
- protected override void OnPayloadReceived(Payload payload, PeerInfo peerInfo)
+ protected override void OnPayloadReceived(<PAYLOAD_T> payload, <PEER_INFO_T> peerInfo)
{
Parcel parcelReceived;
void CsCionProxyGen::OnInitGen(std::ofstream& stream) {
GenVersion(stream);
- stream << "using System;" << NLine(1)
- << "using System.Collections.Generic;" << NLine(1)
- << "using System.Threading;" << NLine(1)
- << "using Tizen.Applications;" << NLine(1)
- << "using Tizen.Applications.RPCPort;" << NLine(1)
- << "using Tizen.Applications.Cion;" << NLine(1);
+ stream << GetTransportable().Cs().GenInclude();
GenNamespace(stream);
}
stream << Tab(2) << "public class " << iface.GetID()
<< " : ClientBase" << NLine(1);
GenBrace(stream, TAB_SIZE * 2, [&]() {
- stream << ReplaceAll(CB_DATA_MEMBERS, "<VERSION>", FULLVER);
+ ReplaceAll(CB_DATA_MEMBERS)
+ .Change("<PEER_INFO_T>", GetTransportable().Cs().GenPeerInfoType())
+ .Change("<PAYLOAD_TRANSFER_STATUS>",
+ GetTransportable().Cs().GenPayloadTransferStatusType())
+ .Out(stream);
GenCallbacks(stream, iface, true);
GenDelegateId(stream, iface);
GenMethodId(stream, iface);
void CsCionProxyGen::GenConnectMethod(std::ofstream& stream,
const Interface& iface) {
- stream << CB_CONNECT_METHOD;
+ ReplaceAll(CB_CONNECT_METHOD)
+ .Change("<PEER_INFO_T>", GetTransportable().Cs().GenPeerInfoType())
+ .Out(stream);
stream << NLine(1);
}
* <VERSION> Version of TIDL Compiler.
*/
const char CB_DATA_MEMBERS[] =
-R"__cs_cb( public delegate void DiscoveredEvent(object sender, PeerInfo peerInfo);
+R"__cs_cb( public delegate void DiscoveredEvent(object sender, <PEER_INFO_T> peerInfo);
public delegate void DisconnectedEvent(object sender);
- public delegate void FileReceivedEvent(object sender, FilePayload payload, PayloadTransferStatus status);
+ public delegate void FileReceivedEvent(object sender, FilePayload payload, <PAYLOAD_TRANSFER_STATUS> status);
public delegate void ConnectionResultEvent(object sender, ConnectionResult result);
public event DiscoveredEvent Discovered;
const char CB_EVENT_METHODS[] =
R"__cs_cb(
- protected override void OnConnectionResult(PeerInfo peerInfo, ConnectionResult result)
+ protected override void OnConnectionResult(<PEER_INFO_T> peerInfo, ConnectionResult result)
{
- if (result.Status == ConnectionStatus.OK)
- {
+ if (result.Status == ConnectionStatus.OK)
+ {
_online = true;
- }
+ }
ConnectionResult?.Invoke(this, result);
}
- protected override void OnDisconnected(PeerInfo peerInfo)
+ protected override void OnDisconnected(<PEER_INFO_T> peerInfo)
{
_online = false;
Disconnected?.Invoke(this);
}
- protected override void OnDiscovered(PeerInfo peerInfo)
+ protected override void OnDiscovered(<PEER_INFO_T> peerInfo)
{
Discovered?.Invoke(this, peerInfo);
}
- protected override void OnPayloadReceived(Payload payload, PayloadTransferStatus status)
+ protected override void OnPayloadReceived(<PAYLOAD_T> payload, <PAYLOAD_TRANSFER_STATUS> status)
{
- if(payload.PayloadType == PayloadType.FilePayload)
+ if(payload.PayloadType == <PAYLOAD_TYPE_FILE>)
{
FileReceived?.Invoke(this, (FilePayload)payload, status);
}
/// Thrown when the permission is denied.
/// </exception>
/// <remark> If you want to use this method, you must add privileges.</remark>
- public new void Connect(PeerInfo peer)
+ public new void Connect(<PEER_INFO_T> peer)
{
base.Connect(peer);
}
const char CB_ASYNC_INVOCATION_MID[] =
R"__cs_cb( // Send
- DataPayload dp = new DataPayload(p.ToBytes());
+ DataPayload dp = new DataPayload(p.ToBytes());
base.SendPayloadAsync(dp);
)__cs_cb";
void CsCionStubGen::OnInitGen(std::ofstream& stream) {
GenVersion(stream);
- stream << "using System;" << NLine(1)
- << "using System.Collections.Generic;" << NLine(1)
- << "using Tizen.Applications;" << NLine(1)
- << "using Tizen.Applications.RPCPort;" << NLine(1)
- << "using Tizen.Applications.Cion;" << NLine(1);
+ stream << GetTransportable().Cs().GenInclude();
GenNamespace(stream);
}
stream << Tab(2) << "public sealed class " << iface.GetID()
<< " : ServerBase" << NLine(1);
GenBrace(stream, TAB_SIZE * 2, [&]() {
- stream << ReplaceAll(CB_DATA_MEMBERS, "<VERSION>", FULLVER);
GenServiceBase(stream, iface);
GenCallbacks(stream, iface, false);
GenDelegateId(stream, iface);
}
void CsCionStubGen::GenServiceBase(std::ofstream& stream, const Interface& iface) {
- stream << CB_SERVICE_BASE_FRONT;
+ ReplaceAll(CB_SERVICE_BASE_FRONT)
+ .Change("<PEER_INFO_T>", GetTransportable().Cs().GenPeerInfoType())
+ .Change("<PAYLOAD_TRANSFER_STATUS>",
+ GetTransportable().Cs().GenPayloadTransferStatusType())
+ .Out(stream);
GenDeclarations(stream, iface.GetDeclarations());
stream << NLine(1);
stream << AddIndent(TAB_SIZE * 3, "}\n");
void CsCionStubGen::GenReceivedSyncEvent(std::ofstream& stream,
const Interface& iface) {
- stream << CB_ON_RECEIVED_SYNC_EVENT_FRONT;
+ ReplaceAll(CB_ON_RECEIVED_SYNC_EVENT_FRONT)
+ .Change("<PEER_INFO_T>", GetTransportable().Cs().GenPeerInfoType())
+ .Out(stream);
for (const auto& i : iface.GetDeclarations()) {
if (i->GetMethodType() != Declaration::MethodType::SYNC)
continue;
void CsCionStubGen::GenReceivedAsyncEvent(std::ofstream& stream,
const Interface& iface) {
- stream << CB_ON_RECEIVED_ASYNC_EVENT_FRONT;
+ ReplaceAll(CB_ON_RECEIVED_ASYNC_EVENT_FRONT)
+ .Change("<PEER_INFO_T>", GetTransportable().Cs().GenPeerInfoType())
+ .Change("<PAYLOAD_TRANSFER_STATUS>",
+ GetTransportable().Cs().GenPayloadTransferStatusType())
+ .Change("<PAYLOAD_T>", GetTransportable().Cs().GenPayloadType())
+ .Change("<PAYLOAD_TYPE_FILE>",
+ GetTransportable().Cs().GenPayloadTypeFile())
+ .Out(stream);
for (const auto& i : iface.GetDeclarations()) {
if (i->GetMethodType() != Declaration::MethodType::ASYNC)
continue;
}
void CsCionStubGen::GenConnectionRequestedEvent(std::ofstream& stream) {
- stream << CB_ON_CONNECTIONREQUESTED_EVENT;
+ ReplaceAll(CB_ON_CONNECTIONREQUESTED_EVENT)
+ .Change("<PEER_INFO_T>", GetTransportable().Cs().GenPeerInfoType())
+ .Out(stream);
}
void CsCionStubGen::GenConnectedEvent(std::ofstream& stream) {
- stream << CB_ON_CONNECTED_EVENT;
+ ReplaceAll(CB_ON_CONNECTED_EVENT)
+ .Change("<PEER_INFO_T>", GetTransportable().Cs().GenPeerInfoType())
+ .Out(stream);
}
void CsCionStubGen::GenDisconnectedEvent(std::ofstream& stream) {
- stream << CB_ON_DISCONNECTED_EVENT;
+ ReplaceAll(CB_ON_DISCONNECTED_EVENT)
+ .Change("<PEER_INFO_T>", GetTransportable().Cs().GenPeerInfoType())
+ .Out(stream);
}
void CsCionStubGen::GenCtor(std::ofstream& stream, const Interface& iface) {
/// <summary>
/// The PeerInfo of client
/// </summary>
- public PeerInfo Client
+ public <PEER_INFO_T> Client
{
get; internal set;
}
- internal PeerInfo ConnectionRequestClient;
+ internal <PEER_INFO_T> ConnectionRequestClient;
internal ServerBase ServerBase;
/// <summary>
/// This method will be called when received file payload.
/// </summary>
- public abstract void OnFilePayloadReceived(FilePayload file, PayloadTransferStatus status);
+ public abstract void OnFilePayloadReceived(FilePayload file, <PAYLOAD_TRANSFER_STATUS> status);
/// <summary>
/// This method will be called when the client is disconnected
const char CB_ON_RECEIVED_ASYNC_EVENT_FRONT[] =
R"__cs_cb(
- protected override void OnPayloadReceived(Payload data, PeerInfo peerInfo, PayloadTransferStatus status)
+ protected override void OnPayloadReceived(<PAYLOAD_T> data, <PEER_INFO_T> peerInfo, <PAYLOAD_TRANSFER_STATUS> status)
{
try
{
return;
}
- if (data.PayloadType == PayloadType.FilePayload)
+ if (data.PayloadType == <PAYLOAD_TYPE_FILE>)
{
b.OnFilePayloadReceived((FilePayload)data, status);
return;
const char CB_ON_RECEIVED_SYNC_EVENT_FRONT[] =
R"__cs_cb(
- protected override byte[] OnDataReceived(byte[] data, PeerInfo peerInfo)
+ protected override byte[] OnDataReceived(byte[] data, <PEER_INFO_T> peerInfo)
{
Parcel p;
byte[] returnData = new byte[0];
const char CB_ON_CONNECTIONREQUESTED_EVENT[] =
R"__cs_cb(
- protected override void OnConnectionRequest(PeerInfo peerInfo)
+ protected override void OnConnectionRequest(<PEER_INFO_T> peerInfo)
{
ServiceBase s = Activator.CreateInstance(_serviceType) as ServiceBase;
s.ServiceName = base.ServiceName;
const char CB_ON_CONNECTED_EVENT[] =
R"__cs_cb(
- protected override void OnConnectionResult(PeerInfo peerInfo, ConnectionResult result)
+ protected override void OnConnectionResult(<PEER_INFO_T> peerInfo, ConnectionResult result)
{
foreach (var i in _services)
{
const char CB_ON_DISCONNECTED_EVENT[] =
R"__cs_cb(
- protected override void OnDisconnected(PeerInfo peerInfo)
+ protected override void OnDisconnected(<PEER_INFO_T> peerInfo)
{
foreach (var i in _services)
{
}
- /// <summary>
- /// Stops the listen operation.
- /// </summary>
- /// <exception cref="InvalidOperationException">Thrown when the server is not listening.</exception>
- public new void Stop()
- {
- base.Stop();
- _services.Clear();
- }
-
- /// <summary>
- /// Sets ondemand launch enabled flag.
- /// </summary>
- /// <param name="enable">Whether ondemand launch is enabled or not.</param>
- /// <exception cref="UnauthorizedAccessException">
- /// Thrown when an application does not have the privilege to access this method.
- /// </exception>
- /// <privilege>http://tizen.org/privilege/d2d.remotelaunch</privilege>
- public new void SetOndemandLaunchEnabled(bool enable)
- {
- base.SetOndemandLaunchEnabled(enable);
- }
+ /// <summary>
+ /// Stops the listen operation.
+ /// </summary>
+ /// <exception cref="InvalidOperationException">Thrown when the server is not listening.</exception>
+ public new void Stop()
+ {
+ base.Stop();
+ _services.Clear();
+ }
+
+ /// <summary>
+ /// Sets ondemand launch enabled flag.
+ /// </summary>
+ /// <param name="enable">Whether ondemand launch is enabled or not.</param>
+ /// <exception cref="UnauthorizedAccessException">
+ /// Thrown when an application does not have the privilege to access this method.
+ /// </exception>
+ /// <privilege>http://tizen.org/privilege/d2d.remotelaunch</privilege>
+ public new void SetOndemandLaunchEnabled(bool enable)
+ {
+ base.SetOndemandLaunchEnabled(enable);
+ }
/// <summary>
/// Gets service objects which are connected
class CsTransportable {
public:
virtual ~CsTransportable() = default;
+ virtual std::string GenInclude() const = 0;
+ virtual std::string GenFileSend(std::string path) const = 0;
+ virtual std::string GenGroupType() const = 0;
+ virtual std::string GenPayloadTransferStatusType() const = 0;
+ virtual std::string GenPeerInfoType() const = 0;
+ virtual std::string GenPayloadType() const = 0;
+ virtual std::string GenClientType() const = 0;
+ virtual std::string GenServerType() 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 GenPayloadTypeData() const = 0;
+ virtual std::string GenPayloadTypeFile() const = 0;
};
} // namespace tidl
--- /dev/null
+/*
+ * 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_cs_transportable.h"
+
+#include <utility>
+
+#include "idlc/gen/replace_all.h"
+
+namespace {
+
+constexpr const char __USING[] =
+R"__cs_cb(
+using System;
+using System.Collections.Generic;
+using Tizen.Applications;
+using Tizen.Applications.Cion;
+)__cs_cb";
+
+constexpr const char __FILE_SEND[] =
+R"__cs_cb(if (path == null)
+ throw new ArgumentException("Invalid path");
+
+ <PAYLOAD_T> fp = new FilePayload(<FILE_PATH>);
+ base.SendPayloadAsync(fp);
+)__cs_cb";
+
+} // namespace
+
+namespace tidl {
+
+std::string DefaultCsTransportable::GenInclude() const {
+ return __USING;
+}
+
+std::string DefaultCsTransportable::GenFileSend(std::string path) const {
+ return std::string(ReplaceAll(__FILE_SEND, {
+ { "<FILE_PATH>", path } }));
+}
+
+std::string DefaultCsTransportable::GenGroupType() const {
+ return "GroupBase";
+}
+
+std::string DefaultCsTransportable::GenPayloadTransferStatusType() const {
+ return "PayloadTransferStatus";
+}
+
+std::string DefaultCsTransportable::GenPeerInfoType() const {
+ return "PeerInfo";
+}
+
+std::string DefaultCsTransportable::GenPayloadType() const {
+ return "Payload";
+}
+
+std::string DefaultCsTransportable::GenClientType() const {
+ return "ClientBase";
+}
+
+std::string DefaultCsTransportable::GenServerType() const {
+ return "ServerBase";
+}
+
+std::string DefaultCsTransportable::GenClientExtraHeader() const {
+ return "";
+}
+
+std::string DefaultCsTransportable::GenClientExtraBody() const {
+ return "";
+}
+
+std::string DefaultCsTransportable::GenServerExtraHeader() const {
+ return "";
+}
+
+std::string DefaultCsTransportable::GenServerExtraBody() const {
+ return "";
+}
+
+std::string DefaultCsTransportable::GenPayloadTypeData() const {
+ return "PayloadType.DataPayload";
+}
+
+std::string DefaultCsTransportable::GenPayloadTypeFile() const {
+ return "PayloadType.FilePayload";
+}
+
+} // namespace tidl
--- /dev/null
+/*
+ * 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_CS_TRANSPORTABLE_H_
+#define IDLC_GEN_CION_DEFAULT_CS_TRANSPORTABLE_H_
+
+#include <string>
+
+#include "idlc/gen_cion/cs_transportable.h"
+
+namespace tidl {
+
+class DefaultCsTransportable : public CsTransportable {
+ public:
+ virtual ~DefaultCsTransportable() = default;
+ std::string GenInclude() const override;
+ std::string GenFileSend(std::string path) const override;
+ std::string GenGroupType() const override;
+ std::string GenPayloadTransferStatusType() const override;
+ std::string GenPeerInfoType() const override;
+ std::string GenPayloadType() const override;
+ std::string GenClientType() const override;
+ std::string GenServerType() const override;
+ std::string GenClientExtraHeader() const override;
+ std::string GenClientExtraBody() const override;
+ std::string GenServerExtraHeader() const override;
+ std::string GenServerExtraBody() const override;
+ std::string GenPayloadTypeData() const override;
+ std::string GenPayloadTypeFile() const override;
+};
+
+} // namespace tidl
+
+#endif // IDLC_GEN_CION_DEFAULT_CS_TRANSPORTABLE_H_
#include "idlc/gen_cion/default_c_transportable.h"
#include "idlc/gen_cion/default_cpp_transportable.h"
#include "idlc/gen_cion/default_java_transportable.h"
+#include "idlc/gen_cion/default_cs_transportable.h"
namespace tidl {
if (plugin_path.empty()) {
C_.reset(new DefaultCTransportable());
Cpp_.reset(new DefaultCppTransportable());
- // Cs_.reset(new DefaultCsTransportable());
+ Cs_.reset(new DefaultCsTransportable());
Java_.reset(new DefaultJavaTransportable());
} else {
// TODO