Scheduler.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 
00031 
00032 
00036 
00037 
00039 /* @{ */
00040 
00041 
00042 #ifndef __SCHEDULER_H_
00043 #define __SCHEDULER_H_
00044 
00045 #include <FifoTerm.h>
00046 #include <LogTrace.h>
00047 #include <Task.h>
00048 #include <TaskFactory.h>
00049 #include <Resource.h>
00050 #include <ResourceFactory.h>
00051 #include <dlfcn.h>
00052 
00053 using namespace MipTasks;
00054 
00055 class SchedulerStatus{
00056  public:
00057   bool isScheduling;
00058   Decimal frequency;
00059   
00060   SchedulerStatus(){
00061    isScheduling = false;
00062    frequency = 0.0;
00063   }
00064 };
00065 
00070 class Scheduler: public MIPObject{
00071  private:
00072   TasksPointers   _scheduledTasks;   
00073   ResourcePointers _scheduledResources; 
00075   TasksPPointers  _tasksUnloadList;   
00076   ResourcePPointers _resourcesUnloadList; 
00078   int argc;
00079   const char** argv;
00080   
00081   vector<destroy_task*> pluginTaskDestroyers;
00082   vector<destroy_resource*> pluginResourceDestroyers;
00083   
00085   bool checkResPlate(ResourcePlate plate,Resource* resource);
00086   
00088   template <class ResourceType> void resourceLoader(ResourcePlate plate){
00089    Resource* resource = new ResourceType(argc,argv);/* polymorph */
00090     checkResPlate(plate,resource); /* check its plate */
00091    stringstream ss;
00092    ss << "Loaded resource " << ResourceNames[resource->getPlate()] << " ("<< (long int) resource << ")";
00093    debug(1,ss.str());
00094    _scheduledResources.push_back(resource);
00095    _resourcesUnloadList.push_back(&resource);
00096    
00097   }
00098 
00100   template <class ResourceType> void resourceUnloader(Resource* resource){
00101    ResourceType* realResource = (ResourceType*) resource;
00102    stringstream ss;
00103    ss << "Deleting resource " << ResourceNames[resource->getPlate()] << " ("<< (long int) resource << ")";
00104    debug(1,ss.str());
00105    delete realResource;
00106   }
00107   
00109   void resourcePluginLoader(string &resourceName, string &libraryName);
00110   
00112   bool checkTaskPlate(TaskPlate plate,Task* task);
00113   
00115   template <class TaskType> void taskLoader(TaskPlate plate){
00116    Task* task = new TaskType(_scheduledResources,argc,argv);
00117    checkTaskPlate(plate,task);
00118    stringstream ss;
00119    ss << "Loaded task " << TaskNames[task->getPlate()];
00120    debug(1,ss.str());
00121    _scheduledTasks.push_back(task); /*polymorph */
00122    _tasksUnloadList.push_back(&task);
00123   }
00124   
00125   void newtaskLoaderKbHitTask();
00126   
00127   
00129   void taskPluginLoader(string &taskName, string &libraryName);
00130   
00132   template <class TaskType> void taskUnloader(Task* task){
00133     TaskType* realTask = (TaskType*) task;
00134    stringstream ss;
00135    ss << "Deleting task " << TaskNames[task->getPlate()]; 
00136    debug(1,ss.str());
00137     delete realTask;
00138   }
00139   
00141   void loadResources(const ResourcePlates& resourcePlates);
00143   void unloadResources();
00145   void loadPluginResources(vector<string> &plResourceNames, vector<string> &plResourceLibs);
00147   void unloadPluginResources();
00149   void loadTasks(const TaskPlates& taskPlates);
00151   void unloadTasks();
00153   void loadTasksPlugins(vector<string> &plTaskNames, vector<string> &plTaskLibs);
00155   void unloadPluginTasks();
00156   
00157   
00159   string getObjectName() const;
00160   
00161  public:
00162   SchedulerStatus status;
00163   
00165   Scheduler(const ResourcePlates& resourcePlates,const TaskPlates& taskPlates, vector<string> &plResourceNames, vector<string> &plResourceLibs, vector<string> &plTaskNames, vector<string> &plTaskLibs, int pargc, const char* pargv[]);
00166   
00168   ~Scheduler();
00169   
00171   void schedule(unsigned long int cycles,Time minCycleDuration);
00172   
00173   bool getResourcePointers(ResourcePointers &rp);
00174 };
00175 
00176 #endif
00177 
00178 /* @} */
00179 
00180 

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