Update for YAZ 3s new OID system
[yazpp-moved-to-github.git] / include / yazpp / pdu-assoc.h
1 /*
2  * Copyright (c) 1998-2005, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: pdu-assoc.h,v 1.1 2006-03-29 13:14:15 adam Exp $
6  */
7
8 #ifndef YAZ_PDU_ASSOC_INCLUDED
9 #define YAZ_PDU_ASSOC_INCLUDED
10
11 #include <yaz/comstack.h>
12 #include <yazpp/socket-observer.h>
13 #include <yazpp/pdu-observer.h>
14
15 namespace yazpp_1 {
16 /** Simple Protocol Data Unit Assocation.
17     This object sends - and receives PDU's using the COMSTACK
18     network utility. To use the association in client role, use
19     the method connect. The server role is initiated by using the
20     listen method.
21  */
22 class YAZ_EXPORT PDU_Assoc : public IPDU_Observable, yazpp_1::ISocketObserver {
23     friend class PDU_AssocThread;
24  private:
25     enum { 
26         Connecting,
27         Listen,
28         Ready,
29         Closed,
30         Writing,
31         Accepting
32     } m_state;
33     class PDU_Queue {
34     public:
35         PDU_Queue(const char *buf, int len);
36         ~PDU_Queue();
37         char *m_buf;
38         int m_len;
39         PDU_Queue *m_next;
40     };
41     PDU_Assoc *m_parent;
42     PDU_Assoc *m_children;
43     PDU_Assoc *m_next;
44     COMSTACK m_cs;
45     yazpp_1::ISocketObservable *m_socketObservable;
46     IPDU_Observer *m_PDU_Observer;
47     char *m_input_buf;
48     int m_input_len;
49     PDU_Queue *m_queue_out;
50     PDU_Queue *m_queue_in;
51     int flush_PDU();
52     int *m_destroyed;
53     int m_idleTime;
54     int m_log;
55     void init(yazpp_1::ISocketObservable *socketObservable);
56  public:
57     COMSTACK comstack(const char *type_and_host, void **vp);
58     /// Create object using specified socketObservable
59     PDU_Assoc(yazpp_1::ISocketObservable *socketObservable);
60     /// Create Object using existing comstack
61     PDU_Assoc(yazpp_1::ISocketObservable *socketObservable,
62                   COMSTACK cs);
63     /// Close socket and destroy object.
64     /// virtual ~PDU_Assoc();
65     /// Clone the object
66     IPDU_Observable *clone();
67     /// Send PDU
68     int send_PDU(const char *buf, int len);
69     /// connect to server (client role)
70     int connect(IPDU_Observer *observer, const char *addr);
71     /// listen for clients (server role)
72     int listen(IPDU_Observer *observer, const char *addr);
73     /// Socket notification
74     void socketNotify(int event);
75     /// Close socket
76     void close();
77     /// Close and destroy
78     void destroy();
79     /// Set Idle Time
80     void idleTime (int timeout);
81     /// Child start...
82     virtual void childNotify(COMSTACK cs);
83     const char *getpeername();
84 };
85
86 class YAZ_EXPORT PDU_AssocThread : public PDU_Assoc {
87  public:
88     PDU_AssocThread(yazpp_1::ISocketObservable *socketObservable);
89  private:
90     void childNotify(COMSTACK cs);
91
92 };
93 };
94
95 #endif
96
97 /*
98  * Local variables:
99  * c-basic-offset: 4
100  * indent-tabs-mode: nil
101  * End:
102  * vim: shiftwidth=4 tabstop=8 expandtab
103  */
104