loolwsd/LOOLBroker.cpp |   34 ++++++++++++++++------------------
 loolwsd/LOOLKit.cpp    |   45 +++++++++++++++++++++++----------------------
 2 files changed, 39 insertions(+), 40 deletions(-)

New commits:
commit 5780e311b713954ef1441fa61bd2fe792e9d1e09
Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk>
Date:   Sun Dec 27 17:58:52 2015 -0500

    loolwsd: childId type int -> string
    
    Change-Id: I2aad12da4bb8e7d87866d251258fb44e2aad9a2b
    Reviewed-on: https://gerrit.libreoffice.org/20980
    Reviewed-by: Ashod Nakashian <ashnak...@gmail.com>
    Tested-by: Ashod Nakashian <ashnak...@gmail.com>

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index a55aeaa..a4ee3ad 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -534,7 +534,8 @@ static bool globalPreinit(const std::string &loSubPath)
     return preInit(("/" + loSubPath + "/program").c_str(), "file:///user") == 
0;
 }
 
-static int createLibreOfficeKit(bool sharePages, std::string loSubPath, 
Poco::UInt64 childID)
+static int createLibreOfficeKit(const bool sharePages, const std::string& 
loSubPath,
+                                const std::string& childId)
 {
     Poco::UInt64 child;
     int nFIFOWriter = -1;
@@ -547,7 +548,7 @@ static int createLibreOfficeKit(bool sharePages, 
std::string loSubPath, Poco::UI
         if (!(pid = fork()))
         {
             // child
-            run_lok_main(loSubPath, childID, "");
+            run_lok_main(loSubPath, childId, childId);
             _exit(0);
         }
         else
@@ -569,7 +570,7 @@ static int createLibreOfficeKit(bool sharePages, 
std::string loSubPath, Poco::UI
 
         Process::Args args;
         args.push_back("--losubpath=" + loSubPath);
-        args.push_back("--child=" + std::to_string(childID));
+        args.push_back("--child=" + childId);
         args.push_back("--pipe=" + pipe);
         args.push_back("--clientport=" + ClientPortNumber);
 
@@ -591,18 +592,15 @@ static int createLibreOfficeKit(bool sharePages, 
std::string loSubPath, Poco::UI
     return child;
 }
 
-static int startupLibreOfficeKit(bool sharePages, int nLOKits,
-                                  std::string loSubPath, Poco::UInt64 child)
+static int startupLibreOfficeKit(const bool sharePages, const int nLOKits,
+                                 const std::string& loSubPath, const 
std::string& childId)
 {
     Process::PID pId = -1;
 
-    Log::info() << "Starting " << nLOKits << " LoKit instaces."
-                << " Shared: " << (sharePages ? "true" : "false")
-                << ", loSubPath: " << loSubPath
-                << ", child: " << child << Log::end;
+    Log::info() << "Starting " << nLOKits << " LoKit instaces." << Log::end;
     for (int nCntr = nLOKits; nCntr; nCntr--)
     {
-        if ( (pId = createLibreOfficeKit(sharePages, loSubPath, child)) < 0)
+        if ((pId = createLibreOfficeKit(sharePages, loSubPath, childId)) < 0)
         {
             Log::error("Error: failed to create LibreOfficeKit.");
             break;
@@ -630,7 +628,7 @@ int main(int argc, char** argv)
     std::string loSubPath;
     std::string sysTemplate;
     std::string loTemplate;
-    int _numPreSpawnedChildren = 0;
+    int numPreSpawnedChildren = 0;
 
     for (int i = 0; i < argc; ++i)
     {
@@ -664,7 +662,7 @@ int main(int argc, char** argv)
         {
             eq = strchrnul(cmd, '=');
             if (*eq)
-                _numPreSpawnedChildren = std::stoi(std::string(++eq));
+                numPreSpawnedChildren = std::stoi(std::string(++eq));
         }
         else if (strstr(cmd, "--clientport=") == cmd)
         {
@@ -698,7 +696,7 @@ int main(int argc, char** argv)
         exit(-1);
     }
 
-    if ( !_numPreSpawnedChildren )
+    if ( !numPreSpawnedChildren )
     {
         Log::error("Error: --numprespawns is 0");
         exit(-1);
@@ -728,9 +726,9 @@ int main(int argc, char** argv)
         Log::error(std::string("Exception: ") + exc.what());
     }
 
-    const Poco::UInt64 _childId = Util::rng::getNext();
+    const std::string childId = std::to_string(Util::rng::getNext());
 
-    Path jailPath = Path::forDirectory(childRoot + Path::separator() + 
std::to_string(_childId));
+    Path jailPath = Path::forDirectory(childRoot + Path::separator() + 
childId);
     File(jailPath).createDirectories();
 
     Path jailLOInstallation(jailPath, loSubPath);
@@ -806,9 +804,9 @@ int main(int argc, char** argv)
         exit(-1);
     }
 
-    bool sharePages = globalPreinit(loSubPath);
+    const bool sharePages = globalPreinit(loSubPath);
 
-    if ( startupLibreOfficeKit(sharePages, _numPreSpawnedChildren, loSubPath, 
_childId) < 0 )
+    if ( startupLibreOfficeKit(sharePages, numPreSpawnedChildren, loSubPath, 
childId) < 0 )
     {
         Log::error("Error: failed to create children.");
         exit(-1);
@@ -870,7 +868,7 @@ int main(int argc, char** argv)
             forkMutex.lock();
             forkCounter -= 1;
 
-            if (createLibreOfficeKit(sharePages, loSubPath, _childId) < 0 )
+            if (createLibreOfficeKit(sharePages, loSubPath, childId) < 0)
                 Log::error("Error: fork falied.");
 
             forkMutex.unlock();
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 332879a..b61f0f9 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -339,13 +339,14 @@ private:
 class Connection: public Runnable
 {
 public:
-    Connection(LibreOfficeKit *loKit, LibreOfficeKitDocument *loKitDocument, 
Poco::UInt64 childId, const std::string& threadId) :
+    Connection(LibreOfficeKit *loKit, LibreOfficeKitDocument *loKitDocument,
+               const std::string& childId, const std::string& threadId) :
         _loKit(loKit),
         _loKitDocument(loKitDocument),
         _childId(childId),
         _threadId(threadId)
     {
-        Log::info("New connection in child: " + std::to_string(_childId) + ", 
thread: " + _threadId);
+        Log::info("New connection in child: " + childId + ", thread: " + 
_threadId);
     }
 
     void start()
@@ -383,11 +384,11 @@ public:
             HTTPResponse response;
             auto ws = std::make_shared<WebSocket>(cs, request, response);
 
-            _session.reset(new ChildProcessSession(ws, _loKit, _loKitDocument, 
std::to_string(_childId)));
+            _session.reset(new ChildProcessSession(ws, _loKit, _loKitDocument, 
_childId));
             ws->setReceiveTimeout(0);
 
             // child Jail TID PID
-            std::string hello("child " + std::to_string(_childId) + " " +
+            std::string hello("child " + _childId + " " +
                               _threadId + " " + std::to_string(Process::id()));
             _session->sendTextFrame(hello);
 
@@ -437,20 +438,20 @@ public:
 
     ~Connection()
     {
-        Log::info("Closing connection in child: " + std::to_string(_childId) + 
", thread: " + _threadId);
+        Log::info("Closing connection in child: " + _childId + ", thread: " + 
_threadId);
         //_thread.stop();
     }
 
 private:
     LibreOfficeKit *_loKit;
     LibreOfficeKitDocument *_loKitDocument;
-    Poco::UInt64 _childId;
+    const std::string _childId;
     std::string _threadId;
     Thread _thread;
     std::shared_ptr<ChildProcessSession> _session;
 };
 
-void run_lok_main(const std::string &loSubPath, Poco::UInt64 _childId, const 
std::string& pipe)
+void run_lok_main(const std::string &loSubPath, const std::string& childId, 
const std::string& pipe)
 {
     if (std::getenv("SLEEPFORDEBUGGER"))
     {
@@ -469,8 +470,8 @@ void run_lok_main(const std::string &loSubPath, 
Poco::UInt64 _childId, const std
     std::string aURL;
     std::map<std::string, std::shared_ptr<Connection>> _connections;
 
-    assert (_childId != 0);
-    assert (!loSubPath.empty());
+    assert(!childId.empty());
+    assert(!loSubPath.empty());
 
     static const std::string thread_name = "libreofficekit";
 #ifdef __linux
@@ -514,7 +515,7 @@ void run_lok_main(const std::string &loSubPath, 
Poco::UInt64 _childId, const std
         CallBackWorker callbackWorker(ChildProcessSession::_callbackQueue);
         Poco::ThreadPool::defaultPool().start(callbackWorker);
 
-        Log::info("Child [" + std::to_string(_childId) + "] is ready.");
+        Log::info("Child [" + childId + "] is ready.");
 
         std::string aResponse;
         std::string aMessage;
@@ -602,14 +603,14 @@ void run_lok_main(const std::string &loSubPath, 
Poco::UInt64 _childId, const std
                             std::shared_ptr<Connection> thread;
                             if ( _connections.empty() )
                             {
-                                Log::info("Creating main thread for child: " + 
std::to_string(_childId) + ", thread: " + threadId);
-                                thread = 
std::make_shared<Connection>(loKit.get(), nullptr, _childId, threadId);
+                                Log::info("Creating main thread for child: " + 
childId + ", thread: " + threadId);
+                                thread = 
std::make_shared<Connection>(loKit.get(), nullptr, childId, threadId);
                             }
                             else
                             {
-                                Log::info("Creating view thread for child: " + 
std::to_string(_childId) + ", thread: " + threadId);
+                                Log::info("Creating view thread for child: " + 
childId + ", thread: " + threadId);
                                 auto aConnection = _connections.begin();
-                                thread = 
std::make_shared<Connection>(loKit.get(), 
aConnection->second->getLOKitDocument(), _childId, threadId);
+                                thread = 
std::make_shared<Connection>(loKit.get(), 
aConnection->second->getLOKitDocument(), childId, threadId);
                             }
 
                             auto aInserted = _connections.emplace(threadId, 
thread);
@@ -617,7 +618,7 @@ void run_lok_main(const std::string &loSubPath, 
Poco::UInt64 _childId, const std
                             if ( aInserted.second )
                                 thread->start();
                             else
-                                Log::error("Connection already exists for 
child: " + std::to_string(_childId) + ", thread: " + threadId);
+                                Log::error("Connection already exists for 
child: " + childId + ", thread: " + threadId);
 
                             Log::debug("Connections: " + 
std::to_string(_connections.size()));
                         }
@@ -674,8 +675,8 @@ void run_lok_main(const std::string &loSubPath, 
Poco::UInt64 _childId, const std
 int main(int argc, char** argv)
 {
     std::string loSubPath;
-    Poco::UInt64 _childId = 0;
-    std::string _pipe;
+    std::string childId;
+    std::string pipe;
 
     Log::initialize("kit");
 
@@ -693,13 +694,13 @@ int main(int argc, char** argv)
         {
             eq = strchrnul(cmd, '=');
             if (*eq)
-                _childId = std::stoll(std::string(++eq));
+                childId = std::string(++eq);
         }
         else if (strstr(cmd, "--pipe=") == cmd)
         {
             eq = strchrnul(cmd, '=');
             if (*eq)
-                _pipe = std::string(++eq);
+                pipe = std::string(++eq);
         }
         else if (strstr(cmd, "--clientport=") == cmd)
         {
@@ -715,13 +716,13 @@ int main(int argc, char** argv)
         exit(1);
     }
 
-    if ( !_childId )
+    if ( childId.empty() )
     {
         Log::error("Error: --child is 0");
         exit(1);
     }
 
-    if ( _pipe.empty() )
+    if ( pipe.empty() )
     {
         Log::error("Error: --pipe is empty");
         exit(1);
@@ -745,7 +746,7 @@ int main(int argc, char** argv)
         Log::error(std::string("Exception: ") + exc.what());
     }
 
-    run_lok_main(loSubPath, _childId, _pipe);
+    run_lok_main(loSubPath, childId, pipe);
 
     Log::info("loolkit finished OK!");
     return 0;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to