~ubuntu-branches/ubuntu/wily/ginkgocadx/wily-proposed

« back to all changes in this revision

Viewing changes to src/cadxcore/main/controllers/dcmtk/dicomservers.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Tille
  • Date: 2011-05-02 08:09:26 UTC
  • Revision ID: james.westby@ubuntu.com-20110502080926-bql5wep49c7hg91t
Tags: upstream-2.4.1.1
ImportĀ upstreamĀ versionĀ 2.4.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  
 
3
 *  $Id: dicomservers.cpp 3787 2011-04-29 06:38:01Z tovar $
 
4
 *  Ginkgo CADx Project
 
5
 *
 
6
 *  Copyright 2008-10 MetaEmotion S.L. All rights reserved.
 
7
 *  http://ginkgo-cadx.com
 
8
 *
 
9
 *  This file is licensed under LGPL v3 license.
 
10
 *  See License.txt for details
 
11
 *
 
12
 *
 
13
 */
 
14
#include "dicomservers.h"
 
15
#include <iostream>
 
16
#include <wx/filename.h>
 
17
#include <wx/file.h>
 
18
#include <wx/textfile.h>
 
19
#include <wx/dir.h>
 
20
#include <wx/confbase.h>
 
21
#include <main/entorno.h>
 
22
#include <api/globals.h>
 
23
#include <api/icontextoestudio.h>
 
24
 
 
25
DicomServerList* DicomServerList::m_pInstance = 0;
 
26
 
 
27
DicomServerList::DicomServerList()
 
28
{
 
29
        serverHolders = NULL;
 
30
        localServer = NULL;
 
31
        lastInsertedHolder = NULL;
 
32
        Reload();
 
33
        //std::cout << "DicomServerList construido" << std::endl;
 
34
}
 
35
 
 
36
DicomServerList::~DicomServerList()
 
37
{
 
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;
 
43
                holder->next = NULL;
 
44
                delete holder;
 
45
                holder = tempHolder;
 
46
        }
 
47
        if (localServer != NULL) {
 
48
                delete localServer;
 
49
                localServer = NULL;
 
50
        }
 
51
        serverHolders = NULL;
 
52
        lastInsertedHolder = NULL;
 
53
        //std::cout << "DicomServerList destruido" << std::endl;
 
54
}
 
55
 
 
56
DicomServerList* DicomServerList::Instance()
 
57
{
 
58
        if (m_pInstance == NULL) {
 
59
                m_pInstance = new DicomServerList();
 
60
        }
 
61
        return m_pInstance;
 
62
}
 
63
 
 
64
void DicomServerList::FreeInstance()
 
65
{
 
66
        if (m_pInstance != NULL) {
 
67
                delete m_pInstance;
 
68
                m_pInstance = 0;
 
69
        }
 
70
 
 
71
}
 
72
 
 
73
void DicomServerList::AddServer(const DicomServer& newServer, bool isDefault)
 
74
{
 
75
        if (isDefault) {
 
76
                for (DicomServerHolder* sl = GetList(); sl != NULL; sl = sl->next) {
 
77
                        sl->server.isDefault = false;
 
78
                }
 
79
        }
 
80
        if (TieneServer(newServer.ID)) {
 
81
                DicomServer* server = GetServer(newServer.ID);
 
82
                *server = newServer;
 
83
                server->isDefault = isDefault;
 
84
        }
 
85
        else {
 
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;
 
90
                } else {
 
91
                        lastInsertedHolder->next = newServerHolder;
 
92
                        lastInsertedHolder = lastInsertedHolder->next;
 
93
                }
 
94
        }
 
95
        
 
96
}
 
97
 
 
98
bool DicomServerList::TieneServer(const std::string& ID)
 
99
{
 
100
        DicomServerHolder* it;
 
101
 
 
102
        bool found = false;
 
103
 
 
104
        for (it = serverHolders; it != NULL && !found; it = it->next) {
 
105
                if (it->server.ID == ID) {
 
106
                        found = true;
 
107
                }
 
108
        }
 
109
 
 
110
        return found;
 
111
}
 
112
 
 
113
DicomServer* DicomServerList::GetServer(const std::string& ID)
 
