Professional Web Applications Themes

InstallXTimeTask sample? - Mac Programming

Does anybody have a sample on how to install a task using InstallXTime? I'd like to have a function run every 1/60th of a second, but can't seem to find any sample source for InstallXTime. I've searched Apple's website, Google, and a few other places I could think of. How would I do this? Thanks, Mike...

  1. #1

    Default InstallXTimeTask sample?

    Does anybody have a sample on how to install a task using
    InstallXTime? I'd like to have a function run every 1/60th of a
    second, but can't seem to find any sample source for InstallXTime.
    I've searched Apple's website, Google, and a few other places I could
    think of.

    How would I do this?

    Thanks,

    Mike
    macxguy Guest

  2. #2

    Default Re: InstallXTimeTask sample?

    In article <google.com>, macxguy
    <com> wrote:
     

    That because the routine is really named InstallXTimeTask(). Search
    for "time manager" in <http://developer.apple.com/>.


    -=-=-=-=-
    Carl Guest

  3. #3

    Default Re: InstallXTimeTask sample?

    Actually, I had a similar question to this, and haven't really found any
    good code samples for OSX.

    Also, can somebody explain "taking advantage of the drift-free,
    fixed-frequency timing services of the extended Time Manager." If I want
    something to run 200 times per second, at equally spaced intervals, do I use
    InstallTimeTask or InstallXTimeTask?

    Also, it's not quite clear when I call PrimeTimeTask. Is there a good code
    sample out there?

    Thanks,

    Alex

    in article 291020030754097168%com, Carl R. Osterwald at com
    wrote on 10/29/03 9:54 AM:
     
    >
    > That because the routine is really named InstallXTimeTask(). Search
    > for "time manager" in <http://developer.apple.com/>.
    >
    >
    > -=-=-=-=-[/ref]


    Alex Guest

  4. #4

    Default Re: InstallXTimeTask sample?

    In article <BBC6F8F1.2A1B3%rampellsoft.com>,
     

    Don't know if this is a good example, but an example it is.

    I quickly extracted it form one of the many projects it's been
    used in over the past 10 years.

    Hope it's of some use...

    Lloyd D. Ollmann, Jr



    /* ================================================== =============
    * File - CMacTimer.h
    * ---------------------------------------------------------------
    */

    #ifndef CMacTimer_H
    #define CMacTimer_H

    /* ================================================== =============
    * ---------------------------------------------------------------
    */

    #include <Timer.h>

    /* ================================================== =============
    * ---------------------------------------------------------------
    */

    typedef struct {
    TMTask m_tmTask;
    UInt32 m_RefCon;
    } TMInfo;

    typedef TMInfo* TMInfoPtr;

    /* ================================================== =============
    * ---------------------------------------------------------------
    */

    class CMacTimer {
    public:
    CMacTimer();
    virtual ~CMacTimer();

    // Functions
    bool IsActive() const;
    bool RetriggerTimer() const;

    virtual void Start(bool fReArm);
    virtual void Stop();

    virtual void SetTimerRefCon(UInt32 refCon);
    virtual void SetTimerHandlerProc(TimerProcPtr theProc);

    virtual void SetTimerInterval(long lTimeRate);
    virtual long GetTimerInterval() const;

    virtual void SetCounter(UInt32 c);
    virtual UInt32 GetCounter() const;

    private:
    // Data
    TimerUPP m_upp;
    TMInfo m_tmi;
    bool m_bTimerActive;
    bool m_bResetTrigger;
    long m_lTimeRate;

    volatile UInt32 m_lCounter;
    };

    /** ================================================== ============
    * --------------------------------------------------------------
    */

    inline bool CMacTimer::RetriggerTimer() const {
    return m_bResetTrigger;
    }

    /** ================================================== ============
    * --------------------------------------------------------------
    */

    inline bool CMacTimer::IsActive() const {
    return m_bTimerActive;
    }

    #endif

    /* ================================================== =============
    * File - CMacTimer.cpp
    * ---------------------------------------------------------------
    */

    /* ================================================== =============
    * ---------------------------------------------------------------
    */

    #include "CMacTimer.h"

    /** ================================================== ============
    * --------------------------------------------------------------
    * [public]
    */

    CMacTimer::CMacTimer()
    {
    m_upp = nil;

    m_tmi.m_tmTask.tmAddr = m_upp;
    m_tmi.m_tmTask.tmWakeUp = 0;
    m_tmi.m_tmTask.tmReserved = 0;

    m_bTimerActive = false;
    m_bResetTrigger = false;
    m_lTimeRate = 1;
    m_lCounter = 0;
    }

    /** ================================================== ============
    * --------------------------------------------------------------
    * [virtual public]
    */

    CMacTimer::~CMacTimer()
    {
    Stop();

    if( m_upp ) {
    ::DisposeTimerUPP( m_upp );
    }
    }

    /** ================================================== ============
    * --------------------------------------------------------------
    * [virtual public]
    */

    void CMacTimer::Start( bool bResetTrigger )
    {
    if( m_upp ) {
    ::InsXTime((QElemPtr) &m_tmi);
    ::PrimeTime((QElemPtr) &m_tmi, m_lTimeRate);

    m_bTimerActive = true;
    m_bResetTrigger = bResetTrigger;
    }
    }

    /** ================================================== ============
    * --------------------------------------------------------------
    * [virtual public]
    */

    void CMacTimer::Stop()
    {
    if( m_bTimerActive ) {
    m_bTimerActive = false;

    ::RmvTime( (QElemPtr) &m_tmi );
    }
    }

    /** ================================================== ============
    * --------------------------------------------------------------
    * [virtual public]
    */

    void CMacTimer::SetTimerRefCon( UInt32 refCon )
    {
    m_tmi.m_RefCon = refCon;
    }

    /** ================================================== ============
    * --------------------------------------------------------------
    * [virtual public]
    */

    void CMacTimer::SetTimerHandlerProc( TimerProcPtr theProc )
    {
    Stop();

    if(m_upp) {
    ::DisposeTimerUPP( m_upp );
    m_upp = nil;
    }

    m_tmi.m_tmTask.tmAddr = m_upp = ::NewTimerUPP( theProc );
    }

    /** ================================================== ============
    * --------------------------------------------------------------
    * [virtual public]
    */

    void CMacTimer::SetTimerInterval( long lTimeRate )
    {
    // positive values is milliseconds
    // negatie values is microseconds
    m_lTimeRate = lTimeRate;
    };

    /** ================================================== ============
    * --------------------------------------------------------------
    * [virtual public]
    */

    long CMacTimer::GetTimerInterval() const
    {
    return m_lTimeRate;
    }

    /** ================================================== ============
    * --------------------------------------------------------------
    * [virtual public]
    */

    void CMacTimer::SetCounter( UInt32 c )
    {
    m_lCounter = c;
    }

    /** ================================================== ============
    * --------------------------------------------------------------
    * [virtual public]
    */

    UInt32 CMacTimer::GetCounter() const
    {
    return m_lCounter;
    }

    /* ================================================== =============
    * File - main.cpp
    * ---------------------------------------------------------------
    */

    /* ================================================== =============
    * ---------------------------------------------------------------
    */

    #include "CMacTimer.h"

    /* ================================================== =============
    * ---------------------------------------------------------------
    */

    typedef struct {
    CMacTimer* m_pTimer;
    } PrivRef;

    typedef PrivRef* PrivRefPtr;

    // ---------------------------------------------------------------
    // Millisecond timer callback handlers

    static PrivRef s_privrefTimer;
    static CMacTimer s_timer;

    static pascal void TimerInterupptHandler(TMTaskPtr tmTaskPtr) {
    CMacTimer* pt;
    TMInfoPtr ptm = (TMInfoPtr)tmTaskPtr;
    pt = ( (PrivRefPtr)ptm->m_RefCon )->m_pTimer;
    pt->SetCounter( pt->GetCounter() + 1 );

    PrimeTime( (QElemPtr)tmTaskPtr, pt->GetTimerInterval() );
    }

    /** ================================================== ============
    * --------------------------------------------------------------
    */

    UInt32 GetMillisecondTime()
    {
    UInt32 c = 0;

    if( ! s_timer.IsActive()) {
    s_privrefTimer.m_pTimer = &s_timer;

    s_timer.SetTimerRefCon( (UInt32)&s_privrefTimer );
    s_timer.SetTimerHandlerProc( TimerInterupptHandler );
    s_timer.SetTimerInterval( -1000 );
    s_timer.Start( &s_timer );
    } else {
    c = s_timer.GetCounter();
    }

    return c;
    }

    /* ================================================== =============
    * ---------------------------------------------------------------
    */

    int main()
    {
    UInt32 cTicks = GetMillisecondTime();
    }
    lloyd Guest

  5. #5

    Default Re: InstallXTimeTask sample?

    What's the main difference between InstallTimeTask and InstallXTime task,
    though?

    In the doentation, it states:
    "Use InstallXTimeTask only if you wish to use the drift-free,
    fixed-frequency timing services of the extended Time Manager; use
    InstallTimeTask in all other cases."

    Does this mean that InstallXTimeTask will install a time task that will be
    executed at exact intervals? If I'm trying to have something run 100 times
    per second (every 1/100 of a second) is this the call I want?

    Thanks,

    Alex

    Alex Guest

  6. #6

    Default Re: InstallXTimeTask sample?

    In article <BBC82410.2A26F%rampellsoft.com>,
    Alex Rampell <rampellsoft.com> wrote:
     

    Don't use InstallXTimeTask for a one shot timer. Do use it when you care
    that if you set your interval for 1/100 of a second, you will get called
    100 times in a second. Don't bother if it is OK that you only get called
    96 times in a second.

    InstallTimeTask just resets the delay to 1/100 of a second. It doesn't
    care about the effect of other interrupt tasks also running on your
    machine.

    InstallXTimeTask goes through extra work, each time your timer task is
    called, to measure the interrupt latency, and adjust the duration that
    it sleeps for, so that on the average, over a long period of time, the
    sleep duration was what was actually asked for.
    David Guest

Similar Threads

  1. just ran a sample flv
    By izdabye in forum Macromedia Flash Flashcom
    Replies: 0
    Last Post: April 17th, 07:16 PM
  2. The way to run an sample.
    By dreamlikeriver in forum Macromedia Flash Flashcom
    Replies: 0
    Last Post: August 18th, 04:15 AM
  3. sample
    By Edwin Merced in forum Macromedia Flash
    Replies: 1
    Last Post: June 7th, 10:12 PM
  4. TNA or MTA sample
    By Paul in forum ASP Components
    Replies: 1
    Last Post: September 6th, 01:50 AM
  5. Here you have a sample
    By Paul Kraus in forum PERL Beginners
    Replies: 0
    Last Post: August 21st, 02:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139