The 'extension' options is added.
It provides the function that checks whether the pending request exists
or not.
Change-Id: Iab71b0dc8fc5ef7c2d80dd721ed17dc4682f381a
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
void DefaultGenerator::GenCStubCode(std::shared_ptr<Options> options,
const Parser& ps) {
- CStubHeaderGen stub_header(ps.GetDoc());
+ CStubHeaderGen stub_header(ps.GetDoc(), options);
stub_header.EnableNamespace(options->HasNamespace());
stub_header.EnableProxy(false);
stub_header.Run(options->GetOutput() + ".h");
const std::map<std::string, std::unique_ptr<Structure>>& GetStructures();
void GenVersion(std::ofstream& stream);
- virtual void GenIncludeDefaultHeaders(std::ofstream& stream, bool body = true);
+ virtual void GenIncludeDefaultHeaders(std::ofstream& stream,
+ bool body = true);
void GenGNUSourceDefinition(std::ofstream& stream);
virtual std::string GetHandlePrefix();
std::string RemoveLastSpaces(const std::string& str);
GenGNUSourceDefinition(stream);
GenIncludeDefaultHeaders(stream);
GenIncludeHeader(stream);
+ GenIncludeInternalHeader(stream);
GenLogTag(stream, std::string("RPC_PORT_STUB"));
GenLogDefinition(stream);
GenVersionDefinition(stream);
void CStubBodyGen::OnFiniGen(std::ofstream& stream) {
}
+void CStubBodyGen::GenIncludeInternalHeader(std::ofstream& stream) {
+ if (options_->UseExtension())
+ stream << CB_INTENRAL_HEADER_INCLUSION;
+}
+
// @see #CB_THREAD_ENABLE_DEF
void CStubBodyGen::GenThreadEnableDefinition(std::ofstream& stream) {
if (!options_->IsThreadEnabled())
GenInterfaceCallbackPortCheck(stream, iface);
GenInterfaceBase(stream, iface);
+
+ if (options_->UseExtension())
+ GenInterfaceExtensionBase(stream, iface);
}
// @see #CB_INTERFACE_CONTEXT_BASE
stream << SmartIndent(code);
}
+void CStubBodyGen::GenInterfaceExtensionBase(std::ofstream& stream,
+ const Interface& iface) {
+ std::string code(
+ ReplaceAll(CB_INTERFACE_EXTENSION_BASE,
+ {{"<PREFIX>", GetHandlePrefix()}, {"<NAME>", iface.GetID()}}));
+ stream << SmartIndent(code);
+}
+
} // namespace tidl
void OnFiniGen(std::ofstream& stream) override;
private:
+ void GenIncludeInternalHeader(std::ofstream& stream);
void GenThreadEnableDefinition(std::ofstream& stream);
void GenInterfaceMethodHandlerType(std::ofstream& stream);
void GenInterfaceEnums(std::ofstream& stream);
void GenInterfaceCallbackPortCheckDef(std::ofstream& stream,
const Interface& iface);
void GenInterfaceBaseDef(std::ofstream& stream, const Interface& iface);
+ void GenInterfaceExtensionDef(std::ofstream& stream);
void GenInterfaces(std::ofstream& stream);
void GenInterface(std::ofstream& stream, const Interface& iface);
void GenInterfaceCallbackPortCheck(std::ofstream& stream,
const Interface& iface);
void GenInterfaceBase(std::ofstream& stream, const Interface& iface);
+ void GenInterfaceExtensionBase(std::ofstream& stream, const Interface& iface);
std::string GenMethodEnums(const Interface& iface);
std::string GenDelegateEnums(const Interface& iface);
}
)__c_cb";
+constexpr const char CB_INTENRAL_HEADER_INCLUSION[] =
+R"__c_cb(
+#include <rpc-port-internal.h>
+)__c_cb";
+
+/**
+ * <NAME> The name of the interface.
+ */
+constexpr const char CB_INTERFACE_EXTENSION_BASE[] =
+R"__c_cb(
+bool <PREFIX>_<NAME>_has_pending_request(void)
+{
+ bool has_request = false;
+
+ if (__<NAME>.stub == nullptr) {
+ _E("Invalid context");
+ return has_request;
+ }
+
+ rpc_port_stub_has_pending_request(__<NAME>.stub, &has_request);
+ return has_request;
+}
+)__c_cb";
+
#endif // IDLC_C_GEN_C_STUB_BODY_GEN_CB_H_
namespace tidl {
-CStubHeaderGen::CStubHeaderGen(std::shared_ptr<Document> doc)
- : CHeaderGeneratorBase(doc) {}
+CStubHeaderGen::CStubHeaderGen(std::shared_ptr<Document> doc,
+ std::shared_ptr<Options> options)
+ : CHeaderGeneratorBase(doc), options_(std::move(options)) {}
void CStubHeaderGen::OnInitGen(std::ofstream& stream) {
GenVersion(stream);
}
GenInterfaceBase(stream, iface);
+
+ if (options_->UseExtension())
+ GenInterfaceExtensionBase(stream, iface);
}
// @see #CB_INTERFACE_CONTEXT_BASE
stream << SmartIndent(code);
}
+void CStubHeaderGen::GenInterfaceExtensionBase(std::ofstream& stream,
+ const Interface& iface) {
+ std::string code(
+ ReplaceAll(CB_INTERFACE_EXTENSION_BASE,
+ {{"<PREFIX>", GetHandlePrefix()}, {"<NAME>", iface.GetID()}}));
+ stream << SmartIndent(code);
+}
+
} // namespace tidl
#include <string>
#include "idlc/gen/c_header_gen_base.h"
+#include "idlc/options.h"
namespace tidl {
class CStubHeaderGen : public CHeaderGeneratorBase {
public:
- explicit CStubHeaderGen(std::shared_ptr<Document> doc);
+ explicit CStubHeaderGen(std::shared_ptr<Document> doc,
+ std::shared_ptr<Options> options);
virtual ~CStubHeaderGen() = default;
void OnInitGen(std::ofstream& stream) override;
void GenInterfaceDelegateBase(std::ofstream& stream, const Interface& iface,
const Declaration& decl);
void GenInterfaceBase(std::ofstream& stream, const Interface& iface);
+ void GenInterfaceExtensionBase(std::ofstream& stream, const Interface& iface);
std::string GenDelegateParams(const Interface& iface,
const Declaration& decl);
std::string GenMethodParams(const Interface& iface, const Declaration& decl);
std::string GenMethodCallbackDecls(const Interface& iface);
+
+ private:
+ std::shared_ptr<Options> options_;
};
} // namespace tidl
<PREFIX>_<NAME>_<METHOD_NAME>_cb <METHOD_NAME>; /**< This callback function is invoked when the <METHOD_NAME> request is delivered. */
)__c_cb";
+/**
+ * <PREFIX> The prefix of the interface.
+ * <NAME> The name of the interface.
+ */
+constexpr const char CB_INTERFACE_EXTENSION_BASE[] =
+R"__c_cb(
+/**
+ * @brief Checks whether the pending request exists or not.
+ *
+ * @return @c true if the pending request exists, @c false otherwise.
+ */
+bool <PREFIX>_<NAME>_has_pending_request(void);
+)__c_cb";
+
#endif // IDLC_C_GEN_C_STUB_HEADER_GEN_CB_H_
<< "#include <dlog.h>" << NLine(1)
<< NLine(1)
<< "#include \"" << header_file << "\"" << NLine(2);
+ if (options_->UseExtension())
+ stream << CB_INTERNAL_HEADER_INCLUSION;
+
GenLogTag(stream, "RPC_PORT_STUB");
GenLogDefinition(stream);
GenVersionDefinition(stream);
}
void CppStubBodyGen::GenInterface(std::ofstream& stream,
- const Interface& iface) {
+ const Interface& iface) {
GenServiceBase(stream, iface);
GenBodyCallbacks(stream, iface, false);
GenDefaultMethods(stream, iface);
stream << ReplaceAll(CB_DEFAULT_THREAD_METHODS, "##", iface.GetID());
stream << ReplaceAll(CB_DEFAULT_METHODS, "##", iface.GetID());
+
+ if (options_->UseExtension())
+ stream << ReplaceAll(CB_INTERFACE_EXTENSION_BASE, "<NAME>", iface.GetID());
}
void CppStubBodyGen::GenReceivedEvent(std::ofstream& stream,
}
)__cpp_cb";
+constexpr const char CB_INTERNAL_HEADER_INCLUSION[] =
+R"__cpp_cb(
+#include <rpc-port-internal.h>
+)__cpp_cb";
+
+/**
+ * <NAME> The interface name.
+ */
+constexpr const char CB_INTERFACE_EXTENSION_BASE[] =
+R"__cpp_cb(
+bool <NAME>::HasPendingRequest() const {
+ bool has_request = false;
+ rpc_port_stub_has_pending_request(stub_, &has_request);
+ return has_request;
+}
+)__cpp_cb";
+
#endif // IDLC_CPP_GEN_CPP_STUB_BODY_GEN_CB_H_
void CppStubHeaderGen::GenPublicMethods(std::ofstream& stream,
const Interface& iface) {
stream << ReplaceAll(CB_PUBLIC_METHODS, "##", iface.GetID());
+
+ if (options_->UseExtension())
+ stream << CB_INTERFACE_EXTENSION_BASE;
}
} // namespace tidl
)__cpp_cb";
+constexpr const char CB_INTERFACE_EXTENSION_BASE[] =
+R"__cpp_cb(
+ bool HasPendingRequest() const;
+)__cpp_cb";
+
#endif // IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_CB_H_
GenGNUSourceDefinition(stream);
GenIncludeDefaultHeaders(stream);
GenIncludePrivateHeaders(stream);
+ GenIncludeInternalHeaders(stream);
GenIncludeLemHeaders(stream);
GenIncludeHeader(stream);
GenLogTag(stream, std::string("RPC_PORT_STUB"));
stream << CB_PRIVATE_HEADERS;
}
+void CStubBodyGenerator::GenIncludeInternalHeaders(std::ofstream& stream) {
+ if (options_->UseExtension()) stream << CB_INTERNAL_HEADER_INCLUSION;
+}
+
void CStubBodyGenerator::GenDelegateDefinition(std::ofstream& stream) {
if (HasDelegate())
stream << SmartIndent(CB_DELEGATE_DEFS);
GenInterfaceCallbackPortCheck(stream, iface);
GenInterfaceBase(stream, iface);
+ GenInterfaceExtensionBase(stream, iface);
}
// @see #CB_INTERFACE_CONTEXT_BASE
.Out(stream);
}
+// @see #CB_INTERFACE_EXTENSION_BASE
+void CStubBodyGenerator::GenInterfaceExtensionBase(std::ofstream& stream,
+ const Interface& iface) {
+ if (options_->UseExtension()) {
+ ReplaceAll(CB_INTERFACE_EXTENSION_BASE)
+ .Change("<PREFIX>", GetHandlePrefix())
+ .Change("<NAME>", iface.GetID())
+ .Transform([&](std::string code) { return SmartIndent(code); })
+ .Out(stream);
+ }
+}
+
} // namespace version2
} // namespace tidl
private:
void GenIncludePrivateHeaders(std::ofstream& stream);
+ void GenIncludeInternalHeaders(std::ofstream& stream);
void GenThreadEnableDefinition(std::ofstream& stream);
void GenInterfaceMethodHandlerType(std::ofstream& stream);
void GenInterfaceEnums(std::ofstream& stream);
void GenInterfaceCallbackPortCheck(std::ofstream& stream,
const Interface& iface);
void GenInterfaceBase(std::ofstream& stream, const Interface& iface);
+ void GenInterfaceExtensionBase(std::ofstream& stream, const Interface& iface);
std::string GenMethodEnums(const Interface& iface);
std::string GenDelegateEnums(const Interface& iface);
}
)__c_cb";
+constexpr const char CB_INTERNAL_HEADER_INCLUSION[] =
+R"__c_cb(
+#include <rpc-port-internal.h>
+)__c_cb";
+
+/**
+ * <PREFIX> The prefix of the interface.
+ * <NAME> The name of the interface.
+ */
+constexpr const char CB_INTERFACE_EXTENSION_BASE[] =
+R"__c_cb(
+EXPORT_API bool <PREFIX>_<NAME>_has_pending_request(void)
+{
+ bool has_request = false;
+
+ if (__<NAME>.stub == nullptr) {
+ _E("Invalid context");
+ return has_request;
+ }
+
+ rpc_port_stub_has_pending_request(__<NAME>.stub, &has_request);
+ return has_request;
+}
+)__c_cb";
+
} // namespace version2
} // namespace tidl
#include "idlc/gen/version2/c_stub_header_generator.hh"
#include "idlc/gen/version2/c_stub_header_generator_cb.hh"
+#include "idlc/options.h"
namespace tidl {
namespace version2 {
-CStubHeaderGenerator::CStubHeaderGenerator(std::shared_ptr<Document> doc)
- : CHeaderGeneratorBase(doc) {}
+CStubHeaderGenerator::CStubHeaderGenerator(std::shared_ptr<Document> doc,
+ std::shared_ptr<Options> options)
+ : CHeaderGeneratorBase(doc), options_(std::move(options)) {}
void CStubHeaderGenerator::OnInitGen(std::ofstream& stream) {
GenVersion(stream);
}
GenInterfaceBase(stream, iface);
+ GenInterfaceExtensionBase(stream, iface);
}
// @see #CB_INTERFACE_CONTEXT_BASE
.Out(stream);
}
+// @see #CB_INTERFACE_EXTENSION_BASE
+void CStubHeaderGenerator::GenInterfaceExtensionBase(std::ofstream& stream,
+ const Interface& iface) {
+ if (options_->UseExtension()) {
+ ReplaceAll(CB_INTERFACE_EXTENSION_BASE)
+ .Change("<PREFIX>", GetHandlePrefix())
+ .Change("<NAME>", iface.GetID())
+ .Transform([&](std::string code) { return SmartIndent(code); })
+ .Out(stream);
+ }
+}
+
} // namespace version2
} // namespace tidl
#include <string>
#include "idlc/gen/version2/c_header_generator_base.hh"
+#include "idlc/options.h"
namespace tidl {
namespace version2 {
class CStubHeaderGenerator : public CHeaderGeneratorBase {
public:
- explicit CStubHeaderGenerator(std::shared_ptr<Document> doc);
+ CStubHeaderGenerator(std::shared_ptr<Document> doc,
+ std::shared_ptr<Options> options);
virtual ~CStubHeaderGenerator() = default;
void OnInitGen(std::ofstream& stream) override;
void GenInterfaceDelegateBase(std::ofstream& stream, const Interface& iface,
const Declaration& decl);
void GenInterfaceBase(std::ofstream& stream, const Interface& iface);
+ void GenInterfaceExtensionBase(std::ofstream& stream, const Interface& iface);
std::string GenDelegateParams(const Interface& iface,
const Declaration& decl);
std::string GenMethodParams(const Interface& iface, const Declaration& decl);
std::string GenMethodCallbackDecls(const Interface& iface);
+
+ private:
+ std::shared_ptr<Options> options_;
};
} // namespace version2
<PREFIX>_<NAME>_<METHOD_NAME>_cb <METHOD_NAME>; /**< This callback function is invoked when the <METHOD_NAME> request is delivered. */
)__c_cb";
+/**
+ * <PREFIX> The prefix of the interface.
+ * <NAME> The name of the interface.
+ */
+constexpr const char CB_INTERFACE_EXTENSION_BASE[] =
+R"__c_cb(
+bool <PREFIX>_<NAME>_has_pending_request(void);
+)__c_cb";
+
} // namespace version2
} // namespace tidl
GenVersion(stream);
GenIncludeStubBodyHeader(stream);
GenIncludeDefaultHeaders(stream);
+ GenIncludeInternalHeader(stream);
GenLogTag(stream, "RPC_PORT_STUB");
GenLogDefinition(stream);
GenVersionDefinition(stream);
.Out(stream);
}
+void CppStubBodyGenerator::GenIncludeInternalHeader(std::ofstream& stream) {
+ if (options_->UseExtension()) stream << CB_INTERNAL_HEADER_INCLUSION;
+}
+
void CppStubBodyGenerator::GenNamespace(std::ofstream& stream) {
ReplaceAll(CB_NAMESPACE_STUB)
.ChangeToLower("<FILE_NAMESPACE>", GetFileNamespace())
auto& iface = static_cast<Interface&>(*block);
code += GenInterface(iface) + NLine(1);
+ code += GenInterfaceExtensionBase(iface) + NLine(1);
}
return code;
return RemoveLine(code);
}
+std::string CppStubBodyGenerator::GenInterfaceExtensionBase(
+ const Interface& iface) {
+ std::string code;
+ if (options_->UseExtension()) {
+ code +=
+ ReplaceAll(CB_INTERFACE_EXTENSION_BASE, "<CLS_NAME>", iface.GetID());
+ }
+ return code;
+}
+
} // namespace version2
} // namespace tidl
void OnFiniGen(std::ofstream& stream) override;
private:
+ void GenIncludeInternalHeader(std::ofstream& stream);
void GenIncludeStubBodyHeader(std::ofstream& stream);
void GenLemAnonymousNamespace(std::ofstream& stream);
std::string GenLemContext();
std::string GenInterfaceServiceBaseSerialize(const Declaration& decl);
std::string GenInterfaceImplServiceBaseSetPrivilegeMap(
const Interface& iface);
+ std::string GenInterfaceExtensionBase(const Interface& iface);
private:
std::shared_ptr<Options> options_;
}
)__cpp_cb";
+constexpr const char CB_INTERNAL_HEADER_INCLUSION[] =
+R"__cpp_cb(
+#include <rpc-port-internal.h>
+)__cpp_cb";
+
+/**
+ * <CLS_NAME> The class name of the interface.
+ */
+constexpr const char CB_INTERFACE_EXTENSION_BASE[] =
+R"__cpp_cb(
+bool <CLS_NAME>::HasPendingRequest() const {
+ bool has_request = false;
+ rpc_port_stub_has_pending_request(stub_, &has_request);
+ return has_request;
+}
+
+)__cpp_cb";
+
} // namespace version2
} // namespace tidl
.Change("<CALLBACKS>", GenInterfaceCallbacks(iface))
.Change("<ENUMS>", GenEnumerations(iface.GetEnums()))
.Change("<SERVICE_BASE_METHODS>",
- GenInterfaceServiceBaseMethods(iface))
+ GenInterfaceServiceBaseMethods(iface))
.Change("<SERVICE_BASE_DISPATCH_FUNCS>",
- GenInterfaceServiceBaseDispatchFuncs(iface))
+ GenInterfaceServiceBaseDispatchFuncs(iface))
.Change("<SERVICE_BASE_IMPL_THREAD_MEMBER>",
- GenInterfaceServiceBaseImplThreadMember())
+ GenInterfaceServiceBaseImplThreadMember())
+ .Change("<EXTENSION_BASE>", GenInterfaceExtensionBase())
.Change("<METHOD_IDS>", GenMethodIds(iface))
.Change("<DELEGATE_IDS>", GenDelegateIds(iface)));
}
return "";
}
+std::string CppStubHeaderGenerator::GenInterfaceExtensionBase() {
+ if (options_->UseExtension()) return std::string(CB_INTERFACE_EXTENSION_BASE);
+
+ return "";
+}
+
} // namespace version2
} // namespace tidl
std::string GenInterfaceServiceBaseMethods(const Interface& iface);
std::string GenInterfaceServiceBaseDispatchFuncs(const Interface& iface);
std::string GenInterfaceServiceBaseImplThreadMember();
+ std::string GenInterfaceExtensionBase();
private:
std::shared_ptr<Options> options_;
const std::list<std::shared_ptr<ServiceBase>>& GetServices() const {
return services_;
}
-
+ <EXTENSION_BASE>
private:
<METHOD_IDS>
<DELEGATE_IDS>
};
)__cpp_cb";
+constexpr const char CB_INTERFACE_EXTENSION_BASE[] =
+R"__cpp_cb(
+ /// <summary>
+ /// Checks whether the pending request exists or not.
+ /// </summary>
+ /// <returns>True if the pending request exists, false otherwise</returns>
+ bool HasPendingRequest() const;
+)__cpp_cb";
+
} // namespace version2
} // namespace tidl
-t, --thread Generate thread code (Stub only).
-c, --cion Generate CION code.
-m, --mqtt Generate MQTT code.
+ -e, --extension Use extension version (for inhouse developers).
Application Options:
-p, --proxy Generate proxy code
auto options = std::shared_ptr<Options>(new Options());
int option_index = 0;
- struct option long_options[] = {
- {"proxy", no_argument, NULL, 'p'},
- {"stub", no_argument, NULL, 's'},
- {"group", no_argument, NULL, 'g'},
- {"version", no_argument, NULL, 'v'},
- {"help", no_argument, NULL, 'h'},
- {"language", required_argument, NULL, 'l'},
- {"input", required_argument, NULL, 'i'},
- {"output", required_argument, NULL, 'o'},
- {"namespace", no_argument, NULL, 'n'},
- {"rpclib", no_argument, NULL, 'r'},
- {"beta", no_argument, NULL, 'b'},
- {"thread", no_argument, NULL, 't'},
- {"cion", no_argument, NULL, 'c'},
- {"mqtt", no_argument, NULL, 'm'},
- {0, 0, 0, 0}
- };
+ struct option long_options[] = {{"proxy", no_argument, NULL, 'p'},
+ {"stub", no_argument, NULL, 's'},
+ {"group", no_argument, NULL, 'g'},
+ {"version", no_argument, NULL, 'v'},
+ {"help", no_argument, NULL, 'h'},
+ {"language", required_argument, NULL, 'l'},
+ {"input", required_argument, NULL, 'i'},
+ {"output", required_argument, NULL, 'o'},
+ {"namespace", no_argument, NULL, 'n'},
+ {"rpclib", no_argument, NULL, 'r'},
+ {"beta", no_argument, NULL, 'b'},
+ {"thread", no_argument, NULL, 't'},
+ {"cion", no_argument, NULL, 'c'},
+ {"mqtt", no_argument, NULL, 'm'},
+ {"extension", no_argument, NULL, 'e'},
+ {0, 0, 0, 0}};
while (true) {
- int c = getopt_long(argc, argv, "tcbpsgvhml:i:o:nr", long_options,
+ int c = getopt_long(argc, argv, "tcbpsgvhml:i:o:nre", long_options,
&option_index);
if (c == -1)
break;
options->isMqtt_ = true;
break;
+ case 'e':
+ options->useExtension_ = true;
+ break;
+
default:
cmd[CMD_HELP] = 1;
}
std::string GetOutput() const { return output_; }
bool HasNamespace() const { return hasNamespace_; }
bool HasRpcPortLib() const { return hasRpcPortLib_; }
+ bool UseExtension() const { return useExtension_; }
private:
enum Cmd {
OPT_OUTPUT,
OPT_NAMESPACE,
OPT_RPCLIB,
+ OPT_EXTENSION,
OPT_MAX
};
bool hasRpcPortLib_ = false;
bool isBetaEnabled_ = false;
bool isThreadEnabled_ = false;
+ bool useExtension_ = false;
Type type_;
};
void DefaultGenerator::GenCStubCode(std::shared_ptr<Options> options,
const Parser& ps) {
- CStubHeaderGenerator stub_header(ps.GetDoc());
+ CStubHeaderGenerator stub_header(ps.GetDoc(), options);
stub_header.EnableNamespace(options->HasNamespace());
stub_header.SetChannelType(
static_cast<Generator::ChannelType>(options->GetType()));