114
{
 
115
        DicomServer* server = NULL;
 
116
 
 
117
        DicomServerHolder* it;
 
118
 
 
119
        bool found = false;
 
120
 
 
121
        for (it = serverHolders; it != NULL && !found; it = it->next) {
 
122
                if (it->server.ID == ID) {
 
123
                        found = true;
 
124
                        server = &it->server;
 
125
                }
 
126
        }
 
127
 
 
128
        if (server == NULL) {
 
129
                throw GinkgoNoServerFoundException();
 
130
        }
 
131
 
 
132
        return server;
 
133
}
 
134
 
 
135
DicomServer* DicomServerList::GetLocalServer()
 
136
{
 
137
        if (localServer == NULL) {
 
138
                throw GinkgoNoServerFoundException();
 
139
        }
 
140
        return localServer;
 
141
}
 
142
 
 
143
DicomServerHolder* DicomServerList::GetList()
 
144
{
 
145
        return serverHolders;
 
146
}
 
147
 
 
148
DicomServer* DicomServerList::GetDefaultServer()
 
149
{
 
150
        if (serverHolders != NULL) {
 
151
                for (DicomServerHolder* it = serverHolders; it != NULL; it = it->next) {
 
152
                        if (it->server.isDefault) {
 
153
                                return &it->server;
 
154
                        }
 
155
                }
 
156
        }
 
157
        if (serverHolders != NULL) {
 
158
                return &serverHolders->server;
 
159
        } else {
 
160
                return NULL;
 
161
        }
 
162
}
 
163
 
 
164
void DicomServerList::SetDefaultServer(const std::string& ID)
 
165
{
 
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;
 
170
                        } else {
 
171
                                it->server.isDefault = false;
 
172
                        }
 
173
                }
 
174
        }
 
175
}
 
176
 
 
177
DicomServer* DicomServerList::GetFirst()
 
178
{
 
179
        DicomServer* server = NULL;
 
180
        if (serverHolders != NULL) {
 
181
                server = &serverHolders->server;
 
182
        }
 
183
        return server;
 
184
}
 
185
 
 
186
DicomServer* DicomServerList::GetLast()
 
187
{
 
188
        return &lastInsertedHolder->server;
 
189
}
 
190
 
 
191
void DicomServerList::Reload(){
 
192
        DicomServerHolder* holder = NULL;
 
193
        DicomServerHolder* tempHolder = NULL;
 
194
        for (holder = serverHolders; holder != NULL;) {
 
195
                tempHolder = holder->next;
 
196
                holder->next = NULL;
 
197
                delete holder;
 
198
                holder = tempHolder;
 
199
        }
 
200
        serverHolders = NULL;
 
201
        lastInsertedHolder = NULL;
 
202
 
 
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"));
 
207
        wxString str;
 
208
        long dummy;
 
209
 
 
210
        bool bCont = config->GetFirstGroup(str, dummy);
 
211
        bool existDefault = false;
 
212
        while ( bCont ) {
 
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());
 
220
                int puerto=0;
 
221
                config->Read(wxT("Puerto"),&puerto);
 
222
                int pdu=DEFAULT_PDU_LENGTH;
 
223
                config->Read(wxT("PDU"),&pdu,DEFAULT_PDU_LENGTH);
 
224
 
 
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;
 
241
 
 
242
                config->SetPath(wxT(".."));
 
243
                bCont = config->GetNextGroup(str, dummy);
 
244
        }
 
245
 
 
246
        if (!existDefault) {
 
247
                if (serverHolders != NULL) {
 
248
                        serverHolders->server.isDefault = true;
 
249
                }
 
250
        }
 
251
 
 
252
        //local server
 
253
        //se actualiza el fichero de configuracion
 
254
        config->SetPath(wxT("/GinkgoCore/PACS/Local"));
 
255
        int puerto = 0;
 
256
        puerto = (int)config->Read(wxT("Puerto"),11112);
 
257
        std::string localAet = GNC::Entorno::Instance()->GetDicomLocalAET();
 
258
        
 
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);
 
265
#endif
 
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);
 
271
#endif
 
272
        config->Read(wxT("certificate"), &str, clavePublica);
 
273
        localServer->certificate = str.ToUTF8();
 
274
}
 
275