More diagnostics for close
[metaproxy-moved-to-github.git] / src / p2.cpp
1 /* $Id: p2.cpp,v 1.5 2005-10-15 14:09:09 adam Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
5  */
6 /* $Id: p2.cpp,v 1.5 2005-10-15 14:09:09 adam Exp $
7    Copyright (c) 1998-2005, Index Data.
8
9 This file is part of the yaz-proxy.
10
11 YAZ proxy is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 2, or (at your option) any later
14 version.
15
16 YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19 for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with YAZ proxy; see the file LICENSE.  If not, write to the
23 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 02111-1307, USA.
25  */
26
27 #include <pthread.h>
28 #include <stdlib.h>
29 #include <yaz/log.h>
30 #include <yaz/diagbib1.h>
31 #include <yaz/options.h>
32
33 #include "config.hpp"
34 #include <yaz++/socket-manager.h>
35 #include "p2_config.h"
36 #include "p2_frontend.h"
37 #include "p2_xmlerror.h"
38 #include "p2_modules.h"
39
40 using namespace yazpp_1;
41
42 extern P2_ModuleEntry *p2_backend_dummy;
43
44 /*
45   frontend result set map
46     resultset -> db,query
47
48   backend result set map
49     db,query -> resultset, target
50                 resultset, target
51 */
52 class P2_Frontend;
53
54 P2_Config *P2_Server::lockConfig()
55 {
56     pthread_mutex_lock(&m_mutex_config);
57     return m_config;
58 }
59
60 void P2_Server::unlockConfig()
61 {
62     pthread_mutex_unlock(&m_mutex_config);
63 }
64
65 P2_Server::P2_Server(IPDU_Observable *the_PDU_Observable,
66                      yp2::ThreadPoolSocketObserver *my_thread,
67                      P2_Config *config,
68                      P2_ModuleFactory *modules)
69     :  Z_Assoc(the_PDU_Observable)
70 {
71     m_my_thread = my_thread;
72     m_modules = modules;
73     m_config = config;
74
75     pthread_mutex_init(&m_mutex_config, 0);
76     
77     yaz_log(YLOG_LOG, "Construct P2_Server=%p", this);
78 }
79
80 IPDU_Observer *P2_Server::sessionNotify(IPDU_Observable
81                                        *the_PDU_Observable, int fd)
82 {
83     P2_Frontend *my = new P2_Frontend(the_PDU_Observable, m_my_thread, this);
84     yaz_log(YLOG_LOG, "New session %s", the_PDU_Observable->getpeername());
85     return my;
86 }
87
88 P2_Server::~P2_Server()
89 {
90     yaz_log(YLOG_LOG, "Destroy P2_server=%p", this);
91     pthread_mutex_destroy(&m_mutex_config);
92 }
93
94 void P2_Server::recv_GDU(Z_GDU *apdu, int len)
95 {
96 }
97
98 void P2_Server::failNotify()
99 {
100 }
101
102 void P2_Server::timeoutNotify()
103 {
104 }
105
106 void P2_Server::connectNotify()
107 {
108 }
109
110 int main(int argc, char **argv)
111 {
112     p2_xmlerror_setup();
113
114     P2_Config config;
115
116     if (!config.parse_options(argc, argv))
117     {
118         yaz_log(YLOG_FATAL, "Configuration incorrect. Exiting");
119         exit(1);
120     }
121
122     SocketManager mySocketManager;
123
124     PDU_Assoc *my_PDU_Assoc = 0;
125     
126     yp2::ThreadPoolSocketObserver my_thread(&mySocketManager,
127                                             config.m_no_threads);
128
129     my_PDU_Assoc = new PDU_Assoc(&mySocketManager);
130
131     P2_ModuleFactory modules;
132
133     modules.add(p2_backend_dummy);
134
135     std::list<P2_ConfigModule *>::const_iterator it;
136     for (it = config.m_modules.begin(); it != config.m_modules.end(); it++)
137         modules.add((*it)->m_fname.c_str());
138     
139     P2_Server z(my_PDU_Assoc, &my_thread, &config, &modules);
140     z.server(config.m_listen_address.c_str());
141
142     while (mySocketManager.processEvent() > 0)
143         ;
144     return 0;
145 }
146 /*
147  * Local variables:
148  * c-basic-offset: 4
149  * indent-tabs-mode: nil
150  * c-file-style: "stroustrup"
151  * End:
152  * vim: shiftwidth=4 tabstop=8 expandtab
153  */
154