001/**
002 * Copyright (C) 2014  Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
003 *
004 * This file is part of Dicoogle/dicoogle.
005 *
006 * Dicoogle/dicoogle is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Dicoogle/dicoogle is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with Dicoogle.  If not, see <http://www.gnu.org/licenses/>.
018 */
019
020
021
022/*
023 * Dicom Network is a singletone class to handler the services
024 * Each Device have a Application Entity and a Device can have multiple
025 * connections. Hence for an Application Entity we have multiple connections 
026 * associated too. 
027 * 
028 * Dicoogle is available to keep some DICOM services up,
029 * but services need to be handled and forward to correct entity 
030 * 
031 * 
032 */
033
034package pt.ua.dicoogle.server;
035
036
037import pt.ua.dicoogle.server.callbacks.LogEvent;
038import pt.ua.dicoogle.server.callbacks.LogEventAfter;
039import pt.ua.dicoogle.server.callbacks.LogEventBefore;
040import org.dcm4che2.net.Device;
041import org.dcm4che2.net.NetworkApplicationEntity;
042import org.dcm4che2.net.NetworkConnection;
043
044/**
045 *
046 * @author Luís A. Bastião Silva <bastiao@ua.pt>
047 */
048public abstract class DicomNetwork
049{    
050    
051
052    private NetworkApplicationEntity remoteAE = new NetworkApplicationEntity();
053    private NetworkConnection remoteConn = new NetworkConnection();
054    private Device device = null ;
055    private NetworkApplicationEntity localAE = new NetworkApplicationEntity();
056    private NetworkConnection localConn = new NetworkConnection();
057
058
059    // AETitle of Service
060    private String AETitle = null ;
061
062
063    /** Event Interface Calls */ 
064    LogEvent eventService = null ;
065    LogEventBefore eventBefore = null ;
066    LogEventAfter eventAfter = null ;
067
068    private String deviceName = null ;
069    
070    public DicomNetwork(String DeviceName)
071    {
072        // Starts Device
073        device = new Device(DeviceName);
074        this.deviceName = DeviceName; 
075    }
076
077
078
079    /**
080     * Connect to the service after happen
081     * For example in the case of c-move it will happen after send all images
082     *
083     * @param e An class that implement methods to be call
084     * @return a boolean to know if event will be triggered or not
085     */
086    public boolean connectAfter(LogEventAfter e)
087    {
088        boolean result = false ;
089        if (e != null && e instanceof LogEventAfter  )
090        {
091            result = true ;
092        }
093        this.eventAfter = e ;
094        return result ; 
095    }
096
097
098    /**
099     * Connect to the service before happen
100     * For example in the case of c-move it will happen before send images
101     *
102     * @param e An class that implement methods to be call
103     * @return a boolean to know if event will be triggered or not
104     */
105    public boolean connectBefore(LogEventBefore e)
106    {
107        boolean result = false ;
108        if (e != null && e instanceof LogEventBefore  )
109        {
110            result = true ;
111        }
112        this.eventBefore = e ;
113        return result ;
114    }
115
116    /**
117     * When a service is started or stopped it will be called after service
118     * start/stop
119     * @param e the class that have necessary callbacks implemented
120     * @return
121     */
122
123    public boolean connectServices(LogEvent e)
124    {
125        boolean result = false ;
126        if (e != null && e instanceof LogEvent )
127        {
128            result = true ;
129        }
130        this.eventService = e ;
131        return result ;
132    }
133
134
135
136
137    public boolean startListening()
138    {
139        boolean result = false;
140
141        result = doStartService();
142        if (this.eventService!=null)
143            this.eventService.startService(this.deviceName +  " was started " +
144                    "QueryRetrieve");
145        return result ; 
146          
147    }
148
149
150    public boolean stopListening()
151    {
152        boolean result = false;
153
154        result = doStopService();
155        if (this.eventService!=null)
156            this.eventService.stopService(this.deviceName +  " was stoppped" +
157                    " QueryRetrieve");
158        return result ;
159    }
160
161    public abstract boolean doStartService();
162    public abstract boolean doStopService();
163    
164
165
166    /**
167     * @return the remoteAE
168     */
169    public NetworkApplicationEntity getRemoteAE() {
170        return remoteAE;
171    }
172
173    /**
174     * @param remoteAE the remoteAE to set
175     */
176    public void setRemoteAE(NetworkApplicationEntity remoteAE) {
177        this.remoteAE = remoteAE;
178    }
179
180    /**
181     * @return the remoteConn
182     */
183    public NetworkConnection getRemoteConn() {
184        return remoteConn;
185    }
186
187    /**
188     * @param remoteConn the remoteConn to set
189     */
190    public void setRemoteConn(NetworkConnection remoteConn) {
191        this.remoteConn = remoteConn;
192    }
193
194    /**
195     * @return the device
196     */
197    public Device getDevice() {
198        return device;
199    }
200
201    /**
202     * @param device the device to set
203     */
204    public void setDevice(Device device) {
205        this.device = device;
206    }
207
208    /**
209     * @return the localAE
210     */
211    public NetworkApplicationEntity getLocalAE() {
212        return localAE;
213    }
214
215    /**
216     * @param localAE the localAE to set
217     */
218    public void setLocalAE(NetworkApplicationEntity localAE) {
219        this.localAE = localAE;
220    }
221
222    /**
223     * @return the localConn
224     */
225    public NetworkConnection getLocalConn() {
226        return localConn;
227    }
228
229    /**
230     * @param localConn the localConn to set
231     */
232    public void setLocalConn(NetworkConnection localConn) {
233        this.localConn = localConn;
234    }
235
236    /**
237     * @return the AETitle
238     */
239    public String getAETitle() {
240        return AETitle;
241    }
242
243    /**
244     * @param AETitle the AETitle to set
245     */
246    public void setAETitle(String AETitle) {
247        this.AETitle = AETitle;
248    }
249
250}