comparison OrthancServer/ServerIndex.cpp @ 1240:62c35e4b67db

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 05 Dec 2014 17:12:35 +0100
parents 92c6b3b57699
children 90d2f320862d
comparison
equal deleted inserted replaced
1239:92c6b3b57699 1240:62c35e4b67db
1025 boost::mutex::scoped_lock lock(mutex_); 1025 boost::mutex::scoped_lock lock(mutex_);
1026 db_->GetAllPublicIds(target, resourceType); 1026 db_->GetAllPublicIds(target, resourceType);
1027 } 1027 }
1028 1028
1029 1029
1030 static void FormatChanges(Json::Value& target,
1031 const std::list<ServerIndexChange>& changes,
1032 bool done,
1033 int64_t since)
1034 {
1035 Json::Value items = Json::arrayValue;
1036 for (std::list<ServerIndexChange>::const_iterator
1037 it = changes.begin(); it != changes.end(); it++)
1038 {
1039 Json::Value item;
1040 it->Format(item);
1041 items.append(item);
1042 }
1043
1044 target = Json::objectValue;
1045 target["Changes"] = items;
1046 target["Done"] = done;
1047
1048 int64_t last = (changes.size() == 0 ? since : changes.back().GetSeq());
1049 target["Last"] = static_cast<int>(last);
1050 }
1051
1052
1030 bool ServerIndex::GetChanges(Json::Value& target, 1053 bool ServerIndex::GetChanges(Json::Value& target,
1031 int64_t since, 1054 int64_t since,
1032 unsigned int maxResults) 1055 unsigned int maxResults)
1033 { 1056 {
1034 boost::mutex::scoped_lock lock(mutex_); 1057 std::list<ServerIndexChange> changes;
1035 db_->GetChanges(target, since, maxResults); 1058 bool done;
1059
1060 {
1061 boost::mutex::scoped_lock lock(mutex_);
1062 db_->GetChanges(changes, done, since, maxResults);
1063 }
1064
1065 FormatChanges(target, changes, done, since);
1036 return true; 1066 return true;
1037 } 1067 }
1038 1068
1069
1039 bool ServerIndex::GetLastChange(Json::Value& target) 1070 bool ServerIndex::GetLastChange(Json::Value& target)
1040 { 1071 {
1041 boost::mutex::scoped_lock lock(mutex_); 1072 std::list<ServerIndexChange> changes;
1042 db_->GetLastChange(target); 1073
1074 {
1075 boost::mutex::scoped_lock lock(mutex_);
1076 db_->GetLastChange(changes);
1077 }
1078
1079 FormatChanges(target, changes, true, 0);
1043 return true; 1080 return true;
1044 } 1081 }
1082
1045 1083
1046 void ServerIndex::LogExportedResource(const std::string& publicId, 1084 void ServerIndex::LogExportedResource(const std::string& publicId,
1047 const std::string& remoteModality) 1085 const std::string& remoteModality)
1048 { 1086 {
1049 boost::mutex::scoped_lock lock(mutex_); 1087 boost::mutex::scoped_lock lock(mutex_);