int msPopulateRendererVTableCairoRaster( rendererVTableObj *renderer ) { #ifdef USE_CAIRO renderer->supports_pixel_buffer=1; renderer->supports_transparent_layers = 0; renderer->default_transform_mode = MS_TRANSFORM_SIMPLIFY; initializeCache(&MS_RENDERER_CACHE(renderer)); renderer->startLayer = startLayerRasterCairo; renderer->endLayer = closeLayerRasterCairo; renderer->renderLineTiled = NULL; renderer->renderLine=&renderLineCairo; renderer->createImage=&createImageCairo; renderer->saveImage=&saveImageCairo; renderer->getRasterBufferHandle=&getRasterBufferHandleCairo; renderer->getRasterBufferCopy=&getRasterBufferCopyCairo; renderer->renderPolygon=&renderPolygonCairo; renderer->renderGlyphs=&renderGlyphsCairo; renderer->freeImage=&freeImageCairo; renderer->renderEllipseSymbol = &renderEllipseSymbolCairo; renderer->renderVectorSymbol = &renderVectorSymbolCairo; renderer->renderTruetypeSymbol = &renderTruetypeSymbolCairo; renderer->renderPixmapSymbol = &renderPixmapSymbolCairo; renderer->mergeRasterBuffer = &mergeRasterBufferCairo; renderer->getTruetypeTextBBox = &getTruetypeTextBBoxCairo; renderer->renderTile = &renderTileCairo; renderer->loadImageFromFile = &msLoadMSRasterBufferFromFile; renderer->renderPolygonTiled = &renderPolygonTiledCairo; renderer->freeSymbol = &freeSymbolCairo; renderer->cleanup = &cleanupCairo; return MS_SUCCESS; #else msSetError(MS_MISCERR, "Cairo Driver requested but is not built in", "msPopulateRendererVTableCairoRaster()"); return MS_FAILURE; #endif }
//! @brief set cache path // @param d new directory to use as cache path void HttpGet::setCache(const QDir& d) { m_cachedir = d; bool result; result = initializeCache(d); m_usecache = result; }
/** @brief enable / disable cache useage * @param c set cache usage */ void HttpGet::setCache(bool c) { m_usecache = c; // make sure cache is initialized if(c) m_usecache = initializeCache(m_cachedir); }
void OsgEarth::initialize() { // TOOO not thread safe... if (initialized) { return; } initialized = true; qDebug() << "OsgEarth::initialize - initializing osgearth..."; // increase cache (default is 300); // setenv("OSG_MAX_PAGEDLOD", "500", 0); // setenv("OSG_ASSIGN_PBO_TO_IMAGES", "on", 0); // Number of threads in the DatbasePager set up, inclusive of the number of http dedicated threads. osg::DisplaySettings::instance()->setNumOfDatabaseThreadsHint(6); osg::DisplaySettings::instance()->setNumOfHttpDatabaseThreadsHint(3); initializePathes(); initWindowingSystem(); initializeCache(); // force early initialization of osgEarth capabilities // Doing this too early (before main window is displayed) causes rendering glitches (black holes) // Not sure why... See OSGViewport for when it is called (late...) osgEarth::Registry::capabilities(); displayInfo(); }
bool configInit() { if( !initializeVolume( )) return false; initializeCache(); return true; }
void configure(){ setLoggingLevelEnabled(LOGGING_LEVEL_DEBUG); setVdaRunningStatus(TRUE); setGlobalHeap( createHeap(1024) ); setupConfiguration(); if (!isVdaOfflineMode()) { initializeWinsock(); initializeKssConnection(); } if(isVdaAvailableCache()) initializeCache(); initializeDisk(); }
int main() { int N; vector<int> parts(5, 0); initializeCache(); cin >> N; cin.ignore(); for (int i = 0; i < N; i++) { string species; cin >> species; cin.ignore(); int j = 0; while(animals[j] != species) j++; animalKinds[j] = true; aniOrder[i] = j; } for (int i = 0; i < N; i++) { string thing; int number; cin >> thing >> number; cin.ignore(); int j = 0; while(partsName[j] != thing) j++; partKinds[j] = true; if (j == 0) parts[j] = number; else parts[j] = number/2; } char *aniCount = solve(parts); // Write an action using cout. DON'T FORGET THE "<< endl" // To debug: cerr << "Debug messages..." << endl; int idx = 0; for (int i = 0; i < 5; ++i) { if (!animalKinds[i]) continue; int order = aniOrder[idx++]; cout << animals[order] << " " << int(aniCount[order]) << endl; } }
void* StartServer(void* vp) { int client_sock , c , *new_sock; struct sockaddr_in server , client; //Create socket socket_desc = socket(AF_INET , SOCK_STREAM , 0); if (socket_desc == -1) { printf("Could not create socket"); } puts("Socket created"); //Prepare the sockaddr_in structure server.sin_family = AF_INET; server.sin_addr.s_addr = INADDR_ANY; server.sin_port = htons(80); //Bind if( bind(socket_desc,(struct sockaddr *)&server , sizeof(server)) < 0) { //print the error message perror("bind failed. Error"); return 0; } puts("bind done"); //Listen listen(socket_desc , 3); //Accept and incoming connection c = sizeof(struct sockaddr_in); client_sock=1; int abortState = getStopIssued(); loadAPIs(); initializeCache(); while( client_sock>0 && abortState!=1) { abortState = getStopIssued(); puts("Waiting for incoming connections..."); client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t*)&c); puts("Connection accepted"); pthread_t sniffer_thread; /* pthread_attr_t threadAttribute; int res = pthread_attr_init(&threadAttribute); if (res != 0) { perror("Attribute init failed"); exit(EXIT_FAILURE); } res = pthread_attr_setdetachstate(&threadAttribute, PTHREAD_CREATE_DETACHED); // The worker threads are detached. if (res != 0) { perror("Setting detached state failed"); exit(EXIT_FAILURE); }*/ new_sock = malloc(sizeof(new_sock)); *new_sock = client_sock; if(pthread_create( &sniffer_thread , NULL , connection_handler , (void*) new_sock) < 0) { perror("could not create thread"); } puts("Handler assigned"); } free(new_sock); if (client_sock < 0) { perror("accept failed"); } if(abortState ==1) { puts("Abort signal received."); } freeAPIs(); cleanCache(); puts("Server Stopped"); return 0; }
int main(int argc, char **argv) { const char *jobid, *user, *title, *options, *ppdFile, *file; unsigned long copies; Request request; PPDFile ppd; // Check the given arguments if (argc != 6 && argc != 7) { fprintf(stderr, _("Usage: %s job-id user title copies options " "[file]\n"), argv[0]); return 1; } jobid = argv[1]; user = argv[2]; title = argv[3]; options = argv[5]; file = argc == 7 ? argv[6] : NULL; copies = strtol(argv[4], (char **)NULL, 10); ppdFile = getenv("PPD"); // Get more information on the SpliX environment (for debugging) DEBUGMSG(_("SpliX filter V. %s by Aurélien Croc (AP²C)"), VERSION); DEBUGMSG(_("More information at: http://splix.ap2c.org")); DEBUGMSG(_("Compiled with: Threads=%s (#=%u, Cache=%u), JBIG=%s, " "BlackOptim=%s"), opt_threads ? _("enabled") : _("disabled"), THREADS, CACHESIZE, opt_jbig ? _("enabled") : _("disabled"), opt_blackoptim ? _("enabled") : _("disabled")); // Open the given file if (file && !freopen(file, "r", stdin)) { ERRORMSG(_("Cannot open file %s"), file); return errno; } // Open the PPD file if (!ppd.open(ppdFile, PPDVERSION, options)) return 1; // Load the request if (!request.loadRequest(&ppd, jobid, user, title, copies)) return 2; #ifndef DISABLE_THREADS if (!initializeCache()) return 3; #endif /* DISABLE_THREADS */ // Render the request if (!render(request)) { uninitializeCache(); return 4; } #ifndef DISABLE_THREADS if (!uninitializeCache()) return 5; #endif /* DISABLE_THREADS */ return 0; }
IsotopeEnvelopeEstimator::Impl::Impl(const Config& config) : config_(config) { initializeCache(); }
int main(int argc, char **argv) { int i, j; struct timeval time_interval; fd_set useRead; fd_set useExcept; int selRet; char errTxt[256]; RsslBuffer errorText = {255, (char*)errTxt}; RsslInProgInfo inProg = RSSL_INIT_IN_PROG_INFO; RsslRet retval = 0; int iargs; RsslErrorInfo rsslErrorInfo; RsslBool cacheOption = RSSL_FALSE; RsslReactorOMMProviderRole providerRole; RsslBindOptions sopts = RSSL_INIT_BIND_OPTS; RsslCreateReactorOptions reactorOpts; RsslReactorDispatchOptions dispatchOpts; time_t nextSendTime; /* Initialize RSSL. The locking mode RSSL_LOCK_GLOBAL_AND_CHANNEL is required to use the RsslReactor. */ if (rsslInitialize(RSSL_LOCK_GLOBAL_AND_CHANNEL, &rsslErrorInfo.rsslError) != RSSL_RET_SUCCESS) { printf("rsslInitialize(): failed <%s>\n",rsslErrorInfo.rsslError.text); /* WINDOWS: wait for user to enter something before exiting */ #ifdef _WIN32 printf("\nPress Enter or Return key to exit application:"); getchar(); #endif exit(RSSL_RET_FAILURE); } rsslClearOMMProviderRole(&providerRole); providerRole.base.channelEventCallback = channelEventCallback; providerRole.base.defaultMsgCallback = defaultMsgCallback; providerRole.loginMsgCallback = loginMsgCallback; providerRole.directoryMsgCallback = directoryMsgCallback; providerRole.dictionaryMsgCallback = dictionaryMsgCallback; providerRole.tunnelStreamListenerCallback = tunnelStreamListenerCallback; rsslClearCreateReactorOptions(&reactorOpts); if (!(pReactor = rsslCreateReactor(&reactorOpts, &rsslErrorInfo))) { printf("Reactor creation failed: %s\n", rsslErrorInfo.rsslError.text); cleanUpAndExit(); } snprintf(portNo, 128, "%s", defaultPortNo); snprintf(serviceName, 128, "%s", defaultServiceName); setServiceId(1); for(iargs = 1; iargs < argc; ++iargs) { if (0 == strcmp("-p", argv[iargs])) { ++iargs; if (iargs == argc) exitWithUsage(); snprintf(portNo, 128, "%s", argv[iargs]); } else if (0 == strcmp("-s", argv[iargs])) { ++iargs; if (iargs == argc) exitWithUsage(); snprintf(serviceName, 128, "%s", argv[iargs]); } else if (0 == strcmp("-id", argv[iargs])) { long tmpId = 0; ++iargs; if (iargs == argc) exitWithUsage(); tmpId = atol(argv[iargs]); if (tmpId < 0) { printf("ServiceId must be positive.\n"); exitWithUsage(); } setServiceId(tmpId); } else if (0 == strcmp("-x", argv[iargs])) { xmlTrace = RSSL_TRUE; snprintf(traceOutputFile, 128, "RsslVAProvider\0"); } else if (0 == strcmp("-runtime", argv[iargs])) { ++iargs; if (iargs == argc) exitWithUsage(); timeToRun = atoi(argv[iargs]); } else if (0 == strcmp("-cache", argv[iargs])) { cacheOption = RSSL_TRUE; } else { printf("Error: Unrecognized option: %s\n\n", argv[iargs]); exitWithUsage(); } } printf("portNo: %s\n", portNo); printf("serviceName: %s\n", serviceName); printf("serviceId: %llu\n", getServiceId()); /* Initialiize client session information */ for (i = 0; i < MAX_CLIENT_SESSIONS; i++) { clearClientSessionInfo(&clientSessions[i]); } initializeCache(cacheOption); /* Initialize login handler */ initLoginHandler(); /* Initialize source directory handler */ initDirectoryHandler(); /* Initialize dictionary provider */ initDictionaryProvider(); /* Initialize market price handler */ initItemHandler(); /* Initialize symbol list item list */ initSymbolListItemList(); /* Initialize market by order items */ initMarketByOrderItems(); /* set service name in directory handler */ setServiceName(serviceName); /* load dictionary */ if (loadDictionary() != RSSL_RET_SUCCESS) { /* exit if dictionary cannot be loaded */ /* WINDOWS: wait for user to enter something before exiting */ #ifdef _WIN32 printf("\nPress Enter or Return key to exit application:"); getchar(); #endif exit(RSSL_RET_FAILURE); } initializeCacheDictionary(); /* Initialize run-time */ initRuntime(); FD_ZERO(&readFds); FD_ZERO(&exceptFds); sopts.guaranteedOutputBuffers = 500; sopts.serviceName = portNo; sopts.majorVersion = RSSL_RWF_MAJOR_VERSION; sopts.minorVersion = RSSL_RWF_MINOR_VERSION; sopts.protocolType = RSSL_RWF_PROTOCOL_TYPE; /* Create the server. */ if (!(rsslSrvr = rsslBind(&sopts, &rsslErrorInfo.rsslError))) { printf("Unable to bind RSSL server: <%s>\n",rsslErrorInfo.rsslError.text); /* WINDOWS: wait for user to enter something before exiting */ #ifdef _WIN32 printf("\nPress Enter or Return key to exit application:"); getchar(); #endif exit(RSSL_RET_FAILURE); } FD_SET(rsslSrvr->socketId, &readFds); FD_SET(pReactor->eventFd, &readFds); rsslClearReactorDispatchOptions(&dispatchOpts); dispatchOpts.maxMessages = MAX_CLIENT_SESSIONS; // initialize next send time nextSendTime = time(NULL) + UPDATE_INTERVAL; /* this is the main loop */ while(RSSL_TRUE) { useRead = readFds; useExcept = exceptFds; time_interval.tv_sec = UPDATE_INTERVAL; time_interval.tv_usec = 0; /* Call select() to check for any messages */ selRet = select(FD_SETSIZE,&useRead, NULL,&useExcept,&time_interval); if (selRet > 0) { RsslRet ret; /* Accept connection, if one is waiting */ if (FD_ISSET(rsslSrvr->socketId, &useRead)) { RsslClientSessionInfo *pClientSessionInfo = NULL; RsslReactorAcceptOptions aopts; rsslClearReactorAcceptOptions(&aopts); /* find an available client session */ for (i = 0; i < MAX_CLIENT_SESSIONS; i++) { if (!clientSessions[i].isInUse) { pClientSessionInfo = &clientSessions[i]; pClientSessionInfo->isInUse = RSSL_TRUE; break; } } /* Reject the channel if we are out of client sessions */ if (!pClientSessionInfo) aopts.rsslAcceptOptions.nakMount = RSSL_TRUE; else aopts.rsslAcceptOptions.userSpecPtr = pClientSessionInfo; printf("Accepting new connection...\n"); if (rsslReactorAccept(pReactor, rsslSrvr, &aopts, (RsslReactorChannelRole*)&providerRole, &rsslErrorInfo) != RSSL_RET_SUCCESS) { printf("rsslReactorAccept() failed: %s(%s)\n", rsslErrorInfo.rsslError.text, rsslErrorInfo.errorLocation); cleanUpAndExit(); } } /* Call rsslReactorDispatch(). This will handle any events that have occurred on its channels. * If there are events or messages for the application to process, they will be delivered * through the callback functions given by the providerRole object. * A return value greater than RSSL_RET_SUCCESS indicates there may be more to process. */ while ((ret = rsslReactorDispatch(pReactor, &dispatchOpts, &rsslErrorInfo)) > RSSL_RET_SUCCESS) ; if (ret < RSSL_RET_SUCCESS) { printf("rsslReactorDispatch() failed: %s\n", rsslErrorInfo.rsslError.text); cleanUpAndExit(); } } else if (selRet < 0) { #ifdef _WIN32 if (WSAGetLastError() == WSAEINTR) continue; printf("Error: select: %d\n", WSAGetLastError()); #else if (errno == EINTR) continue; perror("select"); #endif cleanUpAndExit(); } // send any updates at next send time if (time(NULL) >= nextSendTime) { /* Send market price updates for each connected channel */ updateItemInfo(); for (i = 0; i < MAX_CLIENT_SESSIONS; i++) { if (clientSessions[i].clientChannel != NULL) { if (sendItemUpdates(pReactor, clientSessions[i].clientChannel) != RSSL_RET_SUCCESS) { removeClientSessionForChannel(pReactor, clientSessions[i].clientChannel); } // send any tunnel stream messages for (j = 0; j < MAX_TUNNEL_STREAMS; j++) { if (clientSessions[i].simpleTunnelMsgHandler[j].tunnelStreamHandler.pTunnelStream != NULL) { handleSimpleTunnelMsgHandler(pReactor, clientSessions[i].clientChannel, &clientSessions[i].simpleTunnelMsgHandler[j]); } } } } nextSendTime += UPDATE_INTERVAL; } /* Handle run-time */ handleRuntime(); } }
/*** MAIN ***/ int main(int argc, char **argv) { RsslErrorInfo error; RsslError rsslErr; RsslCreateReactorOptions reactorOpts; RsslReactorDispatchOptions dispatchOpts; RsslInt32 j; RsslReactorOMMNIProviderRole role; RsslDataDictionary dictionary = RSSL_INIT_DATA_DICTIONARY; char err[128]; RsslBuffer errBuf = {128, &err[0]}; int selRet; time_t currentTime = 0; RsslRet ret; RsslInitializeExOpts initOpts = RSSL_INIT_INITIALIZE_EX_OPTS; rsslInitNIChannelCommand(&chnlCommand); handleConfig(argc, argv, &chnlCommand); initializeCache(cacheCommandlineOption); initOpts.jitOpts.libcryptoName = libcryptoName; initOpts.jitOpts.libsslName = libsslName; initOpts.jitOpts.libcurlName = libcurlName; initOpts.rsslLocking = RSSL_LOCK_GLOBAL_AND_CHANNEL; /* Initialize run-time */ initRuntime(); rsslInitializeEx(&initOpts, &rsslErr); /* Setup role */ rsslClearOMMNIProviderRole((RsslReactorOMMNIProviderRole*)&role); role.pLoginRequest = (RsslRDMLoginRequest*)&chnlCommand.loginRequest; role.loginMsgCallback = processLoginResponse; role.pDirectoryRefresh = &chnlCommand.directoryRefresh; role.base.channelEventCallback = channelEventCallback; role.base.defaultMsgCallback = processResponse; printf("Connections:\n"); chnlCommand.pRole = (RsslReactorChannelRole*)&role; chnlCommand.cOpts.rsslConnectOptions.guaranteedOutputBuffers = 500; chnlCommand.cOpts.rsslConnectOptions.majorVersion = RSSL_RWF_MAJOR_VERSION; chnlCommand.cOpts.rsslConnectOptions.minorVersion = RSSL_RWF_MINOR_VERSION; chnlCommand.cOpts.rsslConnectOptions.userSpecPtr = (void*)&chnlCommand; // printf(" %s:%s:%s\n", chnlCommand.hostName, chnlCommand.port, chnlCommand.serviceName); printf(" MarketPriceItems:"); for(j = 0; j < CHAN_CMD_MAX_ITEMS; ++j) { RsslNIItemInfo *pItem = &chnlCommand.marketPriceItemInfo[j]; if (pItem->isActive) printf(" %.*s", (int)sizeof(pItem->Itemname), pItem->Itemname); } printf(" MarketByOrderItems:"); for(j = 0; j < CHAN_CMD_MAX_ITEMS; ++j) { RsslNIItemInfo *pItem = &chnlCommand.marketByOrderItemInfo[j]; if (pItem->isActive) printf(" %.*s", (int)sizeof(pItem->Itemname), pItem->Itemname); } printf("\n"); printf("\n"); /* Load local dictionary */ if(rsslLoadFieldDictionary("RDMFieldDictionary", &dictionary, &errBuf) < RSSL_RET_SUCCESS) { printf("Dictionary error: %s\n", errBuf.data); exit(-1); } chnlCommand.dictionary = &dictionary; initializeCacheDictionary(&dictionary); rsslClearCreateReactorOptions(&reactorOpts); reactorOpts.dispatchDecodeMemoryBufferSize = 1024; setupLoginRequest(&chnlCommand, 1); setupDirectoryResponseMsg(&chnlCommand, -1); if (!(pReactor = rsslCreateReactor(&reactorOpts, &error))) { printf("Error: %s", error.rsslError.text); exit(-1); } FD_ZERO(&readFds); FD_ZERO(&writeFds); FD_ZERO(&exceptFds); FD_SET(pReactor->eventFd, &readFds); if (rsslReactorConnect(pReactor, &chnlCommand.cOpts, chnlCommand.pRole, &error) != RSSL_RET_SUCCESS) printf("Error rsslReactorConnect(): %s\n", error.rsslError.text); rsslClearReactorDispatchOptions(&dispatchOpts); //dispatchOpts.pReactorChannel = &chnlCommand.reactorChannel; printf("Connection started!\n"); while ( RSSL_TRUE ) { struct timeval selectTime; int dispatchCount = 0; fd_set useReadFds = readFds, useWriteFds = writeFds, useExceptFds = exceptFds; selectTime.tv_sec = 1; selectTime.tv_usec = 0; handleRuntime(); selRet = select(FD_SETSIZE, &useReadFds, &useWriteFds, &useExceptFds, &selectTime); if (selRet == 0 ) /* no messages received, send updates and continue */ { // Update items updateItemInfo(&chnlCommand); /* Send market price updates for each connected channel */ if (chnlCommand.startWrite == RSSL_TRUE) { if ((chnlCommand.reactorChannel != NULL) && (chnlCommand.reactorChannel->socketId != -1)) { if (sendItemUpdates(pReactor,chnlCommand.reactorChannel) != RSSL_RET_SUCCESS) recoverConnection(pReactor, chnlCommand.reactorChannel, &chnlCommand); } } else { if (cacheInfo.useCache) cacheItemData(&chnlCommand); } } else if (selRet > 0) { RsslRet ret; while ((ret = rsslReactorDispatch(pReactor, &dispatchOpts, &error)) > 0); if(ret < 0) { printf("dispatch error! %i\n %s\n %s\n", ret, error.rsslError.text, error.errorLocation); /* Reactor has shutdown. Clean up and exit. */ cleanUpAndExit(); } } /* get current time */ if ((currentTime = time(NULL)) < 0) { printf("time() failed.\n"); } // send login reissue if login reissue time has passed if (chnlCommand.canSendLoginReissue == RSSL_TRUE && currentTime >= (RsslInt)chnlCommand.loginReissueTime) { RsslReactorSubmitMsgOptions submitMsgOpts; RsslErrorInfo rsslErrorInfo; rsslClearReactorSubmitMsgOptions(&submitMsgOpts); submitMsgOpts.pRDMMsg = (RsslRDMMsg*)chnlCommand.pRole->ommNIProviderRole.pLoginRequest; if ((ret = rsslReactorSubmitMsg(pReactor,chnlCommand.reactorChannel,&submitMsgOpts,&rsslErrorInfo)) != RSSL_RET_SUCCESS) { printf("Login reissue failed: %d(%s)\n", ret, rsslErrorInfo.rsslError.text); } else { printf("Login reissue sent\n"); } chnlCommand.canSendLoginReissue = RSSL_FALSE; } } }