00001 /* 00002 * Copyright (C) 2009, Edmundo Albuquerque de Souza e Silva. 00003 * 00004 * This file may be distributed under the terms of the Q Public License 00005 * as defined by Trolltech AS of Norway and appearing in the file 00006 * LICENSE.QPL included in the packaging of this file. 00007 * 00008 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING 00009 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00010 * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, 00011 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 00012 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00013 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 00014 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00015 * 00016 * Thanks: Jose Renato Santos 00017 * 00018 */ 00019 00020 /////////////////////////////////////////////////////////////////////////////// 00021 // request.h : Definition of request structure and request classes: 00022 // - CRequestQueue 00023 // - CRequestFreeList 00024 /////////////////////////////////////////////////////////////////////////////// 00025 00026 #ifndef __REQUEST_H_ 00027 #define __REQUEST_H_ 00028 00029 #include <rioqueue.h> 00030 #include <riofreelist.h> 00031 #include <buffer.h> 00032 00033 #include <vsitypesint.h> 00034 00035 const s32 RequestStatusFree = 0; 00036 const s32 RequestStatusAccepted = 1; 00037 const s32 RequestStatusWaitRead = 2; 00038 const s32 RequestStatusRead = 3; 00039 const s32 RequestStatusReadDone = 4; 00040 const s32 RequestStatusWaitSendCommand = 5; 00041 const s32 RequestStatusWaitSend = 6; 00042 const s32 RequestStatusSend = 7; 00043 const s32 RequestStatusSendDone = 8; 00044 00045 const s32 RequestStatusWaitReceive = 9; 00046 const s32 RequestStatusReceive = 10; 00047 const s32 RequestStatusReceiveDone = 11; 00048 const s32 RequestStatusWaitFlushCommand = 12; 00049 const s32 RequestStatusWaitWrite = 13; 00050 const s32 RequestStatusWrite = 14; 00051 const s32 RequestStatusWriteDone = 15; 00052 00053 struct StrRequest 00054 { 00055 StrRequest* Next; 00056 u16 Command; 00057 s32 Status; 00058 u32 Id; 00059 u32 ClientId; 00060 u32 RouterId; 00061 u32 IPaddress; 00062 u16 Port; 00063 u16 Disk; 00064 u64 Pos; 00065 u32 Size; 00066 char* Data; 00067 /*Modified by Bernardo(not send ack)*/ 00068 u16 StreamTraffic; 00069 // Modificacao usada pela implementacao do controle de fluxo. Um novo 00070 // campo para enviar a taxa de envio do video ao servidor de armazenamento. 00071 u32 VideoRate; 00072 private: 00073 friend class CRequestManager; 00074 StrBuffer* Buffer; 00075 }; 00076 00077 /////////////////////////////////////////////////////////////////////////////// 00078 class CRequestQueue 00079 { 00080 public: 00081 // CRequestQueue(); 00082 // ~CRequestQueue(); 00083 void Put(StrRequest *Request); // Put Tequest at end of queue 00084 StrRequest* Get() ; // Get first element of queue. 00085 // Block calling thread if none 00086 // available (Requires single 00087 // thread using Get() ) 00088 void Signal(); // If there is a thread waiting 00089 // for an element unblock thread 00090 // making Get() return NULL 00091 private: 00092 RioQueue m_Queue; 00093 }; 00094 00095 /////////////////////////////////////////////////////////////////////////////// 00096 class CRequestManager 00097 { 00098 public: 00099 CRequestManager(); 00100 ~CRequestManager(); 00101 int Initialize( const unsigned int nRequests, 00102 const unsigned int BufferSize); 00103 void Free(StrRequest* Request); // Return Request to free list 00104 StrRequest* New(); // Get new request structure from 00105 // free list if available, otherwise 00106 // return null 00107 StrRequest* Get(const u32 ReqId); // Get address of request structure 00108 // associated with a given request id 00109 private: 00110 unsigned int m_n; 00111 CRioFreeList m_FreeList; 00112 StrRequest* m_Request; 00113 CBufferManager m_BufferManager; 00114 }; 00115 00116 #endif // __STORAGESERVER_H_