Add a new option for inhouse developers 09/312509/3
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 11 Jun 2024 02:34:58 +0000 (11:34 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 11 Jun 2024 10:13:49 +0000 (19:13 +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 41db8a1b3db5d816ee6b00a07c9a32527935c914..94c7fadd721d77bd816f88934757a584e776cd97 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 29202429f02fa3fa6d9362758c4501cb172c6dc8..ab0d93c5f71860b04582a1983aa14d923f999973 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 d92af42f454614f01828f9efbf0ca1afd37ddfce..61195e944a10148ca2a9a526b345d812ca30e002 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 b8358e8154758c38d285a8f0fae7c95194e20b26..f65e8c93971692d88e796b6e93f5ae4ec198700b 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 c1214fcc9ded425f7847e6c373a2675a09d584b8..fe54947c3bb4905485db34dd7fc058e2fba416da 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 31773681eff830aef964e472cc948be9dde1087a..45cf26caf5c7cf9a8b5173256298c9588e3858fd 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 15f7336a9521b94e107f4d367921be67e9a39675..cfb77f1f777a6a1914628bb8a669115b1bed901a 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 ee6c9b91b00fcea003571f7220f4299087f32c06..99b9508ed60bcbb8b9c0aa83e38b5eb4ac1f4c17 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 68676e16d7d70f9fba09cbc470ba83b4f7f77333..0b171001b29e1035d7ddc02b51b6189e55e82c8a 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 185248d94d1a87fc318de0fe24cc6728a7e10070..a544ff0a2c58275167414bead4dd9382f59c0f0e 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 86cc3409dcaa1d3e7ad7e7eea6e09c6e8c865f06..72a19dca2bd71702243ba6125272b3abd11ddf97 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 49158c2896191790c60a54c6401172a0437f2f59..a6182466e33844dc08ef14c452e3cd7fc48c99a2 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 4cb231c32e3fba75ef1e5b94ced54e0ac3a496ef..3cedd41de81abe3f16b4dbac5ca98b969465a8e1 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 645bcce09e32523f46d0462271ee951528a0ded0..e340ba3d3bc5c5dc3bf850a08ca20072c82d1779 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 fafe5180de7c5701918dd3f9768f8266a8ba0881..748217f1acdc6eead11be542e077a6561df575b4 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 da089dc6017d89a302684f07ad1b9ebcf09986e1..62c9889a4c179d3bf7b36f3bf8f607eb2483a335 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 05b57c04f5de36021ab9b670e964d6a667785c20..209a0e56909cddaaade17d9a99f99dabd5dec42c 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 e98f2fcf813d8777cba5dbb2c055620fec293fcc..003fbac9aff2f4e85c08361aa455063e04b6bbd2 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 793d54deaf0bccdbe02121ffd943d14fffdbe559..5072c75887e900c183382bb58d43d39a2ebf02dc 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 90a7353cfc26c3346079e75766c1c30c4275a1fe..1e32865a418339e8de00db114ea3f4846dbdb25c 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 ed24abe03fe8ba1fd53ea7dc336d0d613dafd9bb..55bf4543a410548ee90db1d3ebe86bf91e8a00b1 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 9453b42d9f7f54b59e58a19244d200145f228fdf..20d7773b78b9de3fd5015e6fb69877388516d7d8 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 e124fc70ba8e307206fa765d583c7c52b60353f0..7c4277d91e4e8e17630195b7afd4e44169000b51 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 562491a8e9c4d1126b0dd9ad0f4b16e0bd178e01..7049129de179ba9ec80e54173beef2c1bb047d6c 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 2d819a6cc5758375850d40d46c03da2d09b01364..de4b5d9e7f55f285f1919c345c4154fd6707ba1f 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 1478f2520d4f916c6f89390b09cebb5a5971ced3..eb9329bb83c43f71a35d6dd7074c71253099b5bc 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 2c52c5864fff641de5de9d6a7e988096d58bcde0..0db6d775ecdb744713ec85d969ca8f65dba80aee 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()));