Wiselib
wiselib.testing/external_interface/iphone/iphone_timer.h
Go to the documentation of this file.
00001 // vim: set noexpandtab ts=4 sw=4:
00002 
00003 #ifndef IPHONE_TIMER_H
00004 #define IPHONE_TIMER_H
00005 
00006 #include "util/delegates/delegate.hpp"
00007 #include "iphone_system.h"
00008 #import <Foundation/Foundation.h>
00009 
00010 typedef delegate1<void, void*> iphone_timer_delegate_t;
00011 
00012 @interface iPhoneTimerController : NSObject {
00013    iphone_timer_delegate_t delegate_;
00014    void* userData_;
00015    NSTimeInterval seconds_;
00016 }
00017 
00018 - (id) initWithTime: (NSTimeInterval)seconds andDelegate: (iphone_timer_delegate_t) aDelegate andUserData: (void*) aData;
00019 - (void) startTimer;
00020 - (void) fireDelegate: (NSTimer*)theTimer;
00021 
00022 @end
00023 
00024 namespace wiselib
00025 {
00026 
00027    template<typename OsModel_P>
00028    class iPhoneTimerModel
00029    {
00030    public:
00031       typedef OsModel_P OsModel;
00032 
00033       typedef iPhoneTimerModel<OsModel> self_type;
00034       typedef self_type* self_pointer_t;
00035 
00036       typedef uint32_t millis_t;
00037       
00038       // --------------------------------------------------------------------
00039       enum ErrorCodes
00040       {
00041          SUCCESS = OsModel::SUCCESS,
00042          ERR_UNSPEC = OsModel::ERR_UNSPEC
00043       };
00044       // --------------------------------------------------------------------
00045       iPhoneTimerModel( iPhoneSystem& system )
00046          : system_(system)
00047       {
00048       }
00049       // --------------------------------------------------------------------
00050       template<typename T, void (T::*TMethod)(void*)>
00051       int set_timer( millis_t millis, T *obj_pnt, void *userdata )
00052       {     
00053          NSTimeInterval seconds = millis/1000.0;
00054          iPhoneTimerController *timer = [[iPhoneTimerController alloc] initWithTime: seconds
00055                                              andDelegate: iphone_timer_delegate_t::from_method<T, TMethod>(obj_pnt)
00056                                              andUserData: userdata];
00057          [timer startTimer];        
00058          [timer release];
00059          return SUCCESS;
00060       }
00061 
00062    private:
00063       iPhoneSystem& system()
00064       { return system_; }
00065       // --------------------------------------------------------------------
00066       iPhoneSystem& system_;
00067    };
00068    
00069 }
00070 #endif // IPHONE_TIMER_H
00071 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines