Mercurial > hg > orthanc
comparison Plugins/Samples/StorageArea/Plugin.cpp @ 1627:da7854deb662
Plugin callbacks must now return explicit "OrthancPluginErrorCode" instead of integers
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 18 Sep 2015 16:32:29 +0200 |
parents | 97268448bdfc |
children | 87c77b9b3679 |
comparison
equal
deleted
inserted
replaced
1626:8dc468f44661 | 1627:da7854deb662 |
---|---|
31 { | 31 { |
32 return "plugin_" + std::string(uuid); | 32 return "plugin_" + std::string(uuid); |
33 } | 33 } |
34 | 34 |
35 | 35 |
36 static int32_t StorageCreate(const char* uuid, | 36 static OrthancPluginErrorCode StorageCreate(const char* uuid, |
37 const void* content, | 37 const void* content, |
38 int64_t size, | 38 int64_t size, |
39 OrthancPluginContentType type) | 39 OrthancPluginContentType type) |
40 { | 40 { |
41 std::string path = GetPath(uuid); | 41 std::string path = GetPath(uuid); |
42 | 42 |
43 FILE* fp = fopen(path.c_str(), "wb"); | 43 FILE* fp = fopen(path.c_str(), "wb"); |
44 if (!fp) | 44 if (!fp) |
45 { | 45 { |
46 return -1; | 46 return OrthancPluginErrorCode_Plugin; |
47 } | 47 } |
48 | 48 |
49 bool ok = fwrite(content, size, 1, fp) == 1; | 49 bool ok = fwrite(content, size, 1, fp) == 1; |
50 fclose(fp); | 50 fclose(fp); |
51 | 51 |
52 return ok ? 0 : -1; | 52 return ok ? OrthancPluginErrorCode_Success : OrthancPluginErrorCode_Plugin; |
53 } | 53 } |
54 | 54 |
55 | 55 |
56 static int32_t StorageRead(void** content, | 56 static OrthancPluginErrorCode StorageRead(void** content, |
57 int64_t* size, | 57 int64_t* size, |
58 const char* uuid, | 58 const char* uuid, |
59 OrthancPluginContentType type) | 59 OrthancPluginContentType type) |
60 { | 60 { |
61 std::string path = GetPath(uuid); | 61 std::string path = GetPath(uuid); |
62 | 62 |
63 FILE* fp = fopen(path.c_str(), "rb"); | 63 FILE* fp = fopen(path.c_str(), "rb"); |
64 if (!fp) | 64 if (!fp) |
65 { | 65 { |
66 return -1; | 66 return OrthancPluginErrorCode_Plugin; |
67 } | 67 } |
68 | 68 |
69 if (fseek(fp, 0, SEEK_END) < 0) | 69 if (fseek(fp, 0, SEEK_END) < 0) |
70 { | 70 { |
71 fclose(fp); | 71 fclose(fp); |
72 return -1; | 72 return OrthancPluginErrorCode_Plugin; |
73 } | 73 } |
74 | 74 |
75 *size = ftell(fp); | 75 *size = ftell(fp); |
76 | 76 |
77 if (fseek(fp, 0, SEEK_SET) < 0) | 77 if (fseek(fp, 0, SEEK_SET) < 0) |
78 { | 78 { |
79 fclose(fp); | 79 fclose(fp); |
80 return -1; | 80 return OrthancPluginErrorCode_Plugin; |
81 } | 81 } |
82 | 82 |
83 bool ok = true; | 83 bool ok = true; |
84 | 84 |
85 if (*size == 0) | 85 if (*size == 0) |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 fclose(fp); | 99 fclose(fp); |
100 | 100 |
101 return ok ? 0 : -1; | 101 return ok ? OrthancPluginErrorCode_Success : OrthancPluginErrorCode_Plugin; |
102 } | 102 } |
103 | 103 |
104 | 104 |
105 static int32_t StorageRemove(const char* uuid, | 105 static OrthancPluginErrorCode StorageRemove(const char* uuid, |
106 OrthancPluginContentType type) | 106 OrthancPluginContentType type) |
107 { | 107 { |
108 std::string path = GetPath(uuid); | 108 std::string path = GetPath(uuid); |
109 return remove(path.c_str()); | 109 |
110 if (remove(path.c_str()) == 0) | |
111 { | |
112 return OrthancPluginErrorCode_Success; | |
113 } | |
114 else | |
115 { | |
116 return OrthancPluginErrorCode_Plugin; | |
117 } | |
110 } | 118 } |
111 | 119 |
112 | 120 |
113 extern "C" | 121 extern "C" |
114 { | 122 { |