079a55f921adee0b7d19296ac6026f4453af88fe
[yazpp-moved-to-github.git] / include / yaz-pdu-assoc.h
1 /*
2  * Copyright (c) 1998-1999, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  * 
6  * $Log: yaz-pdu-assoc.h,v $
7  * Revision 1.1  1999-01-28 09:41:07  adam
8  * Initial revision
9  *
10  */
11
12 #include <comstack.h>
13 #include <yaz-socket-observer.h>
14 #include <yaz-pdu-observer.h>
15
16 /** Simple Protocol Data Unit Assocation.
17     This object sends - and receives PDU's using the COMSTACK
18     network utility. To use the association in client role, use
19     the method connect. The server role is initiated by using the
20     listen method.
21  */
22 class Yaz_PDU_Assoc : public IYaz_PDU_Observable, IYazSocketObserver {
23  private:
24     enum { Connecting, Connected, Listen, Ready, Closed } m_state;
25     class PDU_Queue {
26     public:
27         PDU_Queue(const char *buf, int len);
28         PDU_Queue::~PDU_Queue();
29         char *m_buf;
30         int m_len;
31         PDU_Queue *m_next;
32     };
33     Yaz_PDU_Assoc *m_parent;
34     Yaz_PDU_Assoc *m_children;
35     Yaz_PDU_Assoc *m_next;
36     COMSTACK Yaz_PDU_Assoc::comstack();
37     COMSTACK m_cs;
38     IYazSocketObservable *m_socketObservable;
39     IYaz_PDU_Observer *m_PDU_Observer;
40     char *m_input_buf;
41     int m_input_len;
42     PDU_Queue *m_queue_out;
43     int Yaz_PDU_Assoc::flush_PDU();
44  public:
45     /// Create object using specified socketObservable
46     Yaz_PDU_Assoc(IYazSocketObservable *socketObservable, COMSTACK cs);
47     /// Close socket and destroy object.
48     virtual ~Yaz_PDU_Assoc();
49     /// Clone the object
50     IYaz_PDU_Observable *clone();
51     /// Send PDU
52     int send_PDU(const char *buf, int len);
53     /// connect to server (client role)
54     void connect(IYaz_PDU_Observer *observer, const char *addr);
55     /// listen for clients (server role)
56     void listen(IYaz_PDU_Observer *observer, const char *addr);
57     /// Socket notification
58     void socketNotify(int event);
59     /// Close socket
60     void close();
61 };