Skip to content

Commit 7b2739b

Browse files
authored
Merge pull request #13 from nopesir/dev-server
Merge branch 'dev-server'
2 parents f380d0d + 625c4c2 commit 7b2739b

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

server/Session.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ std::string Session::process_reqs(const std::string& j_op, const json& j_data, i
579579
if(resp == dbService::OPENFILE_OK) {
580580
//Update session data
581581
shared_from_this()->set_curr_file(uri_JSON);
582-
shared_from_this()->set_symbols(SharedEditor::getInstance().get_file(uri_JSON, true));
582+
shared_from_this()->set_symbols(SharedEditor::getInstance().get_file(shared_from_this()->get_id(),uri_JSON, true));
583583
SharedEditor::getInstance().update_file(shared_from_this()->get_curr_file(),
584584
shared_from_this()->get_symbols());
585585

@@ -628,7 +628,7 @@ std::string Session::process_reqs(const std::string& j_op, const json& j_data, i
628628
if (resp == dbService::OPENWITHURI_OK) {
629629
//Update session data
630630
shared_from_this()->set_curr_file(uri_JSON);
631-
shared_from_this()->set_symbols(SharedEditor::getInstance().get_file(uri_JSON, true));
631+
shared_from_this()->set_symbols(SharedEditor::getInstance().get_file(shared_from_this()->get_id(),uri_JSON, true));
632632

633633
SharedEditor::getInstance().update_file(shared_from_this()->get_curr_file(),
634634
shared_from_this()->get_symbols());
@@ -730,7 +730,7 @@ std::string Session::process_reqs(const std::string& j_op, const json& j_data, i
730730

731731
//process received symbol and retrieve new calculated index
732732
int newIndex = process(index_ed_JSON,
733-
SharedEditor::getInstance().get_file(shared_from_this()->get_curr_file(),
733+
SharedEditor::getInstance().get_file(shared_from_this()->get_id(),shared_from_this()->get_curr_file(),
734734
false), symbol_JSON);
735735

736736
//Update room symbols for this file
@@ -753,7 +753,7 @@ std::string Session::process_reqs(const std::string& j_op, const json& j_data, i
753753
for(const std::pair<int,int>& id : symbolsId) {
754754
//process received symbol and retrieve new calculated index
755755
newIndex = get_index_by_id(
756-
SharedEditor::getInstance().get_file(shared_from_this()->get_curr_file(), false), id);
756+
SharedEditor::getInstance().get_file(shared_from_this()->get_id(),shared_from_this()->get_curr_file(), false), id);
757757
if(newIndex != -1) {
758758
//Update SE symbols for this file
759759
SharedEditor::getInstance().erase_from_file(shared_from_this()->get_curr_file(), newIndex);
@@ -783,7 +783,7 @@ std::string Session::process_reqs(const std::string& j_op, const json& j_data, i
783783
for(const std::pair<int, int>& id : symbols_id) {
784784
//process received symbol and retrieve new calculated index
785785
new_index = get_index_by_id(SharedEditor::getInstance().get_file(
786-
shared_from_this()->get_curr_file(), false), id);
786+
shared_from_this()->get_id(), shared_from_this()->get_curr_file(), false), id);
787787
if(new_index != -1) {
788788
//Update room symbols for this file
789789
SharedEditor::getInstance().format_in_file(shared_from_this()->get_curr_file(), new_index, format_JSON);
@@ -808,7 +808,7 @@ std::string Session::process_reqs(const std::string& j_op, const json& j_data, i
808808
for(const std::pair<int, int>& id : symbols_id) {
809809
//process received symbol and retrieve new calculated index
810810
new_index = get_index_by_id(
811-
SharedEditor::getInstance().get_file(shared_from_this()->get_curr_file(), false), id);
811+
SharedEditor::getInstance().get_file(shared_from_this()->get_id(),shared_from_this()->get_curr_file(), false), id);
812812
if(new_index != -1) {
813813
//Update room symbols for this file
814814
SharedEditor::getInstance().ch_font_sz_in_file(shared_from_this()->get_curr_file(), new_index,
@@ -834,7 +834,7 @@ std::string Session::process_reqs(const std::string& j_op, const json& j_data, i
834834
for(const std::pair<int, int>& id : symbols_id) {
835835
//process received symbol and retrieve new calculated index
836836
new_index = get_index_by_id(
837-
SharedEditor::getInstance().get_file(shared_from_this()->get_curr_file(), false), id);
837+
SharedEditor::getInstance().get_file(shared_from_this()->get_id(),shared_from_this()->get_curr_file(), false), id);
838838
if(new_index != -1) {
839839
//Update room symbols for this file
840840
SharedEditor::getInstance().ch_font_fam_in_file(shared_from_this()->get_curr_file(), new_index,
@@ -860,7 +860,7 @@ std::string Session::process_reqs(const std::string& j_op, const json& j_data, i
860860
for (const std::pair<int, int> &id : symbols_id) {
861861
//process received symbol and retrieve new calculated index
862862
new_index = get_index_by_id(
863-
SharedEditor::getInstance().get_file(shared_from_this()->get_curr_file(), false), id);
863+
SharedEditor::getInstance().get_file(shared_from_this()->get_id(),shared_from_this()->get_curr_file(), false), id);
864864
if (new_index != -1) {
865865
//Update room symbols for this file
866866
SharedEditor::getInstance().ch_alignment_in_file(shared_from_this()->get_curr_file(), new_index,
@@ -929,7 +929,7 @@ std::string Session::process_reqs(const std::string& j_op, const json& j_data, i
929929
for(const Symbol& s : symbols) {
930930
//process received symbol and retrieve new calculated index
931931
new_index = process(new_index, SharedEditor::getInstance().get_file(
932-
shared_from_this()->get_curr_file(), false), s);
932+
shared_from_this()->get_id(), shared_from_this()->get_curr_file(), false), s);
933933

934934
//Update room symbols for this file
935935
SharedEditor::getInstance().insert_in_file(shared_from_this()->get_curr_file(), new_index, s);

server/SharedEditor.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,19 @@ void SharedEditor::deliver_to_all(const Message &msg, const int& ed_id, const st
4646
}
4747
}
4848

49-
std::vector<Symbol> SharedEditor::get_file(const std::string& filename, bool get_from_disk) {
49+
std::vector<Symbol> SharedEditor::get_file(const int& ed_id,const std::string& filename, bool get_from_disk) {
5050
if(file_map.empty()) //server has nothing in RAM
5151
return std::vector<Symbol>();
5252
if(file_map.at(filename).empty()) {//server has not in RAM the vector symbols for this filename
53+
int count =0;
54+
for (const auto& p: clients) {
55+
if (p->get_id() != ed_id && p->get_curr_file() == filename) {
56+
count++;
57+
}
58+
if(count!=0)
59+
get_from_disk=false;
60+
}
61+
5362
return get_from_disk ? fileUtility::readFile(R"(../Filesystem/)" + filename + ".txt") : std::vector<Symbol>();
5463
}
5564
else //server has already in RAM this vector symbols

server/SharedEditor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class SharedEditor {
5252
void ch_font_sz_in_file(const std::string &file, int index, int font_sz);
5353
void ch_font_fam_in_file(const std::string &file, int index, const std::string& family);
5454
void ch_alignment_in_file(const std::string &key, int index, int alignment);
55-
std::vector<Symbol> get_file(const std::string& filename, bool get_from_disk);
55+
std::vector<Symbol> get_file(const int& ed_id,const std::string& filename, bool get_from_disk);
5656
};
5757

5858

0 commit comments

Comments
 (0)