fe403e6fc468815e1527446905a7e568a78efab8
[yazproxy-moved-to-github.git] / src / p2_frontend.h
1 /* $Id: p2_frontend.h,v 1.1 2005-10-05 12:07:14 adam Exp $
2    Copyright (c) 1998-2005, Index Data.
3
4 This file is part of the yaz-proxy.
5
6 YAZ proxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with YAZ proxy; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #ifndef P2_FRONTEND_H
23 #define P2_FRONTEND_H
24
25 #include <list>
26 #include <vector>
27 #include <string>
28
29 #include "msg-thread.h"
30 #include <yaz++/z-assoc.h>
31 #include <yaz++/pdu-assoc.h>
32 #include <yaz++/gdu.h>
33 #include <yaz++/z-query.h>
34
35 class P2_Frontend;
36 class P2_Server;
37 class P2_Config;
38 class P2_ConfigTarget;
39 class P2_ModuleFactory;
40
41 class IP2_BackendSet;
42
43 class P2_BackendResultSet {
44  public:
45     P2_BackendResultSet();
46     ~P2_BackendResultSet();
47     yazpp_1::Yaz_Z_Query m_query;
48     std::list<std::string> m_db_list;
49     int m_hit_count;
50     IP2_BackendSet *m_int;
51     // record cache here 
52 };
53
54 class IP2_Backend;
55
56 class P2_Backend {
57  public:
58     P2_Backend(P2_ConfigTarget *cfg, IP2_Backend *backend_interface);
59     ~P2_Backend();
60  public:
61     std::list<P2_BackendResultSet *>m_resultSets;
62     P2_ConfigTarget *m_configTarget;
63     bool m_busy;
64     IP2_Backend *m_int;
65 };
66
67 class P2_Server : public yazpp_1::Z_Assoc {
68 public:
69     ~P2_Server();
70     P2_Server(yazpp_1::IPDU_Observable *the_PDU_Observable,
71               Msg_Thread *m_my_thread,
72               P2_Config *config,
73               P2_ModuleFactory *modules);
74     P2_Config *lockConfig();
75     void unlockConfig();
76     std::list<P2_Backend *>m_backend_list;
77     P2_ModuleFactory *m_modules;
78 private:
79     yazpp_1::IPDU_Observer* sessionNotify(
80         yazpp_1::IPDU_Observable *the_PDU_Observable,
81         int fd);
82     void recv_GDU(Z_GDU *apdu, int len);
83
84     void failNotify();
85     void timeoutNotify();
86     void connectNotify();
87 private:
88     P2_Config *m_config;
89     Msg_Thread *m_my_thread;
90     pthread_mutex_t m_mutex_config;
91 };
92
93 class P2_FrontResultSet {
94 public:
95     P2_FrontResultSet(const char *id);
96     ~P2_FrontResultSet();
97     void setQuery(Z_Query *z_query);
98     void setDatabases(char **db, int num);
99     std::string m_resultSetId;
100     std::vector<std::string> m_db_list;
101     yazpp_1::Yaz_Z_Query m_query;
102 };
103
104 class P2_Msg : public IMsg_Thread {
105 public:
106     int m_close_flag;
107     yazpp_1::GDU *m_gdu;
108     yazpp_1::GDU *m_output;
109     P2_Frontend *m_front;
110     P2_Server *m_server;
111     IMsg_Thread *handle();
112     void result();
113     P2_Msg(yazpp_1::GDU *gdu, P2_Frontend *front, P2_Server *server);
114     virtual ~P2_Msg();
115  private:
116
117     Z_APDU *frontend_search_resultset(Z_APDU *z_gdu, ODR odr,
118                                       P2_FrontResultSet **rset);
119     Z_APDU *frontend_present_resultset(Z_APDU *z_gdu, ODR odr,
120                                        P2_FrontResultSet **rset);
121     Z_APDU *frontend_search_apdu(Z_APDU *z_gdu, ODR odr);
122     Z_APDU *frontend_present_apdu(Z_APDU *z_gdu, ODR odr);
123     P2_Backend *select_backend(std::string db,
124                                yazpp_1::Yaz_Z_Query *query,
125                                P2_BackendResultSet **bset);
126     P2_Backend *create_backend(std::string db);
127 };
128
129 class P2_Frontend : public yazpp_1::Z_Assoc {
130  public:
131     ~P2_Frontend();
132     P2_Frontend(yazpp_1::IPDU_Observable *the_PDU_Observable,
133                 Msg_Thread *m_my_thread, P2_Server *server);
134     IPDU_Observer* sessionNotify(yazpp_1::IPDU_Observable *the_PDU_Observable,
135                                  int fd);
136     
137     void recv_GDU(Z_GDU *apdu, int len);
138     
139     void failNotify();
140     void timeoutNotify();
141     void connectNotify();
142
143     int m_no_requests;
144     int m_delete_flag;
145     std::list<P2_FrontResultSet *> m_resultSets;
146     
147  private:
148     yazpp_1::GDUQueue m_in_queue;
149     Msg_Thread *m_my_thread;
150     P2_Server *m_server;
151  private:
152     bool P2_Frontend::search(Z_GDU *z_gdu);
153     bool P2_Frontend::handle_init(Z_GDU *z_gdu);
154 };
155
156 #endif
157 /*
158  * Local variables:
159  * c-basic-offset: 4
160  * indent-tabs-mode: nil
161  * End:
162  * vim: shiftwidth=4 tabstop=8 expandtab
163  */