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