DraWin.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno    
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
00023 //
00024 // ----------------------------------------------------------------------------
00025 
00026 
00032 
00033 #ifndef __DRA_WIN_H_
00034 #define __DRA_WIN_H_
00035 
00036 #ifdef MIP_HOST_APPLE
00037 #include <applePatch.h>
00038 #endif
00039 
00040 #include <assert.h>
00041 
00042 #include <Thread.h>
00043 #include "Resource.h"
00044 #include "DraWinObj.h"
00045 
00046 
00075 
00076 using namespace std;
00077 using namespace MipBaselib;
00078 
00079 namespace MipResources{
00081  /* @{ */
00082 
00083 
00086 class DraWinVar{
00087  private:
00088   static const unsigned int DRA_WIN_DEFAULT_WIDTH  = 300;
00089   static const unsigned int DRA_WIN_DEFAULT_HEIGHT = 300;
00090  public:
00091   unsigned int _width; 
00092   unsigned int _height; 
00093   DraWinBoundBox BB;
00094 
00095   DraWinVar(){
00096    _width = DRA_WIN_DEFAULT_WIDTH;
00097    _height = DRA_WIN_DEFAULT_HEIGHT;
00098   }
00099 };
00100 
00104 class DraWin  : public Resource{
00105 
00106  private:
00107   static const unsigned int DRA_WIN_RES_LIST_SIZE=5000;
00108   pthread_mutex_t _listsMutEx;  
00109  protected:
00111   vector<DraWinList*>   _draWinLists;
00113   vector<DraWinList*>   _draWinListsA;
00115   vector<DraWinList*>   _draWinListsB;
00116   
00117   vector<unsigned int>  _indexA;
00118   vector<unsigned int>  _indexB;
00119   
00123   int _listsTrylock() {
00124    return pthread_mutex_trylock(&_listsMutEx);
00125   }
00126   
00130   int _listsUnlock(){
00131    return pthread_mutex_unlock(&_listsMutEx);
00132   }
00133 
00134 //  DraWinVar    _draWinVar;     ///< DraWin parameters
00135  public:
00136   DraWinVar    _draWinVar;     
00137 
00140   DraWin(){
00141    
00142    
00143    /*list of lists mutex init*/
00144    pthread_mutex_init(&_listsMutEx,NULL);
00145    /* first bank for the default list creation */
00146    DraWinList* _defaultDWListA = new DraWinList();
00147    _draWinListsA.push_back(_defaultDWListA);
00148    /* second bank for the default list  creation */
00149    DraWinList* _defaultDWListB = new DraWinList();
00150    _draWinListsB.push_back(_defaultDWListB);
00151    
00152    _draWinLists.push_back(_defaultDWListA);
00153   }
00154   
00156   ~DraWin(){
00157    unsigned int listNum = _draWinLists.size();
00158    for(unsigned int i=0;i<listNum;i++){
00159     clearList(Time(10,0),i);/*sufficienti 10 secs?*/
00160     delete _draWinLists[i];
00161    }
00162   }
00163   
00166   virtual ResourcePlate getPlate() const =0;
00167   
00173   bool addList(Time timeout,unsigned int& listNum);
00174 
00179   bool swapList(Time timeout,unsigned int listNum);
00180   
00189   bool pushObj(DraWinObj* draWinObj,Time timeout,unsigned int listNum=0);
00190   
00201   bool overlapObj(DraWinObj* draWinObj,Time timeout,unsigned int listNum=0);
00202   
00208   bool clearList(Time timeout,unsigned int listNum){
00209    return swapList(timeout,listNum);
00210   }
00211   
00217   bool accuList(Time timeout,unsigned int listNum){
00218    return swapList(timeout,listNum);
00219   }
00220 };
00221 
00225 
00226 
00227 /* @} */
00228 
00229 };// end namespace MipResources{
00230 
00231 
00232 #endif
00233 
00234 
00235 
00236 
00237 

Generated on Mon Feb 20 07:01:07 2017 for MIP by  doxygen 1.5.6