Added object Yaz_Z_Assoc. Much more functional client.
[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.4  1999-03-23 14:17:57  adam
8  * More work on timeout handling. Work on yaz-client.
9  *
10  * Revision 1.3  1999/02/02 14:01:13  adam
11  * First WIN32 port of YAZ++.
12  *
13  * Revision 1.2  1999/01/28 13:08:40  adam
14  * Yaz_PDU_Assoc better encapsulated. Memory leak fix in
15  * yaz-socket-manager.cc.
16  *
17  * Revision 1.1.1.1  1999/01/28 09:41:07  adam
18  * First implementation of YAZ++.
19  *
20  */
21
22 #include <comstack.h>
23 #include <yaz-socket-observer.h>
24 #include <yaz-pdu-observer.h>
25
26 /** Simple Protocol Data Unit Assocation.
27     This object sends - and receives PDU's using the COMSTACK
28     network utility. To use the association in client role, use
29     the method connect. The server role is initiated by using the
30     listen method.
31  */
32 class YAZ_EXPORT Yaz_PDU_Assoc : public IYaz_PDU_Observable, IYazSocketObserver {
33  private:
34     enum { Connecting, Connected, Listen, Ready, Closed } m_state;
35     class PDU_Queue {
36     public:
37         PDU_Queue(const char *buf, int len);
38         PDU_Queue::~PDU_Queue();
39         char *m_buf;
40         int m_len;
41         PDU_Queue *m_next;
42     };
43     Yaz_PDU_Assoc *m_parent;
44     Yaz_PDU_Assoc *m_children;
45     Yaz_PDU_Assoc *m_next;
46     COMSTACK Yaz_PDU_Assoc::comstack();
47     COMSTACK m_cs;
48     IYazSocketObservable *m_socketObservable;
49     IYaz_PDU_Observer *m_PDU_Observer;
50     char *m_input_buf;
51     int m_input_len;
52     PDU_Queue *m_queue_out;
53     int Yaz_PDU_Assoc::flush_PDU();
54     int *m_destroyed;
55     int m_idleTime;
56  public:
57     /// Create object using specified socketObservable
58     Yaz_PDU_Assoc(IYazSocketObservable *socketObservable, COMSTACK cs);
59     /// Close socket and destroy object.
60     virtual ~Yaz_PDU_Assoc();
61     /// Clone the object
62     IYaz_PDU_Observable *clone();
63     /// Send PDU
64     int send_PDU(const char *buf, int len);
65     /// connect to server (client role)
66     void connect(IYaz_PDU_Observer *observer, const char *addr);
67     /// listen for clients (server role)
68     void listen(IYaz_PDU_Observer *observer, const char *addr);
69     /// Socket notification
70     void socketNotify(int event);
71     /// Close socket
72     void close();
73     /// Close and destroy
74     void destroy();
75     /// Set Idle Time
76     void idleTime (int timeout);
77 };