void Application::_init(const StringW& appType)
{
  _uiEngine = NULL;

  if (appType.startsWith(Ascii8("UI")))
  {
#if defined(FOG_BUILD_UI)
    // Create the UIEngine by name.
    _uiEngine = createUIEngine(appType);
#else
    Logger::warning("Fog::Application", "_init",
      "Requested to create UI based application, but Fog/UI was disabled at compile-time.");
#endif
  }

  EventLoopImpl* eventLoopImpl = NULL;

#if defined(FOG_BUILD_UI)
  if (_uiEngine != NULL)
    eventLoopImpl = _uiEngine->_eventLoop._d->addRef();
#endif // FOG_BUILD_UI

  // Create EventLoop by of the required type.
  if (eventLoopImpl == NULL)
    eventLoopImpl = createEventLoop(appType);

  if (eventLoopImpl != NULL)
    _homeThread->_eventLoop.adopt(eventLoopImpl);

  // Set global application instance (singleton).
  if (_instance == NULL)
    _instance = this;
}
Exemple #2
0
// The main function
int main( int argc, char * argv[] ){

    if( argc != 2 ){
        fprintf( stderr, "Please give one file please.\n" );
        exit( -1 );
    }
    
    fileName = argv[ 1 ];
    
    // Create the event loop
    void * eventLoop = createEventLoop( );
    
    if( eventLoop == NULL ){
        fprintf(stderr, "createEventLoop failed!");
        exit(-1);
    }
    
    // Start the event loop
    startEventLoop(eventLoop, readFile, eventLoop);

    // No memory leaks
    cleanupEventLoop(eventLoop);
    
    return 0;

}
Exemple #3
0
//-----------------------------------------------------------------------------
// 描述: 设置 eventLoop 的个数
//-----------------------------------------------------------------------------
void EventLoopList::setCount(int count)
{
    count = ensureRange(count, 1, (int)MAX_LOOP_COUNT);

    for (int i = 0; i < count; i++)
        items_.add(createEventLoop());
}
int main() {
    int timerfd;
    int ret = 0;
    int numevents = 0;
    int j = 0;
    int processed = 0;
    struct timeval tvp;
    tvp.tv_sec = 0;
    tvp.tv_usec = 1;
    eventLoop *eLoop = createEventLoop();
    timerfd = createTimerfd();
    if ((ret = createFileEvent(eLoop, timerfd, 1, timerCallback)) == -1) {
        printf("timerfd createFileEvent failed!\n");
    } else {
        printf("timerfd createFileEvent ok!\n");
    }
    if ((ret = aePollCreate(eLoop)) == -1) {
        printf("aePollCreate failed!\n");
    } else {
        printf("aePollCreate ok!\n");
    }
    addTimer(eLoop, timerfd, READABLE);
    runEvery(timerfd, 800);

    int count = 0;
    while(1) {
        numevents = 0;
        numevents = aePollPoll(eLoop, &tvp);
        for (j = 0; j < numevents; j++) {
            fileEvent *fe = &eLoop->fEvents[eLoop->fired[j].fd];
            int mask = eLoop->fired[j].mask;
            int fd = eLoop->fired[j].fd;

	    /* note the fe->mask & mask & ... code: maybe an already processed
             * event removed an element that fired and we still didn't
             * processed, so we check if the event is still valid. */
            if (fe->mask & mask & READABLE)
                fe->rfileProc(NULL, eLoop,fd,mask);
            if (fe->mask & mask & WRITEABLE && fe->wfileProc != fe->rfileProc)
                fe->wfileProc(NULL, eLoop,fd,mask);
            processed++;
        }
        count++;
//        if(count==10000000) deleteTimer(eLoop, timerfd, 1);
    } 
}