Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 1244:a0e420c5f2b8
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 08 Dec 2014 12:31:35 +0100 |
parents | 90d2f320862d |
children | 54bf0f0245f4 |
comparison
equal
deleted
inserted
replaced
1243:3a3e7e3e244f | 1244:a0e420c5f2b8 |
---|---|
1036 target.append(*it); | 1036 target.append(*it); |
1037 } | 1037 } |
1038 } | 1038 } |
1039 | 1039 |
1040 | 1040 |
1041 static void FormatChanges(Json::Value& target, | 1041 template <typename T> |
1042 const std::list<ServerIndexChange>& changes, | 1042 static void FormatLog(Json::Value& target, |
1043 bool done, | 1043 const std::list<T>& log, |
1044 int64_t since) | 1044 const std::string& name, |
1045 bool done, | |
1046 int64_t since) | |
1045 { | 1047 { |
1046 Json::Value items = Json::arrayValue; | 1048 Json::Value items = Json::arrayValue; |
1047 for (std::list<ServerIndexChange>::const_iterator | 1049 for (typename std::list<T>::const_iterator |
1048 it = changes.begin(); it != changes.end(); it++) | 1050 it = log.begin(); it != log.end(); it++) |
1049 { | 1051 { |
1050 Json::Value item; | 1052 Json::Value item; |
1051 it->Format(item); | 1053 it->Format(item); |
1052 items.append(item); | 1054 items.append(item); |
1053 } | 1055 } |
1054 | 1056 |
1055 target = Json::objectValue; | 1057 target = Json::objectValue; |
1056 target["Changes"] = items; | 1058 target[name] = items; |
1057 target["Done"] = done; | 1059 target["Done"] = done; |
1058 | 1060 |
1059 int64_t last = (changes.size() == 0 ? since : changes.back().GetSeq()); | 1061 int64_t last = (log.size() == 0 ? since : log.back().GetSeq()); |
1060 target["Last"] = static_cast<int>(last); | 1062 target["Last"] = static_cast<int>(last); |
1061 } | 1063 } |
1062 | 1064 |
1063 | 1065 |
1064 bool ServerIndex::GetChanges(Json::Value& target, | 1066 bool ServerIndex::GetChanges(Json::Value& target, |
1071 { | 1073 { |
1072 boost::mutex::scoped_lock lock(mutex_); | 1074 boost::mutex::scoped_lock lock(mutex_); |
1073 db_->GetChanges(changes, done, since, maxResults); | 1075 db_->GetChanges(changes, done, since, maxResults); |
1074 } | 1076 } |
1075 | 1077 |
1076 FormatChanges(target, changes, done, since); | 1078 FormatLog(target, changes, "Changes", done, since); |
1077 return true; | 1079 return true; |
1078 } | 1080 } |
1079 | 1081 |
1080 | 1082 |
1081 bool ServerIndex::GetLastChange(Json::Value& target) | 1083 bool ServerIndex::GetLastChange(Json::Value& target) |
1085 { | 1087 { |
1086 boost::mutex::scoped_lock lock(mutex_); | 1088 boost::mutex::scoped_lock lock(mutex_); |
1087 db_->GetLastChange(changes); | 1089 db_->GetLastChange(changes); |
1088 } | 1090 } |
1089 | 1091 |
1090 FormatChanges(target, changes, true, 0); | 1092 FormatLog(target, changes, "Changes", true, 0); |
1091 return true; | 1093 return true; |
1092 } | 1094 } |
1093 | 1095 |
1094 | 1096 |
1095 void ServerIndex::LogExportedResource(const std::string& publicId, | 1097 void ServerIndex::LogExportedResource(const std::string& publicId, |
1168 | 1170 |
1169 bool ServerIndex::GetExportedResources(Json::Value& target, | 1171 bool ServerIndex::GetExportedResources(Json::Value& target, |
1170 int64_t since, | 1172 int64_t since, |
1171 unsigned int maxResults) | 1173 unsigned int maxResults) |
1172 { | 1174 { |
1173 boost::mutex::scoped_lock lock(mutex_); | 1175 std::list<ExportedResource> exported; |
1174 db_->GetExportedResources(target, since, maxResults); | 1176 bool done; |
1177 | |
1178 { | |
1179 boost::mutex::scoped_lock lock(mutex_); | |
1180 db_->GetExportedResources(exported, done, since, maxResults); | |
1181 } | |
1182 | |
1183 FormatLog(target, exported, "Exports", done, since); | |
1175 return true; | 1184 return true; |
1176 } | 1185 } |
1177 | 1186 |
1187 | |
1178 bool ServerIndex::GetLastExportedResource(Json::Value& target) | 1188 bool ServerIndex::GetLastExportedResource(Json::Value& target) |
1179 { | 1189 { |
1180 boost::mutex::scoped_lock lock(mutex_); | 1190 std::list<ExportedResource> exported; |
1181 db_->GetLastExportedResource(target); | 1191 |
1192 { | |
1193 boost::mutex::scoped_lock lock(mutex_); | |
1194 db_->GetLastExportedResource(exported); | |
1195 } | |
1196 | |
1197 FormatLog(target, exported, "Exports", true, 0); | |
1182 return true; | 1198 return true; |
1183 } | 1199 } |
1184 | 1200 |
1185 | 1201 |
1186 bool ServerIndex::IsRecyclingNeeded(uint64_t instanceSize) | 1202 bool ServerIndex::IsRecyclingNeeded(uint64_t instanceSize) |