[Libreoffice-commits] online.git: tools/Replay.hpp wsd/TraceFile.hpp

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Dec 19 08:12:55 UTC 2018


 tools/Replay.hpp  |   50 +++++++++++++++++++++---------------------
 wsd/TraceFile.hpp |   63 ++++++++++++++++++++++++++++++++++++------------------
 2 files changed, 67 insertions(+), 46 deletions(-)

New commits:
commit a65a528220b038069963f8f70b20953e44ee4c14
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Dec 19 09:12:28 2018 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Dec 19 09:12:36 2018 +0100

    TraceFileRecord: make members private
    
    Change-Id: Ie83077b248185d7748423f512b7b61b4945bd779

diff --git a/tools/Replay.hpp b/tools/Replay.hpp
index d9d95b6a3..8ea1be7f3 100644
--- a/tools/Replay.hpp
+++ b/tools/Replay.hpp
@@ -142,14 +142,14 @@ protected:
         for (;;)
         {
             const TraceFileRecord rec = traceFile.getNextRecord();
-            if (rec.Dir == TraceFileRecord::Direction::Invalid)
+            if (rec.getDir() == TraceFileRecord::Direction::Invalid)
             {
                 // End of trace file.
                 break;
             }
 
             const std::chrono::microseconds::rep deltaCurrent = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - epochCurrent).count();
-            const unsigned deltaFile = rec.TimestampNs - epochFile;
+            const unsigned deltaFile = rec.getTimestampNs() - epochFile;
             const unsigned delay = (_ignoreTiming ? 0 : deltaFile - deltaCurrent);
             if (delay > 0)
             {
@@ -163,61 +163,61 @@ protected:
 
             std::cout << rec.toString() << std::endl;
 
-            if (rec.Dir == TraceFileRecord::Direction::Event)
+            if (rec.getDir() == TraceFileRecord::Direction::Event)
             {
                 // Meta info about about an event.
                 static const std::string NewSession("NewSession: ");
                 static const std::string EndSession("EndSession: ");
 
-                if (rec.Payload.find(NewSession) == 0)
+                if (rec.getPayload().find(NewSession) == 0)
                 {
-                    const std::string uriOrig = rec.Payload.substr(NewSession.size());
+                    const std::string uriOrig = rec.getPayload().substr(NewSession.size());
                     std::string uri;
                     Poco::URI::decode(uriOrig, uri);
                     auto it = _sessions.find(uri);
                     if (it != _sessions.end())
                     {
                         // Add a new session.
-                        if (it->second.find(rec.SessionId) != it->second.end())
+                        if (it->second.find(rec.getSessionId()) != it->second.end())
                         {
-                            std::cout << "ERROR: session [" << rec.SessionId << "] already exists on doc [" << uri << "]\n";
+                            std::cout << "ERROR: session [" << rec.getSessionId() << "] already exists on doc [" << uri << "]\n";
                         }
                         else
                         {
-                            std::shared_ptr<Connection> connection = Connection::create(_serverUri, uri, rec.SessionId);
+                            std::shared_ptr<Connection> connection = Connection::create(_serverUri, uri, rec.getSessionId());
                             if (connection)
                             {
-                                it->second.emplace(rec.SessionId, connection);
+                                it->second.emplace(rec.getSessionId(), connection);
                             }
                         }
                     }
                     else
                     {
                         std::cout << "New Document: " << uri << "\n";
-                        _childToDoc.emplace(rec.Pid, uri);
-                        std::shared_ptr<Connection> connection = Connection::create(_serverUri, uri, rec.SessionId);
+                        _childToDoc.emplace(rec.getPid(), uri);
+                        std::shared_ptr<Connection> connection = Connection::create(_serverUri, uri, rec.getSessionId());
                         if (connection)
                         {
-                            _sessions[uri].emplace(rec.SessionId, connection);
+                            _sessions[uri].emplace(rec.getSessionId(), connection);
                         }
                     }
                 }
-                else if (rec.Payload.find(EndSession) == 0)
+                else if (rec.getPayload().find(EndSession) == 0)
                 {
-                    const std::string uriOrig = rec.Payload.substr(EndSession.size());
+                    const std::string uriOrig = rec.getPayload().substr(EndSession.size());
                     std::string uri;
                     Poco::URI::decode(uriOrig, uri);
                     auto it = _sessions.find(uri);
                     if (it != _sessions.end())
                     {
-                        std::cout << "EndSession [" << rec.SessionId << "]: " << uri << "\n";
+                        std::cout << "EndSession [" << rec.getSessionId() << "]: " << uri << "\n";
 
-                        it->second.erase(rec.SessionId);
+                        it->second.erase(rec.getSessionId());
                         if (it->second.empty())
                         {
                             std::cout << "End Doc [" << uri << "].\n";
                             _sessions.erase(it);
-                            _childToDoc.erase(rec.Pid);
+                            _childToDoc.erase(rec.getPid());
                         }
                     }
                     else
@@ -226,27 +226,27 @@ protected:
                     }
                 }
             }
