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