[4] | 1 | /*************************************************************************************** |
---|
| 2 | * SAGE - Scalable Adaptive Graphics Environment |
---|
| 3 | * |
---|
| 4 | * Module: sageBlockPool.h |
---|
| 5 | * Author : Byungil Jeong |
---|
| 6 | * |
---|
| 7 | * Description: Pool (block group and block buffer) of sage pixel blocks |
---|
| 8 | * |
---|
| 9 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
| 10 | * University of Illinois at Chicago |
---|
| 11 | * |
---|
| 12 | * All rights reserved. |
---|
| 13 | * |
---|
| 14 | * Redistribution and use in source and binary forms, with or without |
---|
| 15 | * modification, are permitted provided that the following conditions are met: |
---|
| 16 | * |
---|
| 17 | * * Redistributions of source code must retain the above copyright |
---|
| 18 | * notice, this list of conditions and the following disclaimer. |
---|
| 19 | * * Redistributions in binary form must reproduce the above |
---|
| 20 | * copyright notice, this list of conditions and the following disclaimer |
---|
| 21 | * in the documentation and/or other materials provided with the distribution. |
---|
| 22 | * * Neither the name of the University of Illinois at Chicago nor |
---|
| 23 | * the names of its contributors may be used to endorse or promote |
---|
| 24 | * products derived from this software without specific prior written permission. |
---|
| 25 | * |
---|
| 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
| 29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
| 30 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
| 31 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
| 32 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
| 33 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
| 34 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
| 35 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
| 36 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 37 | * |
---|
| 38 | * Direct questions, comments etc about SAGE to sage_users@listserv.uic.edu or |
---|
| 39 | * http://www.evl.uic.edu/cavern/forum/ |
---|
| 40 | * |
---|
| 41 | *****************************************************************************************/ |
---|
| 42 | |
---|
| 43 | #ifndef _SAGE_BLOCK_POOL_H |
---|
| 44 | #define _SAGE_BLOCK_POOL_H |
---|
| 45 | |
---|
| 46 | #include "sageBuf.h" |
---|
| 47 | |
---|
| 48 | #define MAX_READER_NUM 100 |
---|
| 49 | |
---|
| 50 | class sagePixelBlock; |
---|
| 51 | class sageBlockGroup; |
---|
| 52 | |
---|
| 53 | /** |
---|
| 54 | * sageBlockPool |
---|
| 55 | */ |
---|
| 56 | class sageBlockPool { |
---|
| 57 | protected: |
---|
| 58 | bool memAlloc; |
---|
| 59 | |
---|
| 60 | public: |
---|
| 61 | sageBlockPool() {} |
---|
| 62 | virtual bool isFull() = 0; |
---|
| 63 | virtual bool pushBack(sagePixelBlock* block) = 0; |
---|
| 64 | virtual int returnBG(sageBlockGroup* grp) = 0; |
---|
| 65 | virtual int returnBlocks(sageBlockGroup* grp) = 0; |
---|
| 66 | virtual int returnBlock(sagePixelBlock* block) = 0; |
---|
| 67 | virtual bool garbageCollection() { return false; } |
---|
| 68 | }; |
---|
| 69 | |
---|
| 70 | // group options |
---|
| 71 | #define GRP_MEM_ALLOC 1 |
---|
| 72 | #define GRP_CIRCULAR 2 |
---|
| 73 | #define GRP_MULTI_READER 4 |
---|
| 74 | #define GRP_USE_IOV 8 |
---|
| 75 | |
---|
| 76 | #define GROUP_HEADER_SIZE 32 |
---|
| 77 | |
---|
| 78 | /** |
---|
| 79 | * class sageBlockGroup can have many sageBlock objects |
---|
| 80 | */ |
---|
| 81 | class sageBlockGroup : public sageBlockPool { |
---|
| 82 | protected: |
---|
| 83 | sageBuf *buf; |
---|
| 84 | int flag; |
---|
| 85 | int blockSize, frameSize; |
---|
| 86 | int frameID; |
---|
| 87 | int configID; |
---|
| 88 | int refCnt; |
---|
| 89 | int deRefCnt; |
---|
| 90 | char header[GROUP_HEADER_SIZE]; |
---|
| 91 | |
---|
| 92 | int blockNum; |
---|
| 93 | |
---|
| 94 | #ifdef WIN32 |
---|
| 95 | WSABUF *iovs; |
---|
| 96 | #else |
---|
| 97 | struct iovec *iovs; |
---|
| 98 | #endif |
---|
| 99 | |
---|
| 100 | public: |
---|
| 101 | static const int PIXEL_DATA; |
---|
| 102 | static const int CONFIG_UPDATE; |
---|
| 103 | static const int END_FRAME; |
---|
| 104 | |
---|
| 105 | sageBlockGroup() : buf(NULL), iovs(NULL), frameID(0), flag(sageBlockGroup::END_FRAME), |
---|
| 106 | blockNum(0), refCnt(0), deRefCnt(0), frameSize(0) {} |
---|
| 107 | sageBlockGroup(int blkSize, int grpSize, char opt); |
---|
| 108 | bool pushBack(sagePixelBlock* block); |
---|
| 109 | sagePixelBlock* front(); |
---|
| 110 | bool next(); |
---|
| 111 | void resetGrp(); |
---|
| 112 | void resetIdx(); |
---|
| 113 | bool isEmpty(); |
---|
| 114 | |
---|
| 115 | bool isFull(); |
---|
| 116 | int returnBG(sageBlockGroup* grp) { return returnBlocks(grp); } |
---|
| 117 | int returnBlocks(sageBlockGroup* grp); |
---|
| 118 | int returnBlock(sagePixelBlock *block); |
---|
| 119 | |
---|
| 120 | int size(); |
---|
| 121 | int getBlockNum(); |
---|
| 122 | sagePixelBlock* operator[] (int idx); |
---|
| 123 | |
---|
| 124 | inline int getDataSize() { return blockSize*getBlockNum(); } |
---|
| 125 | inline int getFlag() { return flag; } |
---|
| 126 | inline void setFlag(int f) { flag = f; } |
---|
| 127 | inline int getConfigID() { return configID; } |
---|
| 128 | inline void setConfigID(int id) { configID = id; } |
---|
| 129 | inline int getFrameID() { return frameID; } |
---|
| 130 | inline void setFrameID(int id) { frameID = id; } |
---|
| 131 | inline void reference(int cnt) { refCnt += cnt; } |
---|
| 132 | inline int dereference() { deRefCnt++; return (refCnt - deRefCnt); } |
---|
| 133 | inline int getRefCnt() { return (refCnt - deRefCnt); } |
---|
| 134 | inline void setFrameSize(int size) { frameSize = size; } |
---|
| 135 | inline int getFrameSize() { return frameSize; } |
---|
| 136 | |
---|
| 137 | void clearBlocks(); |
---|
| 138 | bool updateConfig(); |
---|
| 139 | bool updateConfig(int num, int frame, int config); |
---|
| 140 | bool genIOV(); |
---|
| 141 | bool setRefCnt(); |
---|
| 142 | |
---|
| 143 | //bool dereferenceAll(); |
---|
| 144 | int sendData(int sockFd); |
---|
| 145 | int readData(int sockFd); |
---|
| 146 | int sendDatagram(int sockFd); |
---|
| 147 | int readDatagram(int sockFd); |
---|
| 148 | void clear(); |
---|
| 149 | ~sageBlockGroup(); |
---|
| 150 | }; |
---|
| 151 | |
---|
| 152 | // buffer options |
---|
| 153 | #define BUF_MEM_ALLOC 1 |
---|
| 154 | #define BUF_MULTI_READER 2 |
---|
| 155 | #define BUF_BLOCKING_READ 4 |
---|
| 156 | #define BUF_CTRL_GROUP 8 |
---|
| 157 | #define INTERVAL_EVAL_COUNT 100 |
---|
| 158 | |
---|
| 159 | /** |
---|
| 160 | * sageBlockBuf can have many sageBlockGroup |
---|
| 161 | */ |
---|
| 162 | class sageBlockBuf : public sageBlockPool { |
---|
| 163 | protected: |
---|
| 164 | sageBuf *buf; |
---|
| 165 | sageCircBufSingle *dataPool; |
---|
| 166 | sageRAB *vacantPool; |
---|
| 167 | sageCircBufSingle *ctrlPool; |
---|
| 168 | bool waitingData; |
---|
| 169 | bool multiReader; |
---|
| 170 | double frameInterval; |
---|
| 171 | |
---|
| 172 | sageTimer frameTimer; |
---|
| 173 | sageCounter frameCounter; |
---|
| 174 | bool firstGroup; |
---|
| 175 | |
---|
| 176 | int findNextFrame(int id); |
---|
| 177 | |
---|
| 178 | public: |
---|
| 179 | sageBlockBuf(int bufSize, int grpSize, int blkSize, char opt); |
---|
| 180 | int entryNum() { return buf->getEntryNum(); } |
---|
| 181 | sageBlockGroup* getFreeBlocks(); |
---|
| 182 | sageBlockGroup* getCtrlGroup(int flag); |
---|
| 183 | sageBlockGroup* front(int id = 0, int minFrame = 0); |
---|
| 184 | bool next(int id = 0); |
---|
| 185 | inline bool isEmpty() { return buf->isEmpty(); } |
---|
| 186 | bool pushBack(sageBlockGroup* grp); |
---|
| 187 | bool pushBack(sagePixelBlock* block) { return false; }; |
---|
| 188 | |
---|
| 189 | bool finishFrame(); |
---|
| 190 | int returnBG(sageBlockGroup* grp); |
---|
| 191 | int returnBlocks(sageBlockGroup* grp); |
---|
| 192 | int returnBlock(sagePixelBlock *block); |
---|
| 193 | |
---|
| 194 | bool isFull() { return false; } |
---|
| 195 | void getBufInfo(char *bufStatus); |
---|
| 196 | |
---|
| 197 | inline bool isWaitingData() { return waitingData; } |
---|
| 198 | |
---|
| 199 | int addReader(int id); |
---|
| 200 | inline void removeReader(int id) { ((sageCircBufMulti *)buf)->removeReader(id); } |
---|
| 201 | bool clear(sageBuf *groupBuf); |
---|
| 202 | void releaseLock(); |
---|
| 203 | |
---|
| 204 | double getFrameInterval() { return frameInterval; } |
---|
| 205 | |
---|
| 206 | ~sageBlockBuf(); |
---|
| 207 | }; |
---|
| 208 | |
---|
| 209 | #endif |
---|