comparison Plugins/Engine/OrthancPlugins.cpp @ 1135:67c3c1e4a6e0

index-only mode, and custom storage area with plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 09 Sep 2014 15:55:43 +0200
parents 382e162c074c
children 208dc67b9bab
comparison
equal deleted inserted replaced
1134:ba9fd42284d0 1135:67c3c1e4a6e0
86 86
87 ServerContext& context_; 87 ServerContext& context_;
88 RestCallbacks restCallbacks_; 88 RestCallbacks restCallbacks_;
89 OrthancRestApi* restApi_; 89 OrthancRestApi* restApi_;
90 OnStoredCallbacks onStoredCallbacks_; 90 OnStoredCallbacks onStoredCallbacks_;
91 91 bool hasStorageArea_;
92 PImpl(ServerContext& context) : context_(context), restApi_(NULL) 92 _OrthancPluginRegisterStorageArea storageArea_;
93 { 93
94 PImpl(ServerContext& context) :
95 context_(context),
96 restApi_(NULL),
97 hasStorageArea_(false)
98 {
99 memset(&storageArea_, 0, sizeof(storageArea_));
94 } 100 }
95 }; 101 };
96 102
97 103
98 static char* CopyString(const std::string& str) 104 static char* CopyString(const std::string& str)
803 case _OrthancPluginService_HasInstanceMetadata: 809 case _OrthancPluginService_HasInstanceMetadata:
804 case _OrthancPluginService_GetInstanceMetadata: 810 case _OrthancPluginService_GetInstanceMetadata:
805 AccessDicomInstance(service, parameters); 811 AccessDicomInstance(service, parameters);
806 return true; 812 return true;
807 813
814 case _OrthancPluginService_RegisterStorageArea:
815 {
816 const _OrthancPluginRegisterStorageArea& p =
817 *reinterpret_cast<const _OrthancPluginRegisterStorageArea*>(parameters);
818
819 pimpl_->storageArea_ = p;
820 return true;
821 }
822
808 default: 823 default:
809 return false; 824 return false;
810 } 825 }
811 } 826 }
812 827
814 void OrthancPlugins::SetOrthancRestApi(OrthancRestApi& restApi) 829 void OrthancPlugins::SetOrthancRestApi(OrthancRestApi& restApi)
815 { 830 {
816 pimpl_->restApi_ = &restApi; 831 pimpl_->restApi_ = &restApi;
817 } 832 }
818 833
834
835 bool OrthancPlugins::HasStorageArea() const
836 {
837 return pimpl_->hasStorageArea_;
838 }
839
840
841 namespace
842 {
843 class PluginStorageArea : public IStorageArea
844 {
845 private:
846 _OrthancPluginRegisterStorageArea params_;
847
848 void Free(void* buffer) const
849 {
850 if (buffer != NULL)
851 {
852 params_.free_(buffer);
853 }
854 }
855
856 OrthancPluginContentType Convert(FileContentType type) const
857 {
858 switch (type)
859 {
860 case FileContentType_Dicom:
861 return OrthancPluginContentType_Dicom;
862
863 case FileContentType_DicomAsJson:
864 return OrthancPluginContentType_DicomAsJson;
865
866 default:
867 return OrthancPluginContentType_Unknown;
868 }
869 }
870
871 public:
872 PluginStorageArea(const _OrthancPluginRegisterStorageArea& params) : params_(params)
873 {
874 }
875
876 virtual void Create(const std::string& uuid,
877 const void* content,
878 size_t size,
879 FileContentType type)
880 {
881 if (params_.create_(uuid.c_str(), content, size, Convert(type)) != 0)
882 {
883 throw OrthancException(ErrorCode_Plugin);
884 }
885 }
886
887 virtual void Read(std::string& content,
888 const std::string& uuid,
889 FileContentType type) const
890 {
891 void* buffer = NULL;
892 int64_t size = 0;
893
894 if (params_.read_(&buffer, &size, uuid.c_str(), Convert(type)) != 0)
895 {
896 throw OrthancException(ErrorCode_Plugin);
897 }
898
899 try
900 {
901 content.resize(size);
902 }
903 catch (OrthancException&)
904 {
905 Free(buffer);
906 throw;
907 }
908
909 if (size > 0)
910 {
911 memcpy(&content[0], buffer, size);
912 }
913
914 Free(buffer);
915 }
916
917 virtual void Remove(const std::string& uuid,
918 FileContentType type)
919 {
920 if (params_.remove_(uuid.c_str(), Convert(type)) != 0)
921 {
922 throw OrthancException(ErrorCode_Plugin);
923 }
924 }
925 };
926 }
927
928
929 IStorageArea* OrthancPlugins::GetStorageArea()
930 {
931 if (!HasStorageArea())
932 {
933 throw OrthancException(ErrorCode_BadSequenceOfCalls);
934 }
935
936 return new PluginStorageArea(pimpl_->storageArea_);;
937 }
819 } 938 }