Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

TableDataStore.h

Go to the documentation of this file.
00001 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00002 #ifndef MediaTable_TableDataStore_h
00003 #define MediaTable_TableDataStore_h
00004 
00005 #include "TableDataView.h"
00006 #include "TableDataSource.h"
00007 
00008 #include "TableDataStoreListener.h"
00009 
00010 #include "Application/videolympics/VideolympicsClient.h"
00011 
00012 namespace Impala {
00013 namespace Application {
00014 namespace MediaTable {
00015 
00016 class TableDataStore
00017 {
00018 public:
00019         typedef
00020     std::map<std::string, TableDataView*>                  TableDataViewsMapType;
00021         
00022     typedef
00023     std::pair<TableDataSource*, TableDataViewsMapType> TableDataSourceViewsType;
00024         
00025     typedef
00026     std::map<std::string, TableDataSourceViewsType>        TableDataSourceMapType;
00027         
00028     static void Initialize()
00029     {
00030         if (sInstance)
00031         {
00032             ILOG_WARN("TableDataStore already initialized. Skipping.");
00033             return;
00034         }
00035         sInstance = new TableDataStore();
00036     }   
00037         
00038     static TableDataStore* GetInstance()
00039     {
00040         if (!sInstance)
00041         {
00042             Initialize();
00043         }
00044         return sInstance;
00045     }
00046         
00047     void AddTableDataSource(std::string name, TableDataSource* source)
00048     {
00049         mTableDataSources[name].first = source;
00050         source->SetQuid(mNextTableDataSourceId++);
00051         ILOG_DEBUG("Added TableDataSource: " << name);
00052             DoTableDataStoreAddedTableDataSourceEvent();
00053     }
00054 
00055     TableDataView* GetTableDataView(std::string sourceAndView)
00056     {
00057         std::string::size_type loc = sourceAndView.find(":", 0 );
00058         if(loc != std::string::npos)
00059         {
00060                 return GetTableDataView(sourceAndView.substr(0, loc),
00061                                                                         sourceAndView.substr(loc+1));
00062         }
00063         return 0;
00064     }
00065 
00066     TableDataView* GetTableDataView(std::string source, std::string view)
00067     {
00068         TableDataViewsMapType::iterator it;
00069 
00070         // Check if view already exists, otherwise return a new view
00071         it=mTableDataSources[source].second.find(view);
00072         if(it == mTableDataSources[source].second.end())
00073         {
00074                 mTableDataSources[source].second[view] =
00075                 new TableDataView(mTableDataSources[source].first);
00076             DoTableDataStoreAddedTableDataViewEvent();
00077         }
00078         return mTableDataSources[source].second[view];
00079     }
00080 
00081     Impala::Core::Array::Array2dVec3UInt8*
00082                 GetImageDataByQuid(unsigned long long quid)
00083     {
00084         TableDataSourceMapType::iterator it;
00085         for(it = mTableDataSources.begin(); it != mTableDataSources.end(); it++)
00086         {
00087                 // ToDo: This should be optimized! Now loops over all sources and all columns.
00088                 Impala::Core::Array::Array2dVec3UInt8* img;
00089                 img = it->second.first->GetImageDataByQuid(quid);
00090                 if(img)
00091                         return img;
00092         }
00093         return 0;
00094     }
00095 
00096     std::map<std::string, std::vector<std::string> >
00097     GetContents()
00098     {
00099         std::map<std::string, std::vector<std::string> > contents;
00100         TableDataSourceMapType::iterator it;
00101         for(it = mTableDataSources.begin(); it != mTableDataSources.end(); it++)
00102         {
00103                         contents[it->first]; // RvB: For what purpose is this?
00104                                                                  //  DO: Probably to make sure the vector exists before
00105                                                                  //              pushing back? Does it still work without?
00106             TableDataViewsMapType& secsec = it->second.second;
00107             TableDataViewsMapType::iterator itv;
00108                 for(itv = secsec.begin(); itv != secsec.end(); itv++)
00109                         contents[it->first].push_back(itv->first);
00110         }
00111         return contents;
00112     }
00113 
00114     int GetTableDataSourceCount()
00115     {
00116         return mTableDataSources.size();
00117     }
00118         
00119 #ifdef MEDIATABLE_VIDEOLYMPICS
00120         Application::Videolympics::VideolympicsClient* GetVideOlympicsClient() {
00121                 return mVideOlympicsClient;
00122         }
00123 #endif                  
00124 
00125     void Clear()
00126     {
00127         delete sInstance;
00128         sInstance = new TableDataStore();
00129     }
00130 
00131     /* table listeners ******************************/
00132     void AddTableDataStoreListener(TableDataStoreListener* l)
00133     {
00134         mStoreListeners.push_back(l);
00135     }
00136 
00137     void DoUpdateTableDataStoreEvent()
00138     {
00139         for (int i=0; i< mStoreListeners.size(); i++)
00140             if (mStoreListeners[i]->GetListenTableUpdates())
00141                 mStoreListeners[i]->UpdateTableDataStoreEvent();
00142     }
00143 
00144     void DoTableDataStoreAddedTableDataSourceEvent()
00145     {
00146         DoUpdateTableDataStoreEvent();
00147         for (int i=0; i< mStoreListeners.size(); i++)
00148             if (mStoreListeners[i]->GetListenTableUpdates())
00149                 mStoreListeners[i]->TableDataStoreAddedTableDataSourceEvent();
00150     }
00151 
00152     void DoTableDataStoreAddedTableDataViewEvent()
00153     {
00154         DoUpdateTableDataStoreEvent();
00155         for (int i=0; i< mStoreListeners.size(); i++)
00156             if (mStoreListeners[i]->GetListenTableUpdates())
00157                 mStoreListeners[i]->TableDataStoreAddedTableDataViewEvent();
00158     }
00159 
00160 private:
00161     TableDataStore() // constructor: private
00162     {
00163         Init();
00164     }
00165 
00166     ~TableDataStore() // destructor: private
00167     {
00168         TableDataSourceMapType::reverse_iterator it;
00169         for(it = mTableDataSources.rbegin(); it != mTableDataSources.rend(); it++)
00170         {
00171             TableDataViewsMapType& secsec = it->second.second;
00172             TableDataViewsMapType::iterator itv;
00173                 for(itv = secsec.begin(); itv != secsec.end(); itv++)
00174                         // Delete TableDataView
00175                         delete itv->second;
00176                 // Delete TableDataSource
00177                 delete it->second.first;
00178         }
00179     }
00180 
00181     // copy constructor: private
00182     TableDataStore(TableDataStore const&){};
00183 
00184     // assignment operator: private
00185     TableDataStore& operator=(TableDataStore const&){};
00186 
00187     void Init()
00188     {
00189         ILOG_DEBUG("Initializing TableDataStore");
00190         mNextTableDataSourceId = 1;
00191 #ifdef MEDIATABLE_VIDEOLYMPICS
00192                 InitVideOlympicsClient();
00193 #endif          
00194     }
00195 
00196 #ifdef MEDIATABLE_VIDEOLYMPICS
00197         void InitVideOlympicsClient()
00198         {
00199                 CmdOptions& options = CmdOptions::GetInstance();
00200                 // VideOlympics showcase event contest server connection
00201                 if (!options.GetString("videolympicsServer").empty())
00202                 {
00203                         ILOG_INFO("VideOlympics contest client: enabled.");
00204                         mVideOlympicsClient =
00205                         new Application::Videolympics::VideolympicsClient(
00206                                                                                                                           options.GetString("videolympicsServer"),
00207                                                                                                                           options.GetInt("videolympicsPort"),
00208                                                                                                                           options.GetInt("videolympicsTeam"));
00209                 }
00210                 else
00211                 {
00212                         mVideOlympicsClient = NULL;
00213                         ILOG_DEBUG("VideOlympics contest client: disabled.");
00214                 }
00215         }
00216 
00217         Application::Videolympics::VideolympicsClient *mVideOlympicsClient;
00218 #endif
00219         
00220     TableDataSourceMapType                                      mTableDataSources;
00221     int                                                                         mNextTableDataSourceId;
00222 
00223     std::vector<TableDataStoreListener*>        mStoreListeners;
00224 
00225     static TableDataStore*                  sInstance;
00226         
00227     ILOG_VAR_DEC;
00228 };
00229 
00230 TableDataStore* TableDataStore::sInstance = 0;
00231 
00232 ILOG_VAR_INIT(TableDataStore, Application.MediaTable);
00233 
00234 } // namespace MediaTable
00235 } // namespace Application
00236 } // namespace Impala
00237 #endif // TableDataStore_h

Generated on Fri Mar 19 09:30:35 2010 for ImpalaSrc by  doxygen 1.5.1