[openrtm-commit:03351] r3424 - in trunk/OpenRTM-aist/src/lib: coil/posix/coil coil/vxworks/coil coil/win32/coil rtm

openrtm @ openrtm.org openrtm @ openrtm.org
2018年 11月 1日 (木) 17:59:24 JST


Author: miyamoto
Date: 2018-11-01 17:59:24 +0900 (Thu, 01 Nov 2018)
New Revision: 3424

Modified:
   trunk/OpenRTM-aist/src/lib/coil/posix/coil/Process.cpp
   trunk/OpenRTM-aist/src/lib/coil/posix/coil/Process.h
   trunk/OpenRTM-aist/src/lib/coil/vxworks/coil/Process.cpp
   trunk/OpenRTM-aist/src/lib/coil/vxworks/coil/Process.h
   trunk/OpenRTM-aist/src/lib/coil/win32/coil/Process.cpp
   trunk/OpenRTM-aist/src/lib/coil/win32/coil/Process.h
   trunk/OpenRTM-aist/src/lib/rtm/ModuleManager.cpp
Log:
[incompat] 

Modified: trunk/OpenRTM-aist/src/lib/coil/posix/coil/Process.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/posix/coil/Process.cpp	2018-11-01 08:39:08 UTC (rev 3423)
+++ trunk/OpenRTM-aist/src/lib/coil/posix/coil/Process.cpp	2018-11-01 08:59:24 UTC (rev 3424)
@@ -20,6 +20,7 @@
 #ifndef COIL_PROCESS_H
 #define COIL_PROCESS_H
 
+#include <coil/File.h>
 #include <coil/stringutil.h>
 
 #include <stdlib.h>
@@ -30,6 +31,7 @@
 #include <sys/stat.h>
 #include <string>
 
+
 namespace coil
 {
 
@@ -81,6 +83,27 @@
     return daemon(nochdir, noclose);
   }
 
+  int create_process(std::string command, std::vector<std::string> &out)
+  {
+    FILE* fd;
+    out.clear();
+    if ((fd = popen(command.c_str(), "r")) == NULL)
+      {
+        //std::cerr << "popen faild" << std::endl;
+        return -1;
+      }
+    do
+      {
+        char str[512];
+        fgets(str, 512, fd);
+        std::string line(str);
+        if (0 < line.size())
+          line.erase(line.size() - 1);
+        out.push_back(line);
+      } while (!feof(fd));
 
+    return 0;
+  }
+
 };  // namespace coil
 #endif  // COIL_PROCESS_H

Modified: trunk/OpenRTM-aist/src/lib/coil/posix/coil/Process.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/posix/coil/Process.h	2018-11-01 08:39:08 UTC (rev 3423)
+++ trunk/OpenRTM-aist/src/lib/coil/posix/coil/Process.h	2018-11-01 08:59:24 UTC (rev 3424)
@@ -60,5 +60,27 @@
 
   int daemon(int nochdir, int noclose);
 
+  /*!
+  * @if jp
+  * @brief ¥×¥í¥»¥¹¤òµ¯Æ°¤·¤Æ½ÐÎϤò¼èÆÀ¤¹¤ë
+  *
+  *
+  *
+  * @param cmd µ¯Æ°¤¹¤ë¼Â¹Ô¥Õ¥¡¥¤¥ë¤Î¥Õ¥ë¥Ñ¥¹
+  * @param out ½ÐÎÏ·ë²Ì
+  * @return 0: À®¸ù, -1: ¼ºÇÔ
+  *
+  * @else
+  * @brief Launching a process
+  *
+  *
+  * @param command full path string to a command to be executed.
+  * @param out
+  * @return 0: successful, -1: failed
+  *
+  * @endif
+  */
+  int create_process(std::string command, std::vector<std::string> &out);
+
 };  // namespace coil
 #endif  // COIL_PROCESS_H

Modified: trunk/OpenRTM-aist/src/lib/coil/vxworks/coil/Process.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/vxworks/coil/Process.cpp	2018-11-01 08:39:08 UTC (rev 3423)
+++ trunk/OpenRTM-aist/src/lib/coil/vxworks/coil/Process.cpp	2018-11-01 08:59:24 UTC (rev 3424)
@@ -48,6 +48,11 @@
     return -1;
   }
 
+  int create_process(std::string command, std::vector<std::string> &out)
+  {
+    return -1;
+  }
 
+
 }; // namespace coil
 #endif // COIL_PROCESS_H

Modified: trunk/OpenRTM-aist/src/lib/coil/vxworks/coil/Process.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/vxworks/coil/Process.h	2018-11-01 08:39:08 UTC (rev 3423)
+++ trunk/OpenRTM-aist/src/lib/coil/vxworks/coil/Process.h	2018-11-01 08:59:24 UTC (rev 3424)
@@ -57,5 +57,7 @@
 
   int daemon(int nochdir, int noclose);
 
+  int create_process(std::string command, std::vector<std::string> &out);
+
 }; // namespace coil
 #endif // COIL_PROCESS_H

Modified: trunk/OpenRTM-aist/src/lib/coil/win32/coil/Process.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/win32/coil/Process.cpp	2018-11-01 08:39:08 UTC (rev 3423)
+++ trunk/OpenRTM-aist/src/lib/coil/win32/coil/Process.cpp	2018-11-01 08:59:24 UTC (rev 3424)
@@ -68,5 +68,81 @@
     // not implemented
     return 0;
   }
