Add a new option for inhouse developers
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 11 Jun 2024 02:34:58 +0000 (11:34 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 18 Jun 2024 06:26:29 +0000 (15:26 +0900)
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>
27 files changed:
idlc/default_generator.cc
idlc/gen/c_gen_base.h
idlc/gen/c_stub_body_gen.cc
idlc/gen/c_stub_body_gen.h
idlc/gen/c_stub_body_gen_cb.h
idlc/gen/c_stub_header_gen.cc
idlc/gen/c_stub_header_gen.h
idlc/gen/c_stub_header_gen_cb.h
idlc/gen/cpp_stub_body_gen.cc
idlc/gen/cpp_stub_body_gen_cb.h
idlc/gen/cpp_stub_header_gen.cc
idlc/gen/cpp_stub_header_gen_cb.h
idlc/gen/version2/c_stub_body_generator.cc
idlc/gen/version2/c_stub_body_generator.hh
idlc/gen/version2/c_stub_body_generator_cb.hh
idlc/gen/version2/c_stub_header_generator.cc
idlc/gen/version2/c_stub_header_generator.hh
idlc/gen/version2/c_stub_header_generator_cb.hh
idlc/gen/version2/cpp_stub_body_generator.cc
idlc/gen/version2/cpp_stub_body_generator.hh
idlc/gen/version2/cpp_stub_body_generator_cb.hh
idlc/gen/version2/cpp_stub_header_generator.cc
idlc/gen/version2/cpp_stub_header_generator.hh
idlc/gen/version2/cpp_stub_header_generator_cb.hh
idlc/options.cc
idlc/options.h
idlc/version2_default_generator.cc

index 41db8a1..94c7fad 100644 (file)
@@ -96,7 +96,7 @@ void DefaultGenerator::Generate(std::shared_ptr<Options> options,
 
 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");
index 2920242..ab0d93c 100644 (file)
@@ -59,7 +59,8 @@ class CGeneratorBase : public Generator {
   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);
index d92af42..61195e9 100644 (file)
@@ -31,6 +31,7 @@ void CStubBodyGen::OnInitGen(std::ofstream& stream) {
   GenGNUSourceDefinition(stream);
   GenIncludeDefaultHeaders(stream);
   GenIncludeHeader(stream);
+  GenIncludeInternalHeader(stream);
   GenLogTag(stream, std::string("RPC_PORT_STUB"));
   GenLogDefinition(stream);
   GenVersionDefinition(stream);
@@ -48,6 +49,11 @@ void CStubBodyGen::OnInitGen(std::ofstream& 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())
@@ -271,6 +277,9 @@ void CStubBodyGen::GenInterface(std::ofstream& stream, const Interface& iface) {
     GenInterfaceCallbackPortCheck(stream, iface);
 
   GenInterfaceBase(stream, iface);
+
+  if (options_->UseExtension())
+    GenInterfaceExtensionBase(stream, iface);
 }
 
 // @see #CB_INTERFACE_CONTEXT_BASE
@@ -729,4 +738,12 @@ void CStubBodyGen::GenInterfaceBase(std::ofstream& stream,
   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
index b8358e8..f65e8c9 100644 (file)
@@ -35,6 +35,7 @@ class CStubBodyGen : public CBodyGeneratorBase {
   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);
@@ -52,6 +53,7 @@ class CStubBodyGen : public CBodyGeneratorBase {
   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);
@@ -64,6 +66,7 @@ class CStubBodyGen : public CBodyGeneratorBase {
   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);
index c1214fc..fe54947 100644 (file)
@@ -1206,4 +1206,28 @@ if (ret != RPC_PORT_ERROR_NONE) {
 }
 )__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_
index 3177368..45cf26c 100644 (file)
@@ -22,8 +22,9 @@ namespace {
 
 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);
@@ -156,6 +157,9 @@ void CStubHeaderGen::GenInterface(std::ofstream& stream,
   }
 
   GenInterfaceBase(stream, iface);
+
+  if (options_->UseExtension())
+    GenInterfaceExtensionBase(stream, iface);
 }
 
 // @see #CB_INTERFACE_CONTEXT_BASE
@@ -229,4 +233,12 @@ void CStubHeaderGen::GenInterfaceBase(std::ofstream& stream,
   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
index 15f7336..cfb77f1 100644 (file)
 #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;
@@ -50,11 +52,15 @@ class CStubHeaderGen : public CHeaderGeneratorBase {
   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
index ee6c9b9..99b9508 100644 (file)
@@ -365,4 +365,18 @@ R"__c_cb(
 <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_
index 68676e1..0b17100 100644 (file)
@@ -42,6 +42,9 @@ void CppStubBodyGen::OnInitGen(std::ofstream& stream) {
          << "#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);
@@ -83,7 +86,7 @@ void CppStubBodyGen::GenInterfaces(std::ofstream& stream) {
 }
 
 void CppStubBodyGen::GenInterface(std::ofstream& stream,
-                                    const Interface& iface) {
+                                  const Interface& iface) {
   GenServiceBase(stream, iface);
   GenBodyCallbacks(stream, iface, false);
   GenDefaultMethods(stream, iface);
@@ -130,6 +133,9 @@ void CppStubBodyGen::GenDefaultMethods(std::ofstream& stream,
     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,
index 185248d..a544ff0 100644 (file)
@@ -270,4 +270,21 @@ void $$::ServiceBase::Disconnect() {
 }
 )__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_
index 86cc340..72a19dc 100644 (file)
@@ -121,6 +121,9 @@ void CppStubHeaderGen::GenServiceBase(std::ofstream& stream,
 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
index 49158c2..a618246 100644 (file)
@@ -312,4 +312,9 @@ R"__cpp_cb(
 
 )__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_
index 4cb231c..3cedd41 100644 (file)
@@ -35,6 +35,7 @@ void CStubBodyGenerator::OnInitGen(std::ofstream& stream) {
   GenGNUSourceDefinition(stream);
   GenIncludeDefaultHeaders(stream);
   GenIncludePrivateHeaders(stream);
+  GenIncludeInternalHeaders(stream);
   GenIncludeLemHeaders(stream);
   GenIncludeHeader(stream);
   GenLogTag(stream, std::string("RPC_PORT_STUB"));
@@ -113,6 +114,10 @@ void CStubBodyGenerator::GenIncludePrivateHeaders(std::ofstream& stream) {
   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);
@@ -334,6 +339,7 @@ void CStubBodyGenerator::GenInterface(std::ofstream& stream,
     GenInterfaceCallbackPortCheck(stream, iface);
 
   GenInterfaceBase(stream, iface);
+  GenInterfaceExtensionBase(stream, iface);
 }
 
 // @see #CB_INTERFACE_CONTEXT_BASE
@@ -796,5 +802,17 @@ void CStubBodyGenerator::GenInterfaceBase(std::ofstream& stream,
       .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
index 645bcce..e340ba3 100644 (file)
@@ -37,6 +37,7 @@ class CStubBodyGenerator : public CBodyGeneratorBase {
 
  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);
@@ -72,6 +73,7 @@ class CStubBodyGenerator : public CBodyGeneratorBase {
   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);
index fafe518..748217f 100644 (file)
@@ -2320,6 +2320,31 @@ EXPORT_API int rpc_port_stub_<INPUT_FILE>_lem_<IFACE_NAME>_send(void *context, c
 }
 )__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
 
index da089dc..62c9889 100644 (file)
 #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);
@@ -156,6 +158,7 @@ void CStubHeaderGenerator::GenInterface(std::ofstream& stream,
   }
 
   GenInterfaceBase(stream, iface);
+  GenInterfaceExtensionBase(stream, iface);
 }
 
 // @see #CB_INTERFACE_CONTEXT_BASE
@@ -224,5 +227,17 @@ void CStubHeaderGenerator::GenInterfaceBase(std::ofstream& stream,
       .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
index 05b57c0..209a0e5 100644 (file)
 #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;
@@ -52,11 +54,15 @@ class CStubHeaderGenerator : public CHeaderGeneratorBase {
   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
index e98f2fc..003fbac 100644 (file)
@@ -368,6 +368,15 @@ R"__c_cb(
 <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
 
index 793d54d..5072c75 100644 (file)
@@ -34,6 +34,7 @@ void CppStubBodyGenerator::OnInitGen(std::ofstream& stream) {
   GenVersion(stream);
   GenIncludeStubBodyHeader(stream);
   GenIncludeDefaultHeaders(stream);
+  GenIncludeInternalHeader(stream);
   GenLogTag(stream, "RPC_PORT_STUB");
   GenLogDefinition(stream);
   GenVersionDefinition(stream);
@@ -58,6 +59,10 @@ void CppStubBodyGenerator::GenIncludeStubBodyHeader(std::ofstream& 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())
@@ -134,6 +139,7 @@ std::string CppStubBodyGenerator::GenInterfaces() {
 
     auto& iface = static_cast<Interface&>(*block);
     code += GenInterface(iface) + NLine(1);
+    code += GenInterfaceExtensionBase(iface) + NLine(1);
   }
 
   return code;
@@ -344,5 +350,15 @@ std::string CppStubBodyGenerator::GenInterfaceImplServiceBaseSetPrivilegeMap(
   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
index 90a7353..1e32865 100644 (file)
@@ -36,6 +36,7 @@ class CppStubBodyGenerator : public CppGeneratorBase {
   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();
@@ -58,6 +59,7 @@ class CppStubBodyGenerator : public CppGeneratorBase {
   std::string GenInterfaceServiceBaseSerialize(const Declaration& decl);
   std::string GenInterfaceImplServiceBaseSetPrivilegeMap(
       const Interface& iface);
+  std::string GenInterfaceExtensionBase(const Interface& iface);
 
  private:
   std::shared_ptr<Options> options_;
index ed24abe..55bf454 100644 (file)
@@ -754,6 +754,24 @@ EXPORT_API int rpc_port_stub_<INPUT_FILE>_lem_<CLS_NAME>_send(void* context, rpc
 }
 )__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
 
index 9453b42..20d7773 100644 (file)
@@ -82,11 +82,12 @@ std::string CppStubHeaderGenerator::GenInterface(const Interface& iface) {
           .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)));
 }
@@ -150,5 +151,11 @@ std::string CppStubHeaderGenerator::GenInterfaceServiceBaseImplThreadMember() {
   return "";
 }
 
+std::string CppStubHeaderGenerator::GenInterfaceExtensionBase() {
+  if (options_->UseExtension()) return std::string(CB_INTERFACE_EXTENSION_BASE);
+
+  return "";
+}
+
 }  // namespace version2
 }  // namespace tidl
index e124fc7..7c4277d 100644 (file)
@@ -45,6 +45,7 @@ class CppStubHeaderGenerator : public CppGeneratorBase {
   std::string GenInterfaceServiceBaseMethods(const Interface& iface);
   std::string GenInterfaceServiceBaseDispatchFuncs(const Interface& iface);
   std::string GenInterfaceServiceBaseImplThreadMember();
+  std::string GenInterfaceExtensionBase();
 
  private:
   std::shared_ptr<Options> options_;
index 562491a..7049129 100644 (file)
@@ -352,7 +352,7 @@ class <CLS_NAME> : public LocalExecution::IEvent {
   const std::list<std::shared_ptr<ServiceBase>>& GetServices() const {
     return services_;
   }
-
+  <EXTENSION_BASE>
  private:
   <METHOD_IDS>
   <DELEGATE_IDS>
@@ -442,6 +442,15 @@ class LocalExecution {
 };
 )__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
 
index 2d819a6..de4b5d9 100644 (file)
@@ -41,6 +41,7 @@ Additional Options:
   -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
@@ -84,26 +85,25 @@ std::shared_ptr<Options> Options::Parse(int argc, char** argv) {
   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;
@@ -170,6 +170,10 @@ std::shared_ptr<Options> Options::Parse(int argc, char** argv) {
         options->isMqtt_ = true;
         break;
 
+      case 'e':
+        options->useExtension_ = true;
+        break;
+
       default:
         cmd[CMD_HELP] = 1;
     }
index 1478f25..eb9329b 100644 (file)
@@ -54,6 +54,7 @@ class Options {
   std::string GetOutput() const { return output_; }
   bool HasNamespace() const { return hasNamespace_; }
   bool HasRpcPortLib() const { return hasRpcPortLib_; }
+  bool UseExtension() const { return useExtension_; }
 
  private:
   enum Cmd {
@@ -67,6 +68,7 @@ class Options {
     OPT_OUTPUT,
     OPT_NAMESPACE,
     OPT_RPCLIB,
+    OPT_EXTENSION,
     OPT_MAX
   };
 
@@ -85,6 +87,7 @@ class Options {
   bool hasRpcPortLib_ = false;
   bool isBetaEnabled_ = false;
   bool isThreadEnabled_ = false;
+  bool useExtension_ = false;
   Type type_;
 };
 
index 2c52c58..0db6d77 100644 (file)
@@ -88,7 +88,7 @@ void DefaultGenerator::Generate(std::shared_ptr<Options> options,
 
 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()));