3
* $Id: dicomservers.cpp 3787 2011-04-29 06:38:01Z tovar $
6
* Copyright 2008-10 MetaEmotion S.L. All rights reserved.
7
* http://ginkgo-cadx.com
9
* This file is licensed under LGPL v3 license.
10
* See License.txt for details
14
#include "dicomservers.h"
16
#include <wx/filename.h>
18
#include <wx/textfile.h>
20
#include <wx/confbase.h>
21
#include <main/entorno.h>
22
#include <api/globals.h>
23
#include <api/icontextoestudio.h>
25
DicomServerList* DicomServerList::m_pInstance = 0;
27
DicomServerList::DicomServerList()
31
lastInsertedHolder = NULL;
33
//std::cout << "DicomServerList construido" << std::endl;
36
DicomServerList::~DicomServerList()
38
//std::cout << "DicomServerList destruyendose" << std::endl;
39
DicomServerHolder* holder = NULL;
40
DicomServerHolder* tempHolder = NULL;
41
for (holder = serverHolders; holder != NULL;) {
42
tempHolder = holder->next;
47
if (localServer != NULL) {
52
lastInsertedHolder = NULL;
53
//std::cout << "DicomServerList destruido" << std::endl;
56
DicomServerList* DicomServerList::Instance()
58
if (m_pInstance == NULL) {
59
m_pInstance = new DicomServerList();
64
void DicomServerList::FreeInstance()
66
if (m_pInstance != NULL) {
73
void DicomServerList::AddServer(const DicomServer& newServer, bool isDefault)
76
for (DicomServerHolder* sl = GetList(); sl != NULL; sl = sl->next) {
77
sl->server.isDefault = false;
80
if (TieneServer(newServer.ID)) {
81
DicomServer* server = GetServer(newServer.ID);
83
server->isDefault = isDefault;
86
DicomServerHolder* newServerHolder = new DicomServerHolder(newServer.ID, newServer.AET, newServer.HostName, newServer.Port, newServer.Lossy, newServer.isDefault, newServer.PDU, newServer.useTLS, newServer.pacsUser, newServer.pacsPass, newServer.retrieveWithMove, newServer.retrieveSeries, newServer.verifyCredentials, newServer.certificate, newServer.privateKey);
87
newServerHolder->server.isDefault = isDefault;
88
if (serverHolders == NULL) {
89
lastInsertedHolder = serverHolders = newServerHolder;
91
lastInsertedHolder->next = newServerHolder;
92
lastInsertedHolder = lastInsertedHolder->next;
98
bool DicomServerList::TieneServer(const std::string& ID)
100
DicomServerHolder* it;
104
for (it = serverHolders; it != NULL && !found; it = it->next) {
105
if (it->server.ID == ID) {
113
DicomServer* DicomServerList::GetServer(const std::string& ID)
115
DicomServer* server = NULL;
117
DicomServerHolder* it;
121
for (it = serverHolders; it != NULL && !found; it = it->next) {
122
if (it->server.ID == ID) {
124
server = &it->server;
128
if (server == NULL) {
129
throw GinkgoNoServerFoundException();
135
DicomServer* DicomServerList::GetLocalServer()
137
if (localServer == NULL) {
138
throw GinkgoNoServerFoundException();
143
DicomServerHolder* DicomServerList::GetList()
145
return serverHolders;
148
DicomServer* DicomServerList::GetDefaultServer()
150
if (serverHolders != NULL) {
151
for (DicomServerHolder* it = serverHolders; it != NULL; it = it->next) {
152
if (it->server.isDefault) {
157
if (serverHolders != NULL) {
158
return &serverHolders->server;
164
void DicomServerList::SetDefaultServer(const std::string& ID)
166
if (serverHolders != NULL) {
167
for (DicomServerHolder* it = serverHolders; it != NULL; it = it->next) {
168
if (it->server.ID == ID) {
169
it->server.isDefault = true;
171
it->server.isDefault = false;
177
DicomServer* DicomServerList::GetFirst()
179
DicomServer* server = NULL;
180
if (serverHolders != NULL) {
181
server = &serverHolders->server;
186
DicomServer* DicomServerList::GetLast()
188
return &lastInsertedHolder->server;
191
void DicomServerList::Reload(){
192
DicomServerHolder* holder = NULL;
193
DicomServerHolder* tempHolder = NULL;
194
for (holder = serverHolders; holder != NULL;) {
195
tempHolder = holder->next;
200
serverHolders = NULL;
201
lastInsertedHolder = NULL;
203
//se cargan los servidores desde el fichero de configuracion
204
wxConfigBase * config = wxConfigBase::Get();
205
//se actualiza el fichero de configuracion
206
config->SetPath(wxT("/GinkgoCore/PACS/Servidores"));
210
bool bCont = config->GetFirstGroup(str, dummy);
211
bool existDefault = false;
213
config->SetPath(str);
214
config->Read(wxT("Identificador"),&str);
215
std::string id(str.ToUTF8());
216
config->Read(wxT("AET"),&str);
217
std::string aet(str.ToUTF8());
218
config->Read(wxT("Host"),&str);
219
std::string host(str.ToUTF8());
221
config->Read(wxT("Puerto"),&puerto);
222
int pdu=DEFAULT_PDU_LENGTH;
223
config->Read(wxT("PDU"),&pdu,DEFAULT_PDU_LENGTH);
225
DicomServer server(id, aet, host, puerto, 0, false, pdu, false, "", "", false, true, false, "", "");
226
config->Read(wxT("isDefault"), &server.isDefault, false);
227
config->Read(wxT("useTLS"),&server.useTLS, false);
228
config->Read(wxT("pacsUser"),&str, wxT(""));
229
server.pacsUser = str.ToUTF8();
230
config->Read(wxT("pacsPass"),&str, wxT(""));
231
server.pacsPass = str.ToUTF8();
232
config->Read(wxT("verifyCredentials"), &server.verifyCredentials, false);
233
config->Read(wxT("certificate"), &str, wxT(""));
234
server.certificate = str.ToUTF8();
235
config->Read(wxT("privateKey"), &str, wxT(""));
236
server.privateKey = str.ToUTF8();
237
config->Read(wxT("retrieveWithMove"),&server.retrieveWithMove, true);
238
config->Read(wxT("retrieveSeries"),&server.retrieveSeries, true);
239
AddServer(server, server.isDefault);
240
existDefault = existDefault || server.isDefault;
242
config->SetPath(wxT(".."));
243
bCont = config->GetNextGroup(str, dummy);
247
if (serverHolders != NULL) {
248
serverHolders->server.isDefault = true;
253
//se actualiza el fichero de configuracion
254
config->SetPath(wxT("/GinkgoCore/PACS/Local"));
256
puerto = (int)config->Read(wxT("Puerto"),11112);
257
std::string localAet = GNC::Entorno::Instance()->GetDicomLocalAET();
259
localServer = new DicomServer("ginkgo",localAet, "localhost", puerto, 0, false, 16384,false, "", "", false, true, false, "", "");
260
config->Read(wxT("useTLS"),&localServer->useTLS, false);
261
config->Read(wxT("verifyCredentials"), &localServer->verifyCredentials, false);
262
wxString clavePrivada;
263
#ifdef GINKGO_PRIVATE_KEY
264
clavePrivada = wxString::FromUTF8(GINKGO_PRIVATE_KEY);
266
config->Read(wxT("privateKey"), &str, clavePrivada);
267
localServer->privateKey = str.ToUTF8();
268
wxString clavePublica;
269
#ifdef GINKGO_PUBLIC_KEY
270
clavePublica = wxString::FromUTF8(GINKGO_PUBLIC_KEY);
272
config->Read(wxT("certificate"), &str, clavePublica);
273
localServer->certificate = str.ToUTF8();