Common.h

Go to the documentation of this file.
00001 /** @file Common.h
00002 * @author Gabor Madl
00003 * @date Created 08/2005
00004 * @brief Common declarations used in DREAM.
00005 *
00006 *
00007 * =================================================================
00008 * DREAM License v2.0
00009 * 
00010 * DREAM - Distributed Real-time Embedded Analysis Method
00011 * http://dre.sourceforge.net.
00012 * Copyright (c) 2005-2007 Gabor Madl, All Rights Reserved.
00013 * 
00014 * This file is part of DREAM.
00015 * 
00016 * DREAM is free software; you can redistribute it and/or modify it
00017 * under the terms of the GNU General Public License version 2 as
00018 * published by the Free Software Foundation. No future versions of
00019 * the GPL license may be automatically applied to DREAM. It is in
00020 * the sole discretion of the copyright holder to determine whether
00021 * DREAM may be released under a different license or terms. There
00022 * are no restrictions on the use of DREAM for any purpose.
00023 * 
00024 * DREAM is distributed in the hope that it will be useful,
00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00027 * GNU General Public License for more details.
00028 * 
00029 * You should have received a copy of the GNU General Public License
00030 * along with this program; if not, write to the Free Software
00031 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00032 * MA 02110-1301, USA.
00033 * 
00034 * By submitting comments, suggestions, code, code snippets,
00035 * techniques (including that of usage), and algorithms, submitters
00036 * acknowledge that they have the right to do so, that any such
00037 * submissions are given freely and unreservedly, and that they
00038 * waive any claims to copyright or ownership. In addition,
00039 * submitters acknowledge that any such submission might become
00040 * part of the copyright maintained on the overall body of code,
00041 * which comprises DREAM. By making a submission, submitter agrees
00042 * to these terms. Furthermore, submitters acknowledge that the
00043 * incorporation or modification of such submissions is entirely
00044 * at the discretion of the moderators of the DREAM project.
00045 * 
00046 * DREAM links to the Libxml2 third party library. Please see 
00047 * COPYING-libxml for the copyright information of Libxml2.
00048 * =================================================================
00049 */
00050 
00051 #if (_MSC_VER >= 1400)                          // VC8+
00052 #pragma warning (disable:4996)          // Disable all deprecation warnings
00053 #endif 
00054 
00055 #if (_MSC_VER >= 1300)                          // VC7+
00056 #define snprintf _snprintf
00057 #endif 
00058 
00059 #ifndef DREAM_COMMON
00060 #define DREAM_COMMON
00061 
00062 /** Specifies verbose output */
00063 #define DREAM_VERBOSE
00064 
00065 /* Specifies extremely verbose output */
00066 // #define DREAM_VERBOSE2
00067 
00068 /** Enables the dynamic checking of events. If disabled, the model checking method is faster but inaccurate. 
00069 * The example/test/model_check_branching1 example tests this functionality.
00070 */
00071 #define DREAM_BRANCHING
00072 
00073 /** Enables the checking of race conditions (except between zero-time events). If disabled, the model checking method is faster but inaccurate.
00074 * The example/test/model_check_branching2 example tests this functionality and the DREAM_BRANCHING functionality as well.
00075 */
00076 #define DREAM_RACE_CONDITION
00077 
00078 /** Enables the checking of race conditions combinations. If disabled, the model checking method is faster but inaccurate.
00079 * The example/test/model_check_branching3 example tests this functionality, the DREAM_BRANCHING and DREAM_RACE_CONDITION functionalities.
00080 */
00081 #define DREAM_RACE_CONDITION_COMBINATION
00082 
00083 /* Enables the checking of race conditions between zero-time events as well. This turns the analysis slower and finds problems that are often
00084 * irrelevant in real systems (race conditions can be managed within a single CPU).
00085 */
00086 // #define DREAM_RACE_CONDITION_ZERO
00087 
00088 /* Disables error condition on non-executing tasks */
00089 // #define DREAM_NON_EXECUTING_TASKS
00090 
00091 /* Define the following if you encounter strange behavior and would like more extensive error checking (might slow down performance a little). */
00092 // #define DREAM_ENHANCED_EXCEPTION_CHECKING
00093 
00094 #include "../datastructures/AVLTree.h"
00095 #include "../datastructures/AVLTree.cpp"
00096 #include "../datastructures/LinkedList.h"
00097 #include "../datastructures/LinkedList.cpp"
00098 
00099 #include <iostream>
00100 #include <iomanip>
00101 #include <string>
00102 #include <vector>
00103 #include <map>
00104 #include <time.h>
00105 
00106 namespace DREAM
00107 {
00108 class Node;
00109 class Task;
00110 class Thread;
00111 class Scheduler;
00112 class QoSLevel;
00113 
00114 /** Unsigned int type definition.
00115 * Redefining the basic type allows easy portability to 8 or 16 bit machines. 
00116 */
00117 typedef unsigned int uint;
00118 typedef unsigned char uchar;
00119 #define char_size 32
00120 #define double_size 128
00121 #define maxuint 4294967295
00122 
00123 #ifdef DREAM_BRANCHING
00124 /** Enum type definition for best case, worst case, or a random value. */
00125 typedef enum context_enum {bestcase, worstcase, randomcase, branchingpoint, repeat} Context;
00126 #else
00127 typedef enum context_enum {bestcase, worstcase, randomcase, repeat} Context;
00128 #endif
00129 
00130 /** NODE_MAP type definition. */
00131 typedef std::map<std::string, DREAM::Node*> NODE_MAP;
00132 
00133 /** NODE_PAIR type definition. */
00134 typedef std::pair<std::string, DREAM::Node*> NODE_PAIR;
00135 
00136 /** TASK_MAP type definition. */
00137 typedef std::map<std::string, DREAM::Task*> TASK_MAP;
00138 
00139 /** TASK_PAIR type definition. */
00140 typedef std::pair<std::string, DREAM::Task*> TASK_PAIR;
00141 
00142 /** TASK_UINT_MAP type definition. */
00143 typedef std::map<uint, DREAM::Task*> TASK_UINT_MAP;
00144 
00145 /** TASK_UINT_PAIR type definition. */
00146 typedef std::pair<uint, DREAM::Task*> TASK_UINT_PAIR;
00147 
00148 /** THREAD_MAP type definition. */
00149 typedef std::map<uint, DREAM::Thread*> THREAD_MAP;
00150 
00151 /** THREAD_PAIR type definition. */
00152 typedef std::pair<uint, DREAM::Thread*> THREAD_PAIR;
00153 
00154 /** THREAD_STR_MAP type definition. Used in XML parser but not core. */
00155 typedef std::map<std::string, DREAM::Thread*> THREAD_STR_MAP;
00156 
00157 /** THREAD_STR_PAIR type definition. Used in XML parser but not core. */
00158 typedef std::pair<std::string, DREAM::Thread*> THREAD_STR_PAIR;
00159 
00160 /** SCHEDULER_MAP type definition. */
00161 typedef std::map<std::string, DREAM::Scheduler*> SCHEDULER_MAP;
00162 
00163 /** SCHEDULER_PAIR type definition. */
00164 typedef std::pair<std::string, DREAM::Scheduler*> SCHEDULER_PAIR;
00165 
00166 /** QOS_AVLTREE type definition. 
00167 * The AVLTree is sorted based on the QoSLevel speeds.
00168 */
00169 typedef DREAM::AVLTree<double, DREAM::QoSLevel*> QOS_AVLTREE;
00170 
00171 /** NODE_AVLTREE type definition. */
00172 typedef DREAM::AVLTree<std::string, DREAM::Node*> NODE_AVLTREE;
00173 
00174 /** TASK_AVLTREE type definition. */
00175 typedef DREAM::AVLTree<std::string, DREAM::Task*> TASK_AVLTREE;
00176 
00177 /** TASK_AVLTREE_LIST type definition. */
00178 typedef DREAM::LinkedList<DREAM::TASK_AVLTREE*> TASK_AVLTREE_LIST;
00179 
00180 /** TASK_ID_LIST type definition. */
00181 typedef DREAM::LinkedList<std::string> TASK_ID_LIST;
00182 
00183 /** Randomize function with a value between 0 and the parameter size. */
00184 double random (uint size);
00185 
00186 /** Operator overloading for appending std::string to std:string. */
00187 std::string& operator<< (std::string& out, const std::string& parameter)
00188 #ifdef DREAM_ENHANCED_EXCEPTION_CHECKING
00189         throw (std::bad_exception)
00190 #endif
00191         ;
00192 
00193 /** Operator overloading for appending std::string to std:string. */
00194 std::string& operator<< (std::string& out, const char *)
00195 #ifdef DREAM_ENHANCED_EXCEPTION_CHECKING
00196         throw (std::bad_exception)
00197 #endif
00198         ;
00199 
00200 /** Operator overloading for appending uint to std:string. */
00201 std::string& operator<< (std::string& out, uint parameter)
00202 #ifdef DREAM_ENHANCED_EXCEPTION_CHECKING
00203         throw (std::bad_exception)
00204 #endif
00205         ;
00206 
00207 /** Operator overloading for appending double to std:string. */
00208 std::string& operator<< (std::string& out, double parameter)
00209 #ifdef DREAM_ENHANCED_EXCEPTION_CHECKING
00210         throw (std::bad_exception)
00211 #endif
00212         ;
00213 
00214 /** struct to be used in std::for_each to clear elements from vectors. */
00215 struct clear_vector
00216 {
00217         template <typename T> inline
00218         void operator () (T& object)
00219         {
00220                 object.clear ();
00221         }
00222 };
00223 
00224 /** struct to be used in std::for_each to delete elements from vectors. */
00225 struct delete_item
00226 {
00227         template <typename T> inline
00228         void operator () (T* object)
00229         {
00230                 delete object->item ();
00231         }
00232 };
00233 
00234 /** struct to be used in std::for_each to delete elements from vectors. */
00235 struct delete_object
00236 {
00237         template <typename T> inline
00238         void operator () (T* object)
00239         {
00240                 delete object;
00241         }
00242 };
00243 
00244 /** struct to be used in std::for_each to call consume () on std::pair->second. */
00245 struct consume_pair
00246 {
00247         template <typename T> inline
00248         void operator () (T& object)
00249         {
00250                 object.second->consume ();
00251         }
00252 };
00253 
00254 /** struct to be used in std::for_each to delete std::pairs. */
00255 struct delete_pair
00256 {
00257         template <typename T> inline
00258         void operator () (T& object)
00259         {
00260                 delete object.second;
00261         }
00262 };
00263 
00264 /** struct to be used in std::for_each to call reset () on std::pair->second. */
00265 struct reset_pair
00266 {
00267         template <typename T> inline
00268         void operator () (T& object)
00269         {
00270                 object.second->reset ();
00271         }
00272 };
00273 
00274 /* struct to be used in std::for_each to call schedule () on std::pair->second. */
00275 /*struct schedule_pair
00276 {
00277         template <typename T> inline
00278         void operator () (T& object)
00279         {
00280                 object.second->schedule ();
00281         }
00282 };
00283 */
00284 /** struct to be used in std::for_each to call stop () on std::pair->second. */
00285 struct stop_pair
00286 {
00287         template <typename T> inline
00288         void operator () (T& object)
00289         {
00290                 object.second->stop ();
00291         }
00292 };
00293 
00294 /** struct to be used in std::for_each to call take_transitions () on std::pair->second. */
00295 struct transition_pair
00296 {
00297         template <typename T> inline
00298         void operator () (T& object)
00299         {
00300                 object.second->take_transitions ();
00301         }
00302 };
00303 
00304 };
00305 
00306 /** Global options */
00307 struct Option
00308 {
00309         /** Specifies the number of repetitions for genetic algorithms */
00310         static DREAM::uint number_of_repetitions_;
00311 
00312         /** Specifies the size of the optimization space used in genetic algorithms */
00313         static DREAM::uint optimization_space_;
00314 
00315         /** Specifies the simulation time for all simulation-base methods */
00316         static DREAM::uint simulation_time_;
00317 
00318         /** Specifies whether branching is checked during model checking */
00319         static bool branching_;
00320 
00321         /** Specifies whether race conditions are checked during model checking */
00322         static bool race_condition_;
00323 
00324         /** Specifies whether race condition combinations are checked during model checking */
00325         static bool race_condition_combination_;
00326 
00327         /** Specifies whether race conditions between zero time events are checked during model checking */
00328         static bool race_condition_zero_;
00329 
00330         /** Specifies whether race conditions between zero time events are checked during model checking */
00331         static bool non_executing_tasks_;
00332 
00333         /** Specifies whether verbose output is enabled. */
00334         static bool verbose1_;
00335 
00336 #ifdef DREAM_VERBOSE2
00337         /** Specifies whether even more verbose output is enabled. */
00338         static bool verbose2_;
00339 #endif
00340 };
00341 
00342 #endif

Generated on Fri Jul 27 18:30:03 2007 for DREAM by  doxygen 1.5.1