1 /*
2  * Copyright (C) 2012 Simon Richter
3  * Copyright (C) 2012 A. Pic
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef librevisa_session_h_
20 #define librevisa_session_h_ 1
21 
22 #include "exception.h"
23 #include "object.h"
24 #include "resource.h"
25 #include "event_queue.h"
26 
27 namespace librevisa {
28 
29 class session :
30         public object
31 {
32 public:
33         session(resource *);
34 
throw()35         ~session() throw() { }
36 
37         ViStatus Close();
38         ViStatus Lock(ViAccessMode, ViUInt32, ViKeyId, ViKeyId);
39         ViStatus Unlock();
40         ViStatus GetAttribute(ViAttr, void *);
41         ViStatus SetAttribute(ViAttr, ViAttrState);
42 
43         ViStatus Open(ViRsrc, ViAccessMode, ViUInt32, ViSession *);
44         ViStatus FindRsrc(ViString expr, ViFindList *findList, ViUInt32 *retCount, ViRsrc instrDesc);
45 
46         ViStatus Read(ViBuf, ViUInt32, ViUInt32 *);
47         ViStatus Write(ViBuf, ViUInt32, ViUInt32 *);
48         ViStatus ReadSTB(ViUInt16 *);
49 
50         ViStatus EnableEvent(ViEventType eventType, ViUInt16 mechanism, ViEventFilter context);
51         ViStatus DisableEvent(ViEventType eventType, ViUInt16 mechanism);
52 
53         ViStatus WaitOnEvent(ViEventType inEventType, ViUInt32 timeout, ViPEventType outEventType, ViPEvent outContext);
54 
GetFmtReadBufSiz()55         ViUInt32 GetFmtReadBufSiz() { return fmt_read_buf.size; }
SetFmtReadBufSiz(ViUInt32 i)56         void SetFmtReadBufSiz(ViUInt32 i) { fmt_read_buf.size = i; }
GetFmtReadBufCnt()57         ViUInt32 GetFmtReadBufCnt() { return fmt_read_buf.count; }
SetFmtReadBufCnt(ViUInt32 i)58         void SetFmtReadBufCnt(ViUInt32 i) { fmt_read_buf.count = i; }
GetFmtReadBuf()59         ViAByte GetFmtReadBuf() { return fmt_read_buf.buf; }
SetFmtReadBuf(ViAByte a)60         void SetFmtReadBuf(ViAByte a) { fmt_read_buf.buf = a; }
61 
GetFmtWriteBufSiz()62         ViUInt32 GetFmtWriteBufSiz() { return fmt_write_buf.size; }
SetFmtWriteBufSiz(ViUInt32 i)63         void SetFmtWriteBufSiz(ViUInt32 i) { fmt_write_buf.size = i; }
GetFmtWriteBufCnt()64         ViUInt32 GetFmtWriteBufCnt() { return fmt_write_buf.count; }
SetFmtWriteBufCnt(ViUInt32 i)65         void SetFmtWriteBufCnt(ViUInt32 i) { fmt_write_buf.count = i; }
GetFmtWriteBuf()66         ViAByte GetFmtWriteBuf() { return fmt_write_buf.buf; }
SetFmtWriteBuf(ViAByte a)67         void SetFmtWriteBuf(ViAByte a) { fmt_write_buf.buf = a; }
68 
GetIOInBufSiz()69         ViUInt32 GetIOInBufSiz() { return io_in_buf.size; }
SetIOInBufSiz(ViUInt32 i)70         void SetIOInBufSiz(ViUInt32 i) { io_in_buf.size = i; }
GetIOInBufCnt()71         ViUInt32 GetIOInBufCnt() { return io_in_buf.count; }
SetIOInBufCnt(ViUInt32 i)72         void SetIOInBufCnt(ViUInt32 i) { io_in_buf.count = i; }
GetIOInBuf()73         ViAByte GetIOInBuf() { return io_in_buf.buf; }
SetIOInBuf(ViAByte a)74         void SetIOInBuf(ViAByte a) { io_in_buf.buf = a; }
75 
GetIOOutBufSiz()76         ViUInt32 GetIOOutBufSiz() { return io_out_buf.size; }
SetIOOutBufSiz(ViUInt32 i)77         void SetIOOutBufSiz(ViUInt32 i) { io_out_buf.size = i; }
GetIOOutBufCnt()78         ViUInt32 GetIOOutBufCnt() { return io_out_buf.count; }
SetIOOutBufCnt(ViUInt32 i)79         void SetIOOutBufCnt(ViUInt32 i) { io_out_buf.count = i; }
GetIOOutBuf()80         ViAByte GetIOOutBuf() { return io_out_buf.buf; }
SetIOOutBuf(ViAByte a)81         void SetIOOutBuf(ViAByte a) { io_out_buf.buf = a; }
82 
83 private:
84         session(session const &);
85         session &operator=(session const &);
86 
87         resource *res;
88 
89         unsigned int exclusive_lock_count, shared_lock_count;
90 
91         struct buffer
92         {
bufferbuffer93                 buffer() : size(0), count(0), buf(0) { }
94 
95                 ViUInt32 size;
96                 ViUInt32 count;
97                 ViAByte buf;
98         };
99 
100         buffer fmt_read_buf;
101         buffer fmt_write_buf;
102         buffer io_in_buf;
103         buffer io_out_buf;
104 
105         event_queue queue;
106 
107         static unsigned int const num_supported_events = 15;
108         static ViEventType supported_events[num_supported_events];
109 
110         bool queue_enabled[num_supported_events];
111 
112         static unsigned int lookup_event(ViEventType);
113 };
114 
115 }
116 
117 #endif
118