Wiselib
|
00001 /*************************************************************************** 00002 ** This file is part of the generic algorithm library Wiselib. ** 00003 ** Copyright (C) 2008,2009 by the Wisebed (www.wisebed.eu) project. ** 00004 ** ** 00005 ** The Wiselib is free software: you can redistribute it and/or modify ** 00006 ** it under the terms of the GNU Lesser General Public License as ** 00007 ** published by the Free Software Foundation, either version 3 of the ** 00008 ** License, or (at your option) any later version. ** 00009 ** ** 00010 ** The Wiselib is distributed in the hope that it will be useful, ** 00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** 00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** 00013 ** GNU Lesser General Public License for more details. ** 00014 ** ** 00015 ** You should have received a copy of the GNU Lesser General Public ** 00016 ** License along with the Wiselib. ** 00017 ** If not, see <http://www.gnu.org/licenses/>. ** 00018 ***************************************************************************/ 00019 #ifndef CONNECTOR_SHAWN_CLOCK_H 00020 #define CONNECTOR_SHAWN_CLOCK_H 00021 00022 #include "external_interface/shawn/shawn_types.h" 00023 #include <cstdlib> 00024 00025 namespace wiselib 00026 { 00033 template<typename OsModel_P> 00034 class ShawnClockModel 00035 { 00036 public: 00037 typedef OsModel_P OsModel; 00038 00039 typedef ShawnClockModel<OsModel> self_type; 00040 typedef self_type* self_pointer_t; 00041 00042 typedef double time_t; 00043 // -------------------------------------------------------------------- 00044 enum 00045 { 00046 READY = OsModel::READY, 00047 NO_VALUE = OsModel::NO_VALUE, 00048 INACTIVE = OsModel::INACTIVE 00049 }; 00050 // -------------------------------------------------------------------- 00051 enum { 00052 CLOCKS_PER_SECOND = 1000 00053 }; 00054 // -------------------------------------------------------------------- 00055 ShawnClockModel( ShawnOs& os ) 00056 : os_(os) 00057 {} 00058 // -------------------------------------------------------------------- 00059 int state() 00060 { 00061 return READY; 00062 } 00063 // -------------------------------------------------------------------- 00064 time_t time() 00065 { 00066 return os().proc->owner().world().current_time(); 00067 } 00068 // -------------------------------------------------------------------- 00069 uint16_t microseconds( time_t time ) 00070 { 00071 return 0; 00072 } 00073 // -------------------------------------------------------------------- 00074 uint16_t milliseconds( time_t time ) 00075 { 00076 return (uint16_t)(time - int(time)) * 1000; 00077 } 00078 // -------------------------------------------------------------------- 00079 uint32_t seconds( time_t time ) 00080 { 00081 return (uint32_t)time; 00082 } 00083 00084 private: 00085 ShawnOs& os() 00086 { return os_; } 00087 // -------------------------------------------------------------------- 00088 ShawnOs& os_; 00089 }; 00090 } 00091 00092 #endif