-            else if (rec.Dir == TraceFileRecord::Direction::Incoming)
+            else if (rec.getDir() == TraceFileRecord::Direction::Incoming)
             {
-                auto docIt = _childToDoc.find(rec.Pid);
+                auto docIt = _childToDoc.find(rec.getPid());
                 if (docIt != _childToDoc.end())
                 {
                     const auto& uri = docIt->second;
                     auto it = _sessions.find(uri);
                     if (it != _sessions.end())
                     {
-                        const auto sessionIt = it->second.find(rec.SessionId);
+                        const auto sessionIt = it->second.find(rec.getSessionId());
                         if (sessionIt != it->second.end())
                         {
                             // Send the command.
-                            if (!sessionIt->second->send(rec.Payload))
+                            if (!sessionIt->second->send(rec.getPayload()))
                             {
                                 it->second.erase(sessionIt);
                             }
                         }
                         else
                         {
-                            std::cout << "ERROR: Session [" << rec.SessionId << "] does not exist.\n";
+                            std::cout << "ERROR: Session [" << rec.getSessionId() << "] does not exist.\n";
                         }
                     }
                     else
@@ -256,16 +256,16 @@ protected:
                 }
                 else
                 {
-                    std::cout << "ERROR: Unknown PID [" << rec.Pid << "] maps to no active document.\n";
+                    std::cout << "ERROR: Unknown PID [" << rec.getPid() << "] maps to no active document.\n";
                 }
             }
             else
             {
-                std::cout << "ERROR: Unknown trace file direction [" << static_cast<char>(rec.Dir) << "].\n";
+                std::cout << "ERROR: Unknown trace file direction [" << static_cast<char>(rec.getDir()) << "].\n";
             }
 
             epochCurrent = std::chrono::steady_clock::now();
-            epochFile = rec.TimestampNs;
+            epochFile = rec.getTimestampNs();
         }
     }
 
diff --git a/wsd/TraceFile.hpp b/wsd/TraceFile.hpp
index 958a73cf8..f6c27eff7 100644
--- a/wsd/TraceFile.hpp
+++ b/wsd/TraceFile.hpp
@@ -39,25 +39,46 @@ public:
     };
 
     TraceFileRecord() :
-        Dir(Direction::Invalid),
-        TimestampNs(0),
-        Pid(0)
+        _dir(Direction::Invalid),
+        _timestampNs(0),
+        _pid(0)
     {
     }
 
     std::string toString() const
     {
         std::ostringstream oss;
-        oss << static_cast<char>(Dir) << Pid << static_cast<char>(Dir)
-            << SessionId << static_cast<char>(Dir) << Payload;
+        oss << static_cast<char>(_dir) << _pid << static_cast<char>(_dir)
+            << _sessionId << static_cast<char>(_dir) << _payload;
         return oss.str();
     }
 
-    Direction Dir;
-    unsigned TimestampNs;
-    unsigned Pid;
-    std::string SessionId;
-    std::string Payload;
+    void setDir(Direction dir) { _dir = dir; }
+
+    Direction getDir() const { return _dir; }
+
+    void setTimestampNs(unsigned timestampNs) { _timestampNs = timestampNs; }
+
+    unsigned getTimestampNs() const { return _timestampNs; }
+
+    void setPid(unsigned pid) { _pid = pid; }
+
+    unsigned getPid() const { return _pid; }
+
+    void setSessionId(const std::string& sessionId) { _sessionId = sessionId; }
+
+    const std::string& getSessionId() const { return _sessionId; }
+
+    void setPayload(const std::string& payload) { _payload = payload; }
+
+    const std::string& getPayload() const { return _payload; }
+
+private:
+    Direction _dir;
+    unsigned _timestampNs;
+    unsigned _pid;
+    std::string _sessionId;
+    std::string _payload;
 };
 
 /// Trace-file generator class.
@@ -403,19 +424,19 @@ private:
         }
 
         if (_records.empty() ||
-            _records[0].Dir != TraceFileRecord::Direction::Event ||
-            _records[0].Payload.find("NewSession") != 0)
+            _records[0].getDir() != TraceFileRecord::Direction::Event ||
+            _records[0].getPayload().find("NewSession") != 0)
         {
             fprintf(stderr, "Invalid trace file with %ld records. First record: %s\n", _records.size(),
-                    _records.empty() ? "<empty>" : _records[0].Payload.c_str());
+                    _records.empty() ? "<empty>" : _records[0].getPayload().c_str());
             throw std::runtime_error("Invalid trace file.");
         }
 
         _indexIn = advance(-1, TraceFileRecord::Direction::Incoming);
         _indexOut = advance(-1, TraceFileRecord::Direction::Outgoing);
 
-        _epochStart = _records[0].TimestampNs;
-        _epochEnd = _records[_records.size() - 1].TimestampNs;
+        _epochStart = _records[0].getTimestampNs();
+        _epochEnd = _records[_records.size() - 1].getTimestampNs();
     }
 
     static bool extractRecord(const std::string& s, TraceFileRecord& rec)
@@ -424,7 +445,7 @@ private:
             return false;
 
         char delimiter = s[0];
-        rec.Dir = static_cast<TraceFileRecord::Direction>(delimiter);
+        rec.setDir(static_cast<TraceFileRecord::Direction>(delimiter));
 
         size_t pos = 1;
         int record = 0;
@@ -435,16 +456,16 @@ private:
             switch (record)
             {
                 case 0:
-                    rec.TimestampNs = std::atoi(s.substr(pos, next - pos).c_str());
+                    rec.setTimestampNs(std::atoi(s.substr(pos, next - pos).c_str()));
                     break;
                 case 1:
-                    rec.Pid = std::atoi(s.substr(pos, next - pos).c_str());
+                    rec.setPid(std::atoi(s.substr(pos, next - pos).c_str()));
                     break;
                 case 2:
-                    rec.SessionId = s.substr(pos, next - pos);
+                    rec.setSessionId(s.substr(pos, next - pos));
                     break;
                 case 3:
-                    rec.Payload = s.substr(pos);
+                    rec.setPayload(s.substr(pos));
                     return true;
             }
 
@@ -461,7 +482,7 @@ private:
     {
         while (++index < _records.size())
         {
-            if (_records[index].Dir == dir)
+            if (_records[index].getDir() == dir)
             {
                 break;
             }


More information about the Libreoffice-commits mailing list