diff options
| author | Roland Reichwein <mail@reichwein.it> | 2023-01-28 21:24:11 +0100 | 
|---|---|---|
| committer | Roland Reichwein <mail@reichwein.it> | 2023-01-28 21:24:11 +0100 | 
| commit | 4eedb599d8de5559daa4678c7520bb36968e767e (patch) | |
| tree | 43830f8cf5c880d8be76b8f98bb2f73d78e38c78 /whiteboard.cpp | |
| parent | a69b1d0c580bc779740ef79a7d16b69229896785 (diff) | |
Server to client: diffs
Diffstat (limited to 'whiteboard.cpp')
| -rw-r--r-- | whiteboard.cpp | 32 | 
1 files changed, 19 insertions, 13 deletions
| diff --git a/whiteboard.cpp b/whiteboard.cpp index 059571d..35ae30b 100644 --- a/whiteboard.cpp +++ b/whiteboard.cpp @@ -83,33 +83,39 @@ void Whiteboard::storage_cleanup()   }  } -std::string make_xml(const std::initializer_list<std::pair<std::string, std::string>>& key_values) +pt::ptree make_ptree(const std::initializer_list<std::pair<std::string, std::string>>& key_values)  { - pt::ptree xml; + pt::ptree ptree;   for (const auto& i: key_values) { -  xml.put(fmt::format("serverinfo.{}", i.first), i.second); +  ptree.put(fmt::format("serverinfo.{}", i.first), i.second);   } - return Reichwein::XML::plain_xml(xml); + return ptree; +} + +std::string make_xml(const std::initializer_list<std::pair<std::string, std::string>>& key_values) +{ + pt::ptree ptree{make_ptree(key_values)}; + return Reichwein::XML::plain_xml(ptree);  } -void Whiteboard::notify_other_connections_file(Whiteboard::connection& c, const std::string& id) +void Whiteboard::notify_other_connections_diff(Whiteboard::connection& c, const std::string& id, const Diff& diff)  {   std::for_each(m_registry.begin(id), m_registry.end(id), [&](const Whiteboard::connection& ci)                 {                  if (c != ci) {                   boost::beast::flat_buffer buffer; -                 boost::beast::ostream(buffer) << make_xml({ -                   {"type", "getfile"}, -                   {"data", m_storage->getDocument(id)}, -                   {"revision", std::to_string(m_storage->getRevision(id)) }, -                   {"pos", std::to_string(m_storage->getCursorPos(id)) } -                   }); +                 pt::ptree ptree {make_ptree({ +                   {"type", "getdiff"}, +                   {"revision", std::to_string(m_storage->getRevision(id)) } +                   })}; +                 ptree.put_child("serverinfo.diff", diff.get_structure().get_child("diff")); +                 boost::beast::ostream(buffer) << Reichwein::XML::plain_xml(ptree);                   std::lock_guard<std::mutex> lock(m_websocket_mutex);                   try {                    ci->write(buffer.data());                   } catch (const std::exception& ex) { -                  std::cerr << "Warning: Notify getfile write for " << ci << " not possible, id " << id << std::endl; +                  std::cerr << "Warning: Notify getdiff write for " << ci << " not possible, id " << id << std::endl;                    m_registry.dump();                   }                  } @@ -165,7 +171,7 @@ std::string Whiteboard::handle_request(Whiteboard::connection& c, const std::str     m_storage->setDocument(id, data);     m_registry.setId(c, id); -   notify_other_connections_file(c, id); +   notify_other_connections_diff(c, id, d);     int pos {xml.get<int>("request.pos")};     if (m_storage->getCursorPos(id) != pos) { | 
