void* ComuactivClientSlot::ComuactivClientSlotImpl::run() { log_("Creating passive channels"); pLow_ = ProxyChannel(Channel::PASSIVE); pLow_.registerHandler( Message::HEARTBEAT, pHandler(new HeartbeatHandler() ) ); pLow_.start(); log_(std::string("Initialising connection to: ").append(host_).append(std::string(":")).append(highPort_)); high_ = ProxyChannel(Channel::ACTIVE); AssociationSetupResponseHandler::Callback aSRHcallback = std::bind(&ComuactivClientSlotImpl::stageTwo, this, std::placeholders::_1, std::placeholders::_2); high_.registerHandler( messages::Message::ASSOCIATION_SETUP_RESPONSE, pHandler( new AssociationSetupResponseHandler( aSRHcallback ) ) ); high_.setHost(host_); high_.setPort(highPort_); high_.start(); //TODO: synchronizacja sleep(1); pMessage msg = pAssociationSetupMsg( new AssociationSetupMsg( pLow_.getPort() ) ); high_.writeAndHandleMessage(msg->getRaw()); }
_CRTIMP void __cdecl _invalid_parameter( const wchar_t *pszExpression, const wchar_t *pszFunction, const wchar_t *pszFile, unsigned int nLine, uintptr_t pReserved ) { _invalid_parameter_handler pHandler = __pInvalidArgHandler; pszExpression; pszFunction; pszFile; pHandler = (_invalid_parameter_handler) _decode_pointer(pHandler); if (pHandler != NULL) { pHandler(pszExpression, pszFunction, pszFile, nLine, pReserved); return; } // No user handler is defined. Notify the debugger if attached. _CRT_DEBUGGER_HOOK(_CRT_DEBUGGER_INVALIDPARAMETER); _invoke_watson(pszExpression, pszFunction, pszFile, nLine, pReserved); }
void HTTPServerConnection::run() { std::string server = _pParams->getSoftwareVersion(); HTTPServerSession session(socket(), _pParams); while (!_stopped && session.hasMoreRequests()) { try { Poco::FastMutex::ScopedLock lock(_mutex); if (!_stopped) { HTTPServerResponseImpl response(session); HTTPServerRequestImpl request(response, session, _pParams); Poco::Timestamp now; response.setDate(now); response.setVersion(request.getVersion()); response.setKeepAlive(_pParams->getKeepAlive() && request.getKeepAlive() && session.canKeepAlive()); if (!server.empty()) response.set("Server", server); try { std::auto_ptr<HTTPRequestHandler> pHandler(_pFactory->createRequestHandler(request)); if (pHandler.get()) { if (request.expectContinue()) response.sendContinue(); pHandler->handleRequest(request, response); session.setKeepAlive(_pParams->getKeepAlive() && response.getKeepAlive() && session.canKeepAlive()); } else sendErrorResponse(session, HTTPResponse::HTTP_NOT_IMPLEMENTED); } catch (Poco::Exception&) { if (!response.sent()) { try { sendErrorResponse(session, HTTPResponse::HTTP_INTERNAL_SERVER_ERROR); } catch (...) { } } throw; } } } catch (NoMessageException&) { break; } catch (MessageException&) { sendErrorResponse(session, HTTPResponse::HTTP_BAD_REQUEST); } } }
// returns the timer handle (hTimer) unsigned StartKernelTimer (unsigned nHzDelay, TKernelTimerHandler *pHandler, void *pParam, void *pContext) { if(interrupt->ENABLE_BASIC_IRQ != 1) {initInterrupts(); interruptBasicIRQ();} enableTimeout(40, RPI_ARMTIMER_CTRL_23BIT | RPI_ARMTIMER_CTRL_ENABLE | RPI_ARMTIMER_CTRL_INT_ENABLE | RPI_ARMTIMER_CTRL_PRESCALE_256); pHandler(1, pParam, pContext); return 1; }
static BOOL TapeImage_DoHighLevelState(void) { BOOL (*pHandler)(void) = TapeImage_HighLevelStateData; if (pHandler!=NULL) { return pHandler(); } return TRUE; }
bool VJSXMLHttpRequest::_OnReadyStateChange(XBOX::VJSParms_setProperty& ioParms, XMLHttpRequest* inXhr) { XBOX::VJSObject pReceiver=ioParms.GetObject(); XBOX::VJSObject pHandler(pReceiver); ioParms.GetPropertyValue().GetObject(pHandler, NULL); if(pHandler.IsFunction() && inXhr) { XBOX::VError res=inXhr->OnReadyStateChange(pReceiver, pHandler); if(res!=XBOX::VE_OK) XBOX::vThrowError(res); } else XBOX::vThrowError(VE_XHRQ_JS_BINDING_ERROR); return true; //todo - mouai, voir ca de plus pres... }
void ComuactivClientSlot::ComuactivClientSlotImpl::stageTwo(std::string mediumPort, std::string lowPort) { mediumPort_ = mediumPort; medium_ = ProxyChannel(Channel::ACTIVE); medium_.setHost(host_); medium_.setPort(mediumPort); medium_.start(); lowPortActive_ = lowPort; aLow_ = ProxyChannel(Channel::ACTIVE); aLow_.setHost(host_); aLow_.setPort(lowPort); aLow_.start(); high_.switchMode(); high_.registerHandler( messages::Message::FLOW_TABLE_ENTRY_UPDATE, pHandler( new FlowTableEntryUpdateHandler(table_) ) ); high_.start(); stageThree(); }
int main(int argc, char* argv[]) { std::string compassRoot = cc::util::binaryPathToInstallDir(argv[0]); const std::string PARSER_PLUGIN_DIR = compassRoot + "/lib/parserplugin"; const std::string SQL_DIR = compassRoot + "/share/codecompass/sql"; cc::util::initLogger(); //--- Process command line arguments ---// po::options_description desc = commandLineArguments(); po::variables_map vm; po::store(po::command_line_parser(argc, argv) .options(desc).allow_unregistered().run(), vm); //--- Skip parser list ---// std::vector<std::string> skipParserList; if (vm.count("skip")) skipParserList = vm["skip"].as<std::vector<std::string>>(); //--- Load parsers ---// cc::parser::PluginHandler pHandler(PARSER_PLUGIN_DIR); pHandler.loadPlugins(skipParserList); //--- Add arguments of parsers ---// po::options_description pluginOptions = pHandler.getOptions(); desc.add(pluginOptions); po::store(po::parse_command_line(argc, argv, desc), vm); if (argc < 2 || vm.count("help")) { std::cout << desc << std::endl; return 0; } if (vm.count("loglevel")) { trivial::severity_level loglevel = vm["loglevel"].as<trivial::severity_level>(); boost::shared_ptr<boost::log::core> logger = boost::log::core::get(); logger->set_filter(boost::log::expressions::attr< trivial::severity_level>("Severity") >= loglevel); logger->add_global_attribute("Severity", boost::log::attributes::mutable_constant<trivial::severity_level>( loglevel)); } if (vm.count("list")) { std::cout << "Available plugins:" << std::endl; for (const std::string& pluginName : pHandler.getPluginNames()) std::cout << " - " << pluginName << std::endl; return 0; } try { po::notify(vm); } catch (const po::error& e) { LOG(error) << "Error in command line arguments: " << e.what(); return 1; } //--- Check database and project directory existence ---// bool isNewDb = cc::util::connectDatabase( vm["database"].as<std::string>(), false) == nullptr; bool isNewProject = !checkProjectDir(vm); if ((isNewProject ^ isNewDb) && !vm.count("force")) { LOG(error) << "Database and working directory existence are inconsistent. " "Use -f for reparsing!"; return 1; } if (!isNewDb && !vm.count("force")) { LOG(info) << "Project already exists, incremental parsing in action" << (vm.count("dry-run") ? " (DRY RUN)" : "") << "."; } if (isNewDb && vm.count("dry-run")) { LOG(error) << "Dry-run can be only used with incremental parsing, " "no project found. Try turning --dry-run off."; return 1; } //--- Prepare workspace and project directory ---// std::string projDir = prepareProjectDir(vm); if (projDir.empty()) return 1; //--- Create and init database ---// std::shared_ptr<odb::database> db = cc::util::connectDatabase( vm["database"].as<std::string>(), true); std::unordered_map<std::string, cc::parser::IncrementalStatus> fileStatus; if (!db) { LOG(error) << "Couldn't connect to database. Check the connection string. " "Connection string format: \"" + cc::util::getDbDriver() + ":<opt1>=<val1>;<opt2>=<val2>...\""; return 1; } if (vm.count("force")) cc::util::removeTables(db, SQL_DIR); if (vm.count("force") || isNewDb) cc::util::createTables(db, SQL_DIR); //--- Start parsers ---// cc::parser::SourceManager srcMgr(db); cc::parser::ParserContext ctx(db, srcMgr, compassRoot, vm); pHandler.createPlugins(ctx); // TODO: Handle errors returned by preparse(). std::vector<std::string> topologicalOrder = pHandler.getTopologicalOrder(); for (auto it = topologicalOrder.rbegin(); it != topologicalOrder.rend(); ++it) { LOG(info) << "[" << *it << "] preparse started!"; if (!pHandler.getParser(*it)->preparse(vm.count("dry-run"))) { LOG(error) << "[" << *it << "] preparse failed!"; return 2; } } if (vm.count("dry-run")) { incrementalList(ctx); } else { incrementalCleanup(ctx); // TODO: Handle errors returned by parse(). for (const std::string& parserName : pHandler.getTopologicalOrder()) { LOG(info) << "[" << parserName << "] parse started!"; pHandler.getParser(parserName)->parse(); } } //--- Add indexes to the database ---// if (vm.count("force") || isNewDb) cc::util::createIndexes(db, SQL_DIR); //--- Create project config file ---// boost::property_tree::ptree pt; if (vm.count("label")) { boost::property_tree::ptree labels; for (const std::string& label : vm["label"].as<std::vector<std::string>>()) { std::size_t pos = label.find('='); if (pos == std::string::npos) LOG(warning) << "Label doesn't contain '=' for separating label and the path: " << label; else labels.put(label.substr(0, pos), label.substr(pos + 1)); } pt.add_child("labels", labels); } std::string database = cc::util::connStrComponent(vm["database"].as<std::string>(), "database"); pt.put( "database", database.empty() ? vm["name"].as<std::string>() : database); if (vm.count("description")) pt.put("description", vm["description"].as<std::string>()); boost::property_tree::write_json(projDir + "/project_info.json", pt); // TODO: Print statistics. return 0; }
int ehttp:: parse_request( int fd, void *cookie ) { int (*pHandler)(ehttp &obj, void *cookie)=NULL; /* Things in the object which must be reset for each request */ filename=""; localFD=fd; ptheCookie=cookie; filetype=EHTTP_TEXT_FILE; url_parms.clear(); post_parms.clear(); multiform_chunks.clear(); request_header.clear(); replace_token.clear(); contentlength=0; // Loop Through and free/clear our post_chunks DWORD chunkCount = post_chunks.size(); for(int i = 0; i < (int)chunkCount; i++) { DWORD entryCount = post_chunks.at(i).Entries.size(); for(int x = 0; x < (int)entryCount; x++) { post_chunks.at(i).Entries.at(x).Parameters.clear(); } post_chunks.at(i).Entries.clear(); } post_chunks.clear(); string header; //string message; MemoryBuffer memBuffer; if( read_header(fd,cookie, header, memBuffer) == EHTTP_ERR_OK ) if( parse_header(cookie,header) == EHTTP_ERR_OK ) if( parse_message(fd,cookie, memBuffer) == EHTTP_ERR_OK ) { // We are HTTP1.0 and need the content len to be valid // Opera Broswer if( contentlength==0 && requesttype==EHTTP_REQUEST_POST ) { return out_commit(EHTTP_LENGTH_REQUIRED); } //Call the default handler if we didn't get the filename out_buffer_clear(); if( pPreRequestHandler ) pPreRequestHandler( *this, ptheCookie ); if( !filename.length() ) { DebugMsg( "HTTPServer-embed","%d Call default handler no filename \r\n",__LINE__); return pDefaultHandler( *this, ptheCookie ); } else { //Lookup the handler function fo this filename pHandler=handler_map[filename]; //Call the default handler if we didn't get the filename if( !pHandler ) { DebugMsg( "HTTPServer-embed","%d Call default handler\r\n",__LINE__); return pDefaultHandler( *this, ptheCookie ); } //Found a handler else { DebugMsg( "HTTPServer-embed","%d Call user handler\r\n",__LINE__); return pHandler( *this, ptheCookie ); } } } DebugMsg( "HTTPServer-embed","Error parsing request\r\n"); return EHTTP_ERR_GENERIC; }