Modified for new location of YAZ header files. Experimental threaded
[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  * $Id: yaz-pdu-assoc.h,v 1.7 1999-12-06 13:52:45 adam Exp $
7  */
8
9 #include <yaz/comstack.h>
10 #include <yaz-socket-observer.h>
11 #include <yaz-pdu-observer.h>
12
13 /** Simple Protocol Data Unit Assocation.
14     This object sends - and receives PDU's using the COMSTACK
15     network utility. To use the association in client role, use
16     the method connect. The server role is initiated by using the
17     listen method.
18  */
19 class YAZ_EXPORT Yaz_PDU_Assoc : public IYaz_PDU_Observable, IYazSocketObserver {
20  private:
21     enum { Connecting, Listen, Ready, Closed } m_state;
22     class PDU_Queue {
23     public:
24         PDU_Queue(const char *buf, int len);
25         PDU_Queue::~PDU_Queue();
26         char *m_buf;
27         int m_len;
28         PDU_Queue *m_next;
29     };
30     Yaz_PDU_Assoc *m_parent;
31     Yaz_PDU_Assoc *m_children;
32     Yaz_PDU_Assoc *m_next;
33     COMSTACK Yaz_PDU_Assoc::comstack();
34     COMSTACK m_cs;
35     IYazSocketObservable *m_socketObservable;
36     IYaz_PDU_Observer *m_PDU_Observer;
37     char *m_input_buf;
38     int m_input_len;
39     PDU_Queue *m_queue_out;
40     int Yaz_PDU_Assoc::flush_PDU();
41     int *m_destroyed;
42     int m_idleTime;
43     int m_log;
44  public:
45     /// Create object using specified socketObservable
46     Yaz_PDU_Assoc(IYazSocketObservable *socketObservable);
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     /// open with existing socket
58     void socket(IYaz_PDU_Observer *observer, int fd);
59     /// Socket notification
60     void socketNotify(int event);
61     /// Close socket
62     void close();
63     /// Close and destroy
64     void destroy();
65     /// Set Idle Time
66     void idleTime (int timeout);
67     /// Child start...
68     virtual void childNotify(int fd);
69 };