f7d745e0c79c39ac737544c113f9eb34d266a293
[yazproxy-moved-to-github.git] / src / p2_frontend.h
1 /* $Id: p2_frontend.h,v 1.2 2005-10-13 09:58:52 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++/gduqueue.h>
34 #include <yaz++/z-query.h>
35
36 class P2_Frontend;
37 class P2_Server;
38 class P2_Config;
39 class P2_ConfigTarget;
40 class P2_ModuleFactory;
41
42 class IP2_BackendSet;
43
44 class P2_BackendResultSet {
45  public:
46     P2_BackendResultSet();
47     ~P2_BackendResultSet();
48     yazpp_1::Yaz_Z_Query m_query;
49     std::list<std::string> m_db_list;
50     int m_hit_count;
51     IP2_BackendSet *m_int;
52     // record cache here 
53 };
54
55 class IP2_Backend;
56
57 class P2_Backend {
58  public:
59     P2_Backend(P2_ConfigTarget *cfg, IP2_Backend *backend_interface);
60     ~P2_Backend();
61  public:
62     std::list<P2_BackendResultSet *>m_resultSets;
63     P2_ConfigTarget *m_configTarget;
64     bool m_busy;
65     IP2_Backend *m_int;
66 };
67
68 class P2_Server : public yazpp_1::Z_Assoc {
69 public:
70     ~P2_Server();
71     P2_Server(yazpp_1::IPDU_Observable *the_PDU_Observable,
72               Msg_Thread *m_my_thread,
73               P2_Config *config,
74               P2_ModuleFactory *modules);
75     P2_Config *lockConfig();
76     void unlockConfig();
77     std::list<P2_Backend *>m_backend_list;
78     P2_ModuleFactory *m_modules;
79 private:
80     yazpp_1::IPDU_Observer* sessionNotify(
81         yazpp_1::IPDU_Observable *the_PDU_Observable,
82         int fd);
83     void recv_GDU(Z_GDU *apdu, int len);
84
85     void failNotify();
86     void timeoutNotify();
87     void connectNotify();
88 private:
89     P2_Config *m_config;
90     Msg_Thread *m_my_thread;
91     pthread_mutex_t m_mutex_config;
92 };
93
94 class P2_FrontResultSet {
95 public:
96     P2_FrontResultSet(const char *id);
97     ~P2_FrontResultSet();
98     void setQuery(Z_Query *z_query);
99     void setDatabases(char **db, int num);
100     std::string m_resultSetId;
101     std::vector<std::string> m_db_list;
102     yazpp_1::Yaz_Z_Query m_query;
103 };
104
105 class P2_Msg : public IMsg_Thread {
106 public:
107     int m_close_flag;
108     yazpp_1::GDU *m_gdu;
109     yazpp_1::GDU *m_output;
110     P2_Frontend *m_front;
111     P2_Server *m_server;
112     IMsg_Thread *handle();
113     void result();
114     P2_Msg(yazpp_1::GDU *gdu, P2_Frontend *front, P2_Server *server);
115     virtual ~P2_Msg();
116  private:
117
118     Z_APDU *frontend_search_resultset(Z_APDU *z_gdu, ODR odr,
119                                       P2_FrontResultSet **rset);
120     Z_APDU *frontend_present_resultset(Z_APDU *z_gdu, ODR odr,
121                                        P2_FrontResultSet **rset);
122     Z_APDU *frontend_search_apdu(Z_APDU *z_gdu, ODR odr);
123     Z_APDU *frontend_present_apdu(Z_APDU *z_gdu, ODR odr);
124     P2_Backend *select_backend(std::string db,
125                                yazpp_1::Yaz_Z_Query *query,
126                                P2_BackendResultSet **bset);
127     P2_Backend *create_backend(std::string db);
128 };
129
130 class P2_Frontend : public yazpp_1::Z_Assoc {
131  public:
132     ~P2_Frontend();
133     P2_Frontend(yazpp_1::IPDU_Observable *the_PDU_Observable,
134                 Msg_Thread *m_my_thread, P2_Server *server);
135     IPDU_Observer* sessionNotify(yazpp_1::IPDU_Observable *the_PDU_Observable,
136                                  int fd);
137     
138     void recv_GDU(Z_GDU *apdu, int len);
139     
140     void failNotify();
141     void timeoutNotify();
142     void connectNotify();
143
144     int m_no_requests;
145     int m_delete_flag;
146     std::list<P2_FrontResultSet *> m_resultSets;
147     
148  private:
149     yazpp_1::GDUQueue m_in_queue;
150     Msg_Thread *m_my_thread;
151     P2_Server *m_server;
152  private:
153     bool P2_Frontend::search(Z_GDU *z_gdu);
154     bool P2_Frontend::handle_init(Z_GDU *z_gdu);
155 };
156
157 #endif
158 /*
159  * Local variables:
160  * c-basic-offset: 4
161  * indent-tabs-mode: nil
162  * End:
163  * vim: shiftwidth=4 tabstop=8 expandtab
164  */