comparison Plugins/Engine/PluginsManager.cpp @ 1581:357c4bb15701

Plugins have access to explicit error codes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Aug 2015 16:18:37 +0200
parents f967bdf8534e
children 0a2ad4a6858f
comparison
equal deleted inserted replaced
1580:bf502300c52e 1581:357c4bb15701
132 assert(getVersion != NULL); 132 assert(getVersion != NULL);
133 return getVersion(); 133 return getVersion();
134 } 134 }
135 135
136 136
137 int32_t PluginsManager::InvokeService(OrthancPluginContext* context, 137 OrthancPluginErrorCode PluginsManager::InvokeService(OrthancPluginContext* context,
138 _OrthancPluginService service, 138 _OrthancPluginService service,
139 const void* params) 139 const void* params)
140 { 140 {
141 switch (service) 141 switch (service)
142 { 142 {
143 case _OrthancPluginService_LogError: 143 case _OrthancPluginService_LogError:
144 LOG(ERROR) << reinterpret_cast<const char*>(params); 144 LOG(ERROR) << reinterpret_cast<const char*>(params);
145 return 0; 145 return OrthancPluginErrorCode_Success;
146 146
147 case _OrthancPluginService_LogWarning: 147 case _OrthancPluginService_LogWarning:
148 LOG(WARNING) << reinterpret_cast<const char*>(params); 148 LOG(WARNING) << reinterpret_cast<const char*>(params);
149 return 0; 149 return OrthancPluginErrorCode_Success;
150 150
151 case _OrthancPluginService_LogInfo: 151 case _OrthancPluginService_LogInfo:
152 LOG(INFO) << reinterpret_cast<const char*>(params); 152 LOG(INFO) << reinterpret_cast<const char*>(params);
153 return 0; 153 return OrthancPluginErrorCode_Success;
154 154
155 default: 155 default:
156 break; 156 break;
157 } 157 }
158 158
159 PluginsManager* that = reinterpret_cast<PluginsManager*>(context->pluginsManager); 159 PluginsManager* that = reinterpret_cast<PluginsManager*>(context->pluginsManager);
160 bool error = false;
161 160
162 for (std::list<IPluginServiceProvider*>::iterator 161 for (std::list<IPluginServiceProvider*>::iterator
163 it = that->serviceProviders_.begin(); 162 it = that->serviceProviders_.begin();
164 it != that->serviceProviders_.end(); ++it) 163 it != that->serviceProviders_.end(); ++it)
165 { 164 {
166 try 165 try
167 { 166 {
168 if ((*it)->InvokeService(service, params)) 167 if ((*it)->InvokeService(service, params))
169 { 168 {
170 return 0; 169 return OrthancPluginErrorCode_Success;
171 } 170 }
172 } 171 }
173 catch (OrthancException&) 172 catch (OrthancException& e)
174 { 173 {
175 // This service provider has failed, go to the next 174 // This service provider has failed
176 error = true; 175 LOG(ERROR) << "Exception while invoking a plugin service: " << e.What();
177 } 176 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
178 } 177 }
179 178 }
180 if (error) 179
181 { 180 LOG(ERROR) << "Plugin invoking unknown service: " << service;
182 // LOG(ERROR) << "Exception when dealing with service " << service; 181 return OrthancPluginErrorCode_UnknownPluginService;
183 }
184 else
185 {
186 LOG(ERROR) << "Plugin invoking unknown service " << service;
187 }
188
189 return -1;
190 } 182 }
191 183
192 184
193 PluginsManager::PluginsManager() 185 PluginsManager::PluginsManager()
194 { 186 {