Added skeleton of yaz-z-server.
[yazpp-moved-to-github.git] / include / yaz-pdu-assoc.h
1 /*
2  * Copyright (c) 1998-2000, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: yaz-pdu-assoc.h,v 1.8 2000-09-08 10:23:42 adam Exp $
6  */
7
8 #include <yaz/comstack.h>
9 #include <yaz-socket-observer.h>
10 #include <yaz-pdu-observer.h>
11
12 /** Simple Protocol Data Unit Assocation.
13     This object sends - and receives PDU's using the COMSTACK
14     network utility. To use the association in client role, use
15     the method connect. The server role is initiated by using the
16     listen method.
17  */
18 class YAZ_EXPORT Yaz_PDU_Assoc : public IYaz_PDU_Observable, IYazSocketObserver {
19  private:
20     enum { Connecting, Listen, Ready, Closed } m_state;
21     class PDU_Queue {
22     public:
23         PDU_Queue(const char *buf, int len);
24         PDU_Queue::~PDU_Queue();
25         char *m_buf;
26         int m_len;
27         PDU_Queue *m_next;
28     };
29     Yaz_PDU_Assoc *m_parent;
30     Yaz_PDU_Assoc *m_children;
31     Yaz_PDU_Assoc *m_next;
32     COMSTACK Yaz_PDU_Assoc::comstack();
33     COMSTACK m_cs;
34     IYazSocketObservable *m_socketObservable;
35     IYaz_PDU_Observer *m_PDU_Observer;
36     char *m_input_buf;
37     int m_input_len;
38     PDU_Queue *m_queue_out;
39     int Yaz_PDU_Assoc::flush_PDU();
40     int *m_destroyed;
41     int m_idleTime;
42     int m_log;
43  public:
44     /// Create object using specified socketObservable
45     Yaz_PDU_Assoc(IYazSocketObservable *socketObservable);
46     /// Close socket and destroy object.
47     virtual ~Yaz_PDU_Assoc();
48     /// Clone the object
49     IYaz_PDU_Observable *clone();
50     /// Send PDU
51     int send_PDU(const char *buf, int len);
52     /// connect to server (client role)
53     void connect(IYaz_PDU_Observer *observer, const char *addr);
54     /// listen for clients (server role)
55     void listen(IYaz_PDU_Observer *observer, const char *addr);
56     /// open with existing socket
57     void socket(IYaz_PDU_Observer *observer, int fd);
58     /// Socket notification
59     void socketNotify(int event);
60     /// Close socket
61     void close();
62     /// Close and destroy
63     void destroy();
64     /// Set Idle Time
65     void idleTime (int timeout);
66     /// Child start...
67     virtual void childNotify(int fd);
68 };