+
+
+  /*!
+  * @if jp
+  * @brief プロセスを起動して出力を取得する
+  *
+  * @else
+  *
+  * @endif
+  */
+  int create_process(std::string command, std::vector<std::string> &out)
+  {
+      HANDLE rPipe, wPipe;
+      SECURITY_ATTRIBUTES sa;
+      sa.nLength = sizeof(sa);
+      sa.bInheritHandle = TRUE;
+      sa.lpSecurityDescriptor = NULL;
+      if (!CreatePipe(&rPipe, &wPipe, &sa, 0))
+      {
+          return -1;
+      }
+
+
+      STARTUPINFO si = { 0 };
+      si.cb = sizeof(si);
+      si.dwFlags = STARTF_USESTDHANDLES;
+      si.hStdInput = stdin;
+      si.hStdOutput = wPipe;
+      si.hStdError = wPipe;
+
+
+#ifdef UNICODE
+      // std::string -> LPTSTR
+      std::wstring wcommand = string2wstring(command);
+      LPTSTR lpcommand = new TCHAR[wcommand.size() + 1];
+      _tcscpy(lpcommand, wcommand.c_str());
+#else
+      // std::string -> LPTSTR
+      LPTSTR lpcommand = new TCHAR[command.size() + 1];
+      _tcscpy(lpcommand, command.c_str());
+#endif // UNICODE
+
+      PROCESS_INFORMATION pi = { 0 };
+      if (!CreateProcess(NULL, lpcommand, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
+      {
+          delete lpcommand;
+          return -1;
+      }
+
+
+      WaitForSingleObject(pi.hProcess, INFINITE);
+      CloseHandle(pi.hProcess);
+      CloseHandle(pi.hThread);
+
+
+      char Buf[1025] = { 0 };
+      DWORD len;
+      ReadFile(rPipe, Buf, sizeof(Buf) - 1, &len, NULL);
+
+
+      out = coil::split(std::string(Buf), "\n");
+
+      for (coil::vstring::iterator itr = out.begin(); itr != out.end(); ++itr)
+      {
+          std::string &tmp = (*itr);
+          if (0 < tmp.size())
+          {
+              tmp.erase(tmp.size() - 1);
+          }
+          coil::eraseBothEndsBlank(tmp);
+      }
+
+      delete lpcommand;
+      return 0;
+
+  }
 };  // namespace coil
 

Modified: trunk/OpenRTM-aist/src/lib/coil/win32/coil/Process.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/coil/win32/coil/Process.h	2018-11-01 08:39:08 UTC (rev 3423)
+++ trunk/OpenRTM-aist/src/lib/coil/win32/coil/Process.h	2018-11-01 08:59:24 UTC (rev 3424)
@@ -90,6 +90,29 @@
       return line;
     }
   };
+
+  /*!
+  * @if jp
+  * @brief プロセスを起動して出力を取得する
+  *
+  *
+  *
+  * @param cmd 起動する実行ファイルのフルパス
+  * @param out 出力結果
+  * @return 0: 成功, -1: 失敗
+  *
+  * @else
+  * @brief Launching a process
+  *
+  *
+  * @param command full path string to a command to be executed.
+  * @param out
+  * @return 0: successful, -1: failed
+  *
+  * @endif
+  */
+  int create_process(std::string command, std::vector<std::string> &out);
+
 };  // namespace coil
 
 inline FILE* popen(const char* cmd, const char* mode)

Modified: trunk/OpenRTM-aist/src/lib/rtm/ModuleManager.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/ModuleManager.cpp	2018-11-01 08:39:08 UTC (rev 3423)
+++ trunk/OpenRTM-aist/src/lib/rtm/ModuleManager.cpp	2018-11-01 08:59:24 UTC (rev 3424)
@@ -567,33 +567,35 @@
 
     for (size_t i(0), len(modules.size()); i < len; ++i)
       {
+          
         std::string cmd(lprop["profile_cmd"]);
         cmd += " \"" + modules[i] + "\"";
-        FILE* fd;
-        if ((fd = popen(cmd.c_str(), "r")) == NULL)
-          {
-            std::cerr << "popen faild" << std::endl;
-			m_loadfailmods.push_back(modules[i]);
+
+        coil::vstring out;
+        if (coil::create_process(cmd, out) == -1)
+        {
+            std::cerr << "create_process faild" << std::endl;
             continue;
-          }
+        }
         coil::Properties p;
-        do
-          {
-            char str[512];
-            fgets(str, 512, fd);
-            std::string line(str);
-            if (0 < line.size())
-              line.erase(line.size() - 1);
-            std::string::size_type pos(line.find(":"));
+        
+        for (coil::vstring::iterator itr = out.begin(); itr != out.end(); ++itr)
+        {
+            std::string tmp = (*itr);
+            std::string::size_type pos(tmp.find(":"));
             if (pos != std::string::npos)
-              {
-                std::string key(line.substr(0, pos));
+            {
+                std::string key(tmp.substr(0, pos));
                 coil::eraseBothEndsBlank(key);
-                p[key] = line.substr(pos + 1);
+                p[key] = tmp.substr(pos + 1);
                 coil::eraseBothEndsBlank(p[key]);
-              }
-          } while (!feof(fd));
-        pclose(fd);
+            }
+            
+        }
+
+        
+        
+
         RTC_DEBUG(("rtcprof cmd sub process done."));
         if (p["implementation_id"].empty()) { 
 			m_loadfailmods.push_back(modules[i]);
@@ -602,6 +604,7 @@
         p["module_file_name"] = coil::basename(modules[i].c_str());
         p["module_file_path"] = modules[i].c_str();
         modprops.push_back(p);
+        
       }
 #endif
   }



openrtm-commit メーリングリストの案内