First commit
[anna.git] / include / anna / comm / Application.hpp
1 // ANNA - Anna is Not 'N' Anymore
2 //
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
4 //
5 // https://bitbucket.org/testillano/anna
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 //
11 //     * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 //     * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
16 // distribution.
17 //     * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
33 // Authors: eduardo.ramos.testillano@gmail.com
34 //          cisco.tierra@gmail.com
35
36
37 #ifndef anna_comm_Application_hpp
38 #define anna_comm_Application_hpp
39
40 #include <vector>
41
42 #include <anna/app/Application.hpp>
43
44 #include <anna/comm/functions.hpp>
45
46 namespace anna {
47
48 namespace xml {
49 class Node;
50 }
51
52 namespace comm {
53
54 class Communicator;
55 class TransportFactory;
56
57 /**
58    Clase que modela el cargador de configuracin de gestor de comunicaciones.
59
60    Esta clase realiza dos operaciones primordiales para el comunicador:
61    \li Establece las direcciones en las que el comunicador de nuestra aplicacion atiende peticiones
62    de los procesos clientes. Este paso slo sera necesario si nuestro proceso acta como servidor
63    de algn otro proceso.
64    \li Establece las direcciones de los servidores de nuestra aplicacion. Este paso slo sera necesario
65    si nuestra aplicacion acta como cliente de algn otro servidor.
66
67    Hay que destacar que nuestra aplicacion puede actuar simultaneamente como cliente y/o servidor por
68    lo que puede haber ocasiones en que sea requieran las dos operaciones.
69
70    \see Communicator::setup
71 */
72 class Application : public app::Application {
73 public:
74   /**
75      Devuelve la instancia de la factoria de protocolos a usar por defecto en esta
76      aplicacion.
77      \return La instancia de la factoria de protocolos a usar por defecto en esta
78      aplicacion.
79   */
80   virtual TransportFactory& getDefaultTransportFactory() throw();
81
82 protected:
83   /**
84      Constructor.
85
86      @param shortName Nombre lgico de esta instancia. Ver Runnable.
87      @param title titulo de la aplicacion que aparecera al arrancar.
88      @param version Version de este programa. Aconsejamos el forma X.YRZZ. Donde X es la
89      version principal, Y la version secundaria y ZZ es el nmero de entrega realizada.
90      \param date Fecha de realizacion del componente. Normalmente sera el contenido de la macro __DATE__.
91      \param time Hora de realizacion del componente. Normalmente sera el contenido de la macro __TIME__.
92   */
93   Application(const char *shortName, const char *title, const char *version, const char* date = NULL, const char* time = NULL);
94
95   /**
96      Metodo manejador que podemos re-escribir para tratar la recepcion de la senhal SIGTERM.
97   */
98   virtual void signalTerminate() throw(RuntimeException);
99
100 private:
101   Application(const Application&);
102   bool supportCommunication() const throw() { return true; }
103
104   friend class Communicator;
105   friend anna::comm::Application& comm::functions::getApp() throw(RuntimeException);
106 };
107
108 }
109 }
110
111 #endif