comparison OrthancServer/OrthancInitialization.cpp @ 2801:3ee82c7313e7

New events in change callbacks: "UpdatedPeers" and "UpdatedModalities"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 23 Aug 2018 13:52:54 +0200
parents dc7330089736
children 7133ad478eea
comparison
equal deleted inserted replaced
2800:dc7330089736 2801:3ee82c7313e7
37 // "Please include winsock2.h before windows.h" 37 // "Please include winsock2.h before windows.h"
38 # include <winsock2.h> 38 # include <winsock2.h>
39 #endif 39 #endif
40 40
41 #include "OrthancInitialization.h" 41 #include "OrthancInitialization.h"
42 #include "ServerContext.h"
42 43
43 #include "../Core/HttpClient.h" 44 #include "../Core/HttpClient.h"
44 #include "../Core/Logging.h" 45 #include "../Core/Logging.h"
45 #include "../Core/OrthancException.h" 46 #include "../Core/OrthancException.h"
46 #include "../Core/Toolbox.h" 47 #include "../Core/Toolbox.h"
892 throw OrthancException(ErrorCode_InexistentItem); 893 throw OrthancException(ErrorCode_InexistentItem);
893 } 894 }
894 } 895 }
895 896
896 897
897 void Configuration::UpdateModality(const std::string& symbolicName, 898 void Configuration::UpdateModality(ServerContext& context,
899 const std::string& symbolicName,
898 const RemoteModalityParameters& modality) 900 const RemoteModalityParameters& modality)
899 { 901 {
900 boost::recursive_mutex::scoped_lock lock(globalMutex_); 902 {
901 903 boost::recursive_mutex::scoped_lock lock(globalMutex_);
902 if (!configuration_.isMember("DicomModalities")) 904
903 { 905 if (!configuration_.isMember("DicomModalities"))
904 configuration_["DicomModalities"] = Json::objectValue; 906 {
905 } 907 configuration_["DicomModalities"] = Json::objectValue;
906 908 }
907 Json::Value& modalities = configuration_["DicomModalities"]; 909
908 if (modalities.type() != Json::objectValue) 910 Json::Value& modalities = configuration_["DicomModalities"];
909 { 911 if (modalities.type() != Json::objectValue)
910 LOG(ERROR) << "Bad file format for modality: " << symbolicName; 912 {
911 throw OrthancException(ErrorCode_BadFileFormat); 913 LOG(ERROR) << "Bad file format for modality: " << symbolicName;
912 } 914 throw OrthancException(ErrorCode_BadFileFormat);
913 915 }
914 modalities.removeMember(symbolicName); 916
915 917 modalities.removeMember(symbolicName);
916 Json::Value v; 918
917 modality.ToJson(v); 919 Json::Value v;
918 modalities[symbolicName] = v; 920 modality.ToJson(v);
921 modalities[symbolicName] = v;
922 }
923
924 #if ORTHANC_ENABLE_PLUGINS == 1
925 if (context.HasPlugins())
926 {
927 context.GetPlugins().SignalUpdatedModalities();
928 }
929 #endif
919 } 930 }
920 931
921 932
922 void Configuration::RemoveModality(const std::string& symbolicName) 933 void Configuration::RemoveModality(ServerContext& context,
923 { 934 const std::string& symbolicName)
924 boost::recursive_mutex::scoped_lock lock(globalMutex_); 935 {
925 936 {
926 if (!configuration_.isMember("DicomModalities")) 937 boost::recursive_mutex::scoped_lock lock(globalMutex_);
927 { 938
928 LOG(ERROR) << "No modality with symbolic name: " << symbolicName; 939 if (!configuration_.isMember("DicomModalities"))
929 throw OrthancException(ErrorCode_BadFileFormat); 940 {
930 } 941 LOG(ERROR) << "No modality with symbolic name: " << symbolicName;
931 942 throw OrthancException(ErrorCode_BadFileFormat);
932 Json::Value& modalities = configuration_["DicomModalities"]; 943 }
933 if (modalities.type() != Json::objectValue) 944
934 { 945 Json::Value& modalities = configuration_["DicomModalities"];
935 LOG(ERROR) << "Bad file format for the \"DicomModalities\" configuration section"; 946 if (modalities.type() != Json::objectValue)
936 throw OrthancException(ErrorCode_BadFileFormat); 947 {
937 } 948 LOG(ERROR) << "Bad file format for the \"DicomModalities\" configuration section";
938 949 throw OrthancException(ErrorCode_BadFileFormat);
939 modalities.removeMember(symbolicName.c_str()); 950 }
940 } 951
941 952 modalities.removeMember(symbolicName.c_str());
942 953 }
943 void Configuration::UpdatePeer(const std::string& symbolicName, 954
955 #if ORTHANC_ENABLE_PLUGINS == 1
956 if (context.HasPlugins())
957 {
958 context.GetPlugins().SignalUpdatedModalities();
959 }
960 #endif
961 }
962
963
964 void Configuration::UpdatePeer(ServerContext& context,
965 const std::string& symbolicName,
944 const WebServiceParameters& peer) 966 const WebServiceParameters& peer)
945 { 967 {
946 peer.CheckClientCertificate(); 968 peer.CheckClientCertificate();
947 969
948 boost::recursive_mutex::scoped_lock lock(globalMutex_); 970 {
949 971 boost::recursive_mutex::scoped_lock lock(globalMutex_);
950 if (!configuration_.isMember("OrthancPeers")) 972
951 { 973 if (!configuration_.isMember("OrthancPeers"))
952 LOG(ERROR) << "No peer with symbolic name: " << symbolicName; 974 {
953 configuration_["OrthancPeers"] = Json::objectValue; 975 LOG(ERROR) << "No peer with symbolic name: " << symbolicName;
954 } 976 configuration_["OrthancPeers"] = Json::objectValue;
955 977 }
956 Json::Value& peers = configuration_["OrthancPeers"]; 978
957 if (peers.type() != Json::objectValue) 979 Json::Value& peers = configuration_["OrthancPeers"];
958 { 980 if (peers.type() != Json::objectValue)
959 LOG(ERROR) << "Bad file format for the \"OrthancPeers\" configuration section"; 981 {
960 throw OrthancException(ErrorCode_BadFileFormat); 982 LOG(ERROR) << "Bad file format for the \"OrthancPeers\" configuration section";
961 } 983 throw OrthancException(ErrorCode_BadFileFormat);
962 984 }
963 peers.removeMember(symbolicName); 985
964 986 peers.removeMember(symbolicName);
965 Json::Value v; 987
966 peer.Serialize(v, 988 Json::Value v;
967 false /* use simple format if possible */, 989 peer.Serialize(v,
968 true /* include passwords */); 990 false /* use simple format if possible */,
969 peers[symbolicName] = v; 991 true /* include passwords */);
992 peers[symbolicName] = v;
993 }
994
995 #if ORTHANC_ENABLE_PLUGINS == 1
996 if (context.HasPlugins())
997 {
998 context.GetPlugins().SignalUpdatedPeers();
999 }
1000 #endif
970 } 1001 }
971 1002
972 1003
973 void Configuration::RemovePeer(const std::string& symbolicName) 1004 void Configuration::RemovePeer(ServerContext& context,
974 { 1005 const std::string& symbolicName)
975 boost::recursive_mutex::scoped_lock lock(globalMutex_); 1006 {
976 1007 {
977 if (!configuration_.isMember("OrthancPeers")) 1008 boost::recursive_mutex::scoped_lock lock(globalMutex_);
978 { 1009
979 LOG(ERROR) << "No peer with symbolic name: " << symbolicName; 1010 if (!configuration_.isMember("OrthancPeers"))
980 throw OrthancException(ErrorCode_BadFileFormat); 1011 {
981 } 1012 LOG(ERROR) << "No peer with symbolic name: " << symbolicName;
982 1013 throw OrthancException(ErrorCode_BadFileFormat);
983 Json::Value& peers = configuration_["OrthancPeers"]; 1014 }
984 if (peers.type() != Json::objectValue) 1015
985 { 1016 Json::Value& peers = configuration_["OrthancPeers"];
986 LOG(ERROR) << "Bad file format for the \"OrthancPeers\" configuration section"; 1017 if (peers.type() != Json::objectValue)
987 throw OrthancException(ErrorCode_BadFileFormat); 1018 {
988 } 1019 LOG(ERROR) << "Bad file format for the \"OrthancPeers\" configuration section";
989 1020 throw OrthancException(ErrorCode_BadFileFormat);
990 peers.removeMember(symbolicName.c_str()); 1021 }
1022
1023 peers.removeMember(symbolicName.c_str());
1024 }
1025
1026 #if ORTHANC_ENABLE_PLUGINS == 1
1027 if (context.HasPlugins())
1028 {
1029 context.GetPlugins().SignalUpdatedPeers();
1030 }
1031 #endif
991 } 1032 }
992 1033
993 1034
994 1035
995 const std::string& Configuration::GetConfigurationAbsolutePath() 1036 const std::string& Configuration::GetConfigurationAbsolutePath()