Carbon Timer Example

Posted on

static bool g_bUIShow = true;
void RemoveUITimer()
{
if (g_hTimerRef)
{
RemoveEventLoopTimer(g_hTimerRef);
g_hTimerRef = NULL;
}
}

static void sUITimerHandler(EventLoopTimerRef inTimer, void* userData)
{
bool * show = (bool*) userData ;
ControlRef ctrl ;
GetControlByID(g_hCtrlWindow,&kCtrlIDPictStatusAnimOn,&ctrl) ;

if ( *show )
ShowControl(ctrl) ;
else
HideControl(ctrl) ;

*show = ! (*show);
}

OSErr InstallUITimer()
{
OSErr err = noErr;
static EventLoopTimerUPP networkTimerUPP = NULL;
g_bUIShow = true;

if (networkTimerUPP == NULL)
networkTimerUPP = NewEventLoopTimerUPP(sUITimerHandler);

if (g_hTimerRef)
RemoveUITimer();

err = InstallEventLoopTimer(GetCurrentEventLoop(),
0, kEventDurationSecond ,
networkTimerUPP, &g_bUIShow, &g_hTimerRef);

return err;
}

廣告

One thought on “Carbon Timer Example

    cotton5415 responded:
    二月 19, 2008 at 10:42 上午

    example 2:
    Ref : http://developer.apple.com/qa/qa2004/qa1398.html

    #include <assert.h>
    #include <CoreServices/CoreServices.h>
    #include <mach/mach.h>
    #include <mach/mach_time.h>
    #include <unistd.h>

    uint64_t GetPIDTimeInNanoseconds(void)
    {
    uint64_t start;
    uint64_t end;
    uint64_t elapsed;
    Nanoseconds elapsedNano;

    // Start the clock.

    start = mach_absolute_time();

    // Call getpid. This will produce inaccurate results because
    // we’re only making a single system call. For more accurate
    // results you should call getpid multiple times and average
    // the results.

    (void) getpid();

    // Stop the clock.

    end = mach_absolute_time();

    // Calculate the duration.

    elapsed = end – start;

    // Convert to nanoseconds.

    // Have to do some pointer fun because AbsoluteToNanoseconds
    // works in terms of UnsignedWide, which is a structure rather
    // than a proper 64-bit integer.

    elapsedNano = AbsoluteToNanoseconds( *(AbsoluteTime *) &elapsed );

    return * (uint64_t *) &elapsedNano;
    }

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s