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