Fix C++ compiles on newer GCC
[yazpp-moved-to-github.git] / include / yaz++ / pdu-assoc.h
1 /*
2  * Copyright (c) 1998-2003, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: pdu-assoc.h,v 1.3 2003-10-10 12:37:26 adam 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     friend class Yaz_PDU_AssocThread;
23  private:
24     enum { 
25         Connecting,
26         Listen,
27         Ready,
28         Closed,
29         Writing,
30         Accepting
31     } m_state;
32     class PDU_Queue {
33     public:
34         PDU_Queue(const char *buf, int len);
35         PDU_Queue::~PDU_Queue();
36         char *m_buf;
37         int m_len;
38         PDU_Queue *m_next;
39     };
40     Yaz_PDU_Assoc *m_parent;
41     Yaz_PDU_Assoc *m_children;
42     Yaz_PDU_Assoc *m_next;
43     COMSTACK m_cs;
44     IYazSocketObservable *m_socketObservable;
45     IYaz_PDU_Observer *m_PDU_Observer;
46     char *m_input_buf;
47     int m_input_len;
48     PDU_Queue *m_queue_out;
49     int Yaz_PDU_Assoc::flush_PDU();
50     int *m_destroyed;
51     int m_idleTime;
52     int m_log;
53     void init(IYazSocketObservable *socketObservable);
54  public:
55     COMSTACK comstack(const char *type_and_host, void **vp);
56     /// Create object using specified socketObservable
57     Yaz_PDU_Assoc(IYazSocketObservable *socketObservable);
58     /// Create Object using existing comstack
59     Yaz_PDU_Assoc(IYazSocketObservable *socketObservable,
60                   COMSTACK cs);
61     /// Close socket and destroy object.
62     /// virtual ~Yaz_PDU_Assoc();
63     /// Clone the object
64     IYaz_PDU_Observable *clone();
65     /// Send PDU
66     int send_PDU(const char *buf, int len);
67     /// connect to server (client role)
68     int connect(IYaz_PDU_Observer *observer, const char *addr);
69     /// listen for clients (server role)
70     void listen(IYaz_PDU_Observer *observer, const char *addr);
71     /// Socket notification
72     void socketNotify(int event);
73     /// Close socket
74     void close();
75     /// Close and destroy
76     void destroy();
77     /// Set Idle Time
78     void idleTime (int timeout);
79     /// Child start...
80     virtual void childNotify(COMSTACK cs);
81     const char *getpeername();
82 };
83
84 class YAZ_EXPORT Yaz_PDU_AssocThread : public Yaz_PDU_Assoc {
85  public:
86     Yaz_PDU_AssocThread(IYazSocketObservable *socketObservable);
87  private:
88     void childNotify(COMSTACK cs);
89
90 };
91 #endif
92