diff Plugins/Engine/OrthancPlugins.cpp @ 1280:d6a65dc6d0ac

Plugins can access the command-line arguments used to launch Orthanc
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 03 Feb 2015 10:25:56 +0100
parents 2ffe07abd9d8
children 7bccdd221e2b
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPlugins.cpp	Mon Feb 02 16:14:29 2015 +0100
+++ b/Plugins/Engine/OrthancPlugins.cpp	Tue Feb 03 10:25:56 2015 +0100
@@ -192,12 +192,16 @@
     boost::thread  changeThread_;
     bool done_;
     Properties properties_;
+    int argc_;
+    char** argv_;
 
     PImpl(ServerContext& context) : 
       context_(context), 
       restApi_(NULL),
       hasStorageArea_(false),
-      done_(false)
+      done_(false),
+      argc_(1),
+      argv_(NULL)
     {
       memset(&storageArea_, 0, sizeof(storageArea_));
     }
@@ -1058,6 +1062,31 @@
         return true;
       }
 
+      case _OrthancPluginService_GetCommandLineArgumentsCount:
+      {
+        const _OrthancPluginReturnSingleValue& p =
+          *reinterpret_cast<const _OrthancPluginReturnSingleValue*>(parameters);
+        *(p.resultUint32) = pimpl_->argc_ - 1;
+        return true;
+      }
+
+      case _OrthancPluginService_GetCommandLineArgument:
+      {
+        const _OrthancPluginGlobalProperty& p =
+          *reinterpret_cast<const _OrthancPluginGlobalProperty*>(parameters);
+        
+        if (p.property + 1 > pimpl_->argc_)
+        {
+          return false;
+        }
+        else
+        {
+          std::string arg = std::string(pimpl_->argv_[p.property + 1]);
+          *(p.result) = CopyString(arg);
+          return true;
+        }
+      }
+
       default:
         return false;
     }
@@ -1191,4 +1220,16 @@
       return it->second.c_str();
     }
   }
+
+
+  void OrthancPlugins::SetCommandLineArguments(int argc, char* argv[])
+  {
+    if (argc < 1 || argv == NULL)
+    {
+      throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+
+    pimpl_->argc_ = argc;
+    pimpl_->argv_ = argv;
+  }
 }