1 /* 2 * Copyright (C) 2012 A. Pic 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifdef HAVE_CONFIG_H 19 #include <config.h> 20 #endif 21 22 #include "visa.h" 23 #include "object_cache.h" 24 #include "session.h" 25 26 using namespace librevisa; 27 viSetBuf(ViSession vi,ViUInt16 mask,ViUInt32 size)28ViStatus _VI_FUNC viSetBuf(ViSession vi, ViUInt16 mask, ViUInt32 size) 29 { 30 try 31 { 32 if(!(mask & VI_READ_BUF) && !(mask & VI_WRITE_BUF) && 33 !(mask & VI_IO_IN_BUF) && !(mask & VI_IO_OUT_BUF)) 34 return VI_WARN_NSUP_BUF; 35 36 /// @todo viFlush(vi, mask); 37 38 session *s = objects.get_session(vi); 39 40 /// @todo return VI_ERROR_INV_SESSION if session object invalid 41 /// @todo return VI_ERROR_RSRC_LOCKED if object locked 42 43 if(mask & VI_READ_BUF) { 44 if(s->GetFmtReadBufSiz()) 45 delete[](s->GetFmtReadBuf()); 46 s->SetFmtReadBuf(new ViByte[size]); 47 s->SetFmtReadBufSiz(size); 48 s->SetFmtReadBufCnt(0); 49 } 50 if(mask & VI_WRITE_BUF) { 51 if(s->GetFmtWriteBufSiz()) 52 delete[](s->GetFmtWriteBuf()); 53 s->SetFmtWriteBuf(new ViByte[size]); 54 s->SetFmtWriteBufSiz(size); 55 s->SetFmtWriteBufCnt(0); 56 } 57 if(mask & VI_IO_IN_BUF) { 58 if(s->GetIOInBufSiz()) 59 delete[](s->GetIOInBuf()); 60 s->SetIOInBuf(new ViByte[size]); 61 s->SetIOInBufSiz(size); 62 s->SetIOInBufCnt(0); 63 } 64 if(mask & VI_IO_OUT_BUF) { 65 if(s->GetIOOutBufSiz()) 66 delete[](s->GetIOOutBuf()); 67 s->SetIOOutBuf(new ViByte[size]); 68 s->SetIOOutBufSiz(size); 69 s->SetIOOutBufCnt(0); 70 } 71 return VI_SUCCESS; 72 } 73 catch(std::bad_alloc &) 74 { 75 return VI_ERROR_ALLOC; 76 } 77 catch(exception &e) 78 { 79 return e.code; 80 } 81 } 82