void Settings::makeSettingsCache(const QString &groupPath, GroupPathCache &groupPathCache, ConfigOptionGroup *group) { ConfigOption *option; for (ConfigOptionGroup::size_type i = 0, size = group->size(); i < size; ++i) if ((option = group->at(i))->type() == ConfigOption::Value) { Q_ASSERT_X(!m_cache.contains(static_cast<ConfigOptionValue*>(option)->id()), "Settings::makeSettingsCache", "Settings can not have same id"); m_cache[static_cast<ConfigOptionValue*>(option)->id()] = CacheEntry(static_cast<ConfigOptionValue*>(option), groupPath); } else makeSettingsCache(QString(groupPath).append(QChar(L'.')).append(option->title()), groupPathCache, static_cast<ConfigOptionGroup*>(option)); }
bool ConfigBase::set_deserialize(const t_config_option_key &opt_key, std::string str) { const ConfigOptionDef* optdef = this->def->get(opt_key); if (optdef == NULL) throw "Calling set_deserialize() on unknown option"; if (!optdef->shortcut.empty()) { for (std::vector<t_config_option_key>::const_iterator it = optdef->shortcut.begin(); it != optdef->shortcut.end(); ++it) { if (!this->set_deserialize(*it, str)) return false; } return true; } ConfigOption* opt = this->option(opt_key, true); assert(opt != NULL); return opt->deserialize(str); }
void Settings::writeSettingsValues(const QString &path, ConfigOptionGroup *group) { ConfigOption *option; m_storage.beginGroup(path); for (ConfigOptionGroup::size_type i = 0, size = group->size(); i < size; ++i) if ((option = group->at(i))->type() == ConfigOption::Value) m_storage.setValue(option->title(), static_cast<ConfigOptionValue*>(option)->editorValue()); else { m_storage.endGroup(); writeSettingsValues(QString(path).append(QChar(L'.')).append(option->title()), static_cast<ConfigOptionGroup*>(option)); m_storage.beginGroup(path); } m_storage.endGroup(); }
int main(int argc, const char **argv) { print_stats.Enable(); Vector<const char*> unspecified; bool parsed = Config::Parse(argc, argv, &unspecified); if (!parsed || unspecified.Size() != 1) { Config::PrintUsage(USAGE); return 1; } const char *file = unspecified[0]; Xdb *xdb = new Xdb(file, false, false, true); if (!xdb->Exists()) { delete xdb; return 0; } if (print_stats.IsSpecified()) { xdb->PrintStats(); delete xdb; return 0; } Buffer key; for (uint32_t stream = xdb->MinDataStream(); stream <= xdb->MaxDataStream(); stream++) { key.Reset(); xdb->LookupKey(stream, &key); Assert(ValidString(key.base, key.pos - key.base)); logout << (const char*) key.base << endl; } delete xdb; return 0; }
void Settings::readSettingsValues(const QString &path, ConfigOptionGroup *group) { QVariant value; ConfigOption *option; m_storage.beginGroup(path); for (ConfigOptionGroup::size_type i = 0, size = group->size(); i < size; ++i) if ((option = group->at(i))->type() == ConfigOption::Value) { if ((value = m_storage.value(option->title())).isNull()) m_storage.setValue(option->title(), value = static_cast<ConfigOptionValue*>(option)->defaultValue()); static_cast<ConfigOptionValue*>(option)->setLoadedEditorValue(value); } else { m_storage.endGroup(); readSettingsValues(QString(path).append(QChar(L'.')).append(option->title()), static_cast<ConfigOptionGroup*>(option)); m_storage.beginGroup(path); } m_storage.endGroup(); }
bool CheckFrame(CheckerState *state, CheckerFrame *frame, CheckerPropagate *propagate) { Assert(!state->GetReportKind()); BlockMemory *mcfg = frame->Memory(); BlockCFG *cfg = mcfg->GetCFG(); BlockId *id = cfg->GetId(); if (checker_verbose.IsSpecified()) { logout << "CHECK: " << frame << ": Entering " << id << endl; if (propagate) propagate->Print(); } Where *where = propagate ? propagate->m_where : NULL; // check if we should terminate the search at this point (with or without // generating a report). if (where && where->IsNone()) { WhereNone *nwhere = where->AsNone(); ReportKind kind = nwhere->GetReportKind(); if (kind == RK_None) { if (checker_verbose.IsSpecified()) logout << "CHECK: " << frame << ": Ignoring" << endl; return false; } else { if (checker_verbose.IsSpecified()) logout << "CHECK: " << frame << ": Propagation failed" << endl; state->SetReport(kind); return true; } } // check for other propagations on the stack with frames for the same block, // and block the recursion if we exceed the checker's depth. we assume that // if we're ever going to terminate in the presence of recursion, we will // do so quickly. if (propagate) { if (uint32_t depth = checker_depth.UIntValue()) { Vector<CheckerFrame*> recurse_frames; for (size_t ind = 0; ind < state->m_stack.Size(); ind++) { CheckerFrame *other_frame = state->m_stack[ind]->m_frame; if (other_frame != frame && other_frame->Memory() == mcfg && !recurse_frames.Contains(other_frame)) recurse_frames.PushBack(other_frame); } if (recurse_frames.Size() >= depth) { state->SetReport(RK_Recursion); return true; } } } // check if we are propagating into some callee. if (where && where->IsPostcondition()) { WherePostcondition *nwhere = where->AsPostcondition(); // expand the callee at the specified point. PPoint point = nwhere->GetPoint(); PEdge *edge = cfg->GetSingleOutgoingEdge(point); if (edge->IsLoop()) { // expanding data from a loop. first try the case that the loop // does not execute at all. if (checker_verbose.IsSpecified()) logout << "CHECK: " << frame << ": Trying to skip loop at " << point << endl; state->PushContext(); if (CheckSkipLoop(state, frame, point, nwhere)) return true; state->PopContext(); } if (BlockId *callee = edge->GetDirectCallee()) { // easy case, there is only a single callee. if (checker_verbose.IsSpecified()) logout << "CHECK: " << frame << ": Expanding single callee at " << point << ": " << callee << endl; state->PushContext(); if (CheckSingleCallee(state, frame, point, nwhere, callee, true)) return true; state->PopContext(); } else { // iterate through all the possible callees Variable *function = id->BaseVar(); CallEdgeSet *callees = CalleeCache.Lookup(function); Vector<Variable*> callee_vars; if (callees) { for (size_t eind = 0; eind < callees->GetEdgeCount(); eind++) { const CallEdge &edge = callees->GetEdge(eind); if (edge.where.id == id && edge.where.point == point) callee_vars.PushBack(edge.callee); } } SortVector<Variable*,Variable>(&callee_vars); for (size_t cind = 0; cind < callee_vars.Size(); cind++) { Variable *callee = callee_vars[cind]; if (checker_verbose.IsSpecified()) logout << "CHECK: " << frame << ": Expanding indirect callee at " << point << ": " << callee << endl; callee->IncRef(); BlockId *callee_id = BlockId::Make(B_Function, callee); state->PushContext(); if (CheckSingleCallee(state, frame, point, nwhere, callee_id, false)) { CalleeCache.Release(function); return true; } state->PopContext(); } if (callee_vars.Empty()) { if (checker_verbose.IsSpecified()) logout << "CHECK: " << frame << ": No callees to expand at " << point << endl; } CalleeCache.Release(function); } return false; } // any precondition we have to propagate up to the callers. WherePrecondition *precondition = NULL; if (where) precondition = where->IfPrecondition(); // whether we will be reconnecting to the caller without any // propagation information. bool reconnect_caller = false; if (precondition) { Bit *bit = precondition->GetBit(); WherePrecondition *dupe_precondition = new WherePrecondition(mcfg, bit); state->m_precondition_list.PushBack(dupe_precondition); } else { // we will propagate to the caller regardless if there is already a caller // hooked up or if we are inside a loop body. if (frame->GetCaller().id != NULL) reconnect_caller = true; if (frame->Kind() == B_Loop) reconnect_caller = true; } if (propagate && reconnect_caller) { // check to see if we are delaying any heap propagation. if (where->IsInvariant()) { Assert(state->m_delayed_propagate_heap == NULL); state->m_delayed_propagate_heap = propagate; } } else if (!precondition && !reconnect_caller) { // check to see if we are performing heap propagation. if (state->m_delayed_propagate_heap) { Assert(propagate == NULL); CheckerPropagate *heap_propagate = state->m_delayed_propagate_heap; state->m_delayed_propagate_heap = NULL; WhereInvariant *invariant = heap_propagate->m_where->AsInvariant(); if (CheckHeapWrites(state, frame, heap_propagate->m_frame, invariant)) return true; state->m_delayed_propagate_heap = heap_propagate; return false; } else if (where && where->IsInvariant()) { return CheckHeapWrites(state, frame, frame, where->AsInvariant()); } Assert(propagate); // don't need to expand the callers or anything else. // we can finally terminate propagation with an error report. if (checker_verbose.IsSpecified()) logout << "CHECK: " << frame << ": Nothing to expand, finishing" << endl; state->SetReport(RK_Finished); return true; } if (frame->GetCaller().id != NULL) { // just propagate to the existing caller. if (checker_verbose.IsSpecified()) logout << "CHECK: " << frame << ": Returning to caller" << endl; state->PushContext(); if (CheckSingleCaller(state, frame, precondition, frame->GetCaller())) return true; state->PopContext(); } else if (id->Kind() == B_Function) { // propagate to all callers to the function. Variable *function = id->BaseVar(); CallEdgeSet *callers = CallerCache.Lookup(function); Vector<BlockPPoint> caller_points; for (size_t eind = 0; callers && eind < callers->GetEdgeCount(); eind++) { const CallEdge &edge = callers->GetEdge(eind); Assert(edge.callee == function); caller_points.PushBack(edge.where); } SortVector<BlockPPoint,BlockPPoint>(&caller_points); for (size_t cind = 0; cind < caller_points.Size(); cind++) { BlockPPoint caller = caller_points[cind]; if (checker_verbose.IsSpecified()) logout << "CHECK: " << frame << ": Checking caller: " << caller << endl; state->PushContext(); if (CheckSingleCaller(state, frame, precondition, caller)) { CallerCache.Release(function); return true; } state->PopContext(); } if (caller_points.Empty()) { if (checker_verbose.IsSpecified()) logout << "CHECK: " << frame << ": No callers to expand" << endl; } CallerCache.Release(function); } else if (id->Kind() == B_Loop) { // check all possible callers of the loop. unroll an iteration before // checking the parents so that if we can't figure out a sufficient // condition for the loop we will stop exploration quickly. // unroll another iteration of the loop. if (checker_verbose.IsSpecified()) logout << "CHECK: " << frame << ": Unrolling loop iteration" << endl; state->PushContext(); BlockPPoint recursive_caller(id, cfg->GetExitPoint()); if (CheckSingleCaller(state, frame, precondition, recursive_caller)) return true; state->PopContext(); // check the parents which can initially invoke this loop. if (frame->GetLoopParent().id != NULL) { if (checker_verbose.IsSpecified()) logout << "CHECK: " << frame << ": Checking existing loop parent: " << frame->GetLoopParent() << endl; state->PushContext(); if (CheckSingleCaller(state, frame, precondition, frame->GetLoopParent())) return true; state->PopContext(); } else { for (size_t pind = 0; pind < cfg->GetLoopParentCount(); pind++) { BlockPPoint where = cfg->GetLoopParent(pind); if (checker_verbose.IsSpecified()) logout << "CHECK: " << frame << ": Checking loop parent: " << where << endl; state->PushContext(); if (CheckSingleCaller(state, frame, precondition, where)) return true; state->PopContext(); } } } else if (id->Kind() == B_Initializer) { // initializers don't have callers, can just ignore this. // TODO: should address why this code is being reached in the first place. if (checker_verbose.IsSpecified()) logout << "CHECK: " << frame << ": Initializer has no callers" << endl; return false; } else { // unknown type of block. Assert(false); } // if we set the state's delayed heap propagation then unset it. if (propagate && state->m_delayed_propagate_heap == propagate) state->m_delayed_propagate_heap = NULL; return false; }
bool operator== (const ConfigOption &a, const ConfigOption &b) { return a.serialize().compare(b.serialize()) == 0; }
int main(int argc, const char **argv) { plain_text.Enable(); raw_tags.Enable(); Vector<const char*> unspecified; bool parsed = Config::Parse(argc, argv, &unspecified); if (!parsed || unspecified.Size() != 2) { Config::PrintUsage(USAGE); return 1; } // we're only doing one access, we don't need the key cache Xdb::DisableKeyCache(); AnalysisPrepare(); const char *file = unspecified[0]; const char *key = unspecified[1]; Xdb *xdb = new Xdb(file, false, false, true); if (!xdb->Exists()) { delete xdb; return 0; } Buffer bkey((const uint8_t*) key, strlen(key) + 1); Buffer cdata; Buffer bdata; bool success = xdb->Find(&bkey, &cdata); if (success) { UncompressBufferInUse(&cdata, &bdata); size_t len = bdata.pos - bdata.base; if (plain_text.IsSpecified()) { for (size_t n = 0; n < len; n++) logout << (char) bdata.base[n]; logout << endl; } else if (raw_tags.IsSpecified()) { size_t consumed = 0; while (consumed != len) { Buffer parse_data(bdata.base + consumed, len - consumed); parse_data.pos += len - consumed; size_t read_len = PrintPartialBuffer(&parse_data); if (read_len == 0) break; consumed += read_len; } } else { Buffer read_buf(bdata.base, len); while (read_buf.pos != read_buf.base + len) { HashObject *value = ReadSingleValue(&read_buf); logout << value << endl; } } } delete xdb; ClearBlockCaches(); ClearMemoryCaches(); AnalysisFinish(0); }
int main(int argc, const char **argv) { spawn_command.Enable(); spawn_count.Enable(); terminate_on_assert.Enable(); #ifdef USE_COUNT_ALLOCATOR memory_limit.Enable(); #endif modset_wait.Enable(); Vector<const char*> unspecified; bool parsed = Config::Parse(argc, argv, &unspecified); if (!parsed || !unspecified.Empty()) { Config::PrintUsage(USAGE); return 1; } AnalysisPrepare(); // use a different handler for termination signals. signal(SIGINT, termination_handler); signal(SIGTERM, termination_handler); // xmanager failures are unrecoverable. g_pause_assertions = true; if (terminate_on_assert.IsSpecified()) { g_pause_assertions = false; } int ret; event_init(); server_socket = socket(PF_INET, SOCK_STREAM, 0); if (server_socket == -1) { logout << "ERROR: socket() failure: " << errno << endl; return 1; } struct sockaddr_in addr; memset(&addr, 0, sizeof(addr)); ret = bind(server_socket, (sockaddr*) &addr, sizeof(addr)); if (ret == -1) { logout << "ERROR: bind() failure: " << errno << endl; return 1; } int optval = 1; ret = setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)); if (ret == -1) { logout << "ERROR: setsockopt() failure: " << errno << endl; return 1; } int oldcode = fcntl(server_socket, F_GETFL, 0); if (oldcode == -1) { logout << "ERROR: fcntl() failure: " << errno << endl; return 1; } ret = fcntl(server_socket, F_SETFL, oldcode | O_NONBLOCK); if (ret == -1) { logout << "ERROR: fcntl() failure: " << errno << endl; return 1; } ret = listen(server_socket, 200); if (ret == -1) { logout << "ERROR: listen() failure: " << errno << endl; return 1; } event_set(&connect_event, server_socket, EV_READ | EV_PERSIST, handle_connect, NULL); ret = event_add(&connect_event, NULL); if (ret == -1) { logout << "ERROR: event_add() failure: " << errno << endl; return 1; } char hostbuf[256]; unsigned short port; bool hostret = GetCurrentHost(server_socket, hostbuf, sizeof(hostbuf), &port); if (!hostret) return 1; logout << "Listening on " << hostbuf << ":" << port << endl << flush; // spawn the child processes if needed. this is done with a system() // call, in the expectation the call will either fork a new process // on this machine, or start up a process on another machine. if (spawn_count.IsSpecified()) { if (!spawn_command.IsSpecified()) { logout << "ERROR: -spawn-count must be used with -spawn-command" << endl; Config::PrintUsage(USAGE); return 1; } Buffer command_buf; BufferOutStream out(&command_buf); out << spawn_command.StringValue() << " -remote=" << hostbuf << ":" << port << '\0'; const char *command = (const char*) command_buf.base; for (size_t ind = 0; ind < spawn_count.UIntValue(); ind++) { int ret = system(command); if (ret != 0) { logout << "ERROR: Spawn command failed: " << command << endl; return 1; } else { logout << "Command process spawned" << endl; } // we will not receive an initial transaction from these workers. received_initial++; } } ret = event_dispatch(); if (ret == -1) { logout << "ERROR: event_dispatch() failure: " << errno << endl; return 1; } Assert(false); }
void handle_event(int fd, short, void *v) { bool success; size_t index = (size_t) v; Assert(index < connections.Size()); ConnectData *cdata = connections[index]; Assert(cdata->live); if (cdata->write_buf.size != 0) { success = WritePacket(fd, &cdata->write_buf); if (success) { cdata->write_buf.base = NULL; cdata->write_buf.pos = NULL; cdata->write_buf.size = 0; } } else { size_t length = cdata->read_buf.pos - cdata->read_buf.base; success = ReadPacket(fd, &cdata->read_buf); if (success) { size_t data_length = cdata->read_buf.pos - cdata->read_buf.base - UINT32_LENGTH; Buffer transaction_buf(cdata->read_buf.base + UINT32_LENGTH, data_length); Transaction *t = new Transaction(); if (!t->Read(&transaction_buf)) { logout << "ERROR: Corrupt packet data" << endl; delete t; return; } handling_transaction = true; t->Execute(); cdata->read_buf.pos = cdata->read_buf.base; cdata->read_buf.Ensure(UINT32_LENGTH); cdata->read_buf.pos += UINT32_LENGTH; t->WriteResult(&cdata->read_buf); cdata->write_buf.base = cdata->read_buf.base; cdata->write_buf.pos = cdata->write_buf.base; cdata->write_buf.size = cdata->read_buf.pos - cdata->read_buf.base; cdata->read_buf.pos = cdata->read_buf.base; success = WritePacket(fd, &cdata->write_buf); if (success) { cdata->write_buf.base = NULL; cdata->write_buf.pos = NULL; cdata->write_buf.size = 0; } // watch for initial and final transactions. if (t->IsInitial()) { Assert(!spawn_count.IsSpecified()); received_initial++; } if (t->IsFinal()) { Assert(received_final < received_initial); received_final++; if (received_final == received_initial) { // this was the last client, so cleanup and exit. logout << "Final transaction received, finishing..." << endl << flush; close(server_socket); ClearBlockCaches(); ClearMemoryCaches(); AnalysisFinish(0); } } delete t; handling_transaction = false; } else if ((ssize_t) length == cdata->read_buf.pos - cdata->read_buf.base) { // connection is closed. there is nothing to read so remove the event. event_del(&cdata->ev); close(cdata->fd); cdata->live = false; cdata->read_buf.Reset(0); cdata->write_buf.Reset(0); } } }
void Config::registerAlias ( const std::string &optionName, const std::string &alias, const std::string &helpMessage ) { ConfigOption *option = _configOptions[optionName]; ConfigOption *aliasOption = NEW ConfigOption( alias, option->getOption(), helpMessage, _currentSection ); _configOptions[alias] = aliasOption; }
void AtlantikNetwork::processNode(QDomNode n) { QDomAttr a; for ( ; !n.isNull() ; n = n.nextSibling() ) { QDomElement e = n.toElement(); if(!e.isNull()) { if (e.tagName() == "server") { a = e.attributeNode( QString("version") ); if ( !a.isNull() ) m_serverVersion = a.value(); emit receivedHandshake(); } else if (e.tagName() == "msg") { a = e.attributeNode(QString("type")); if (!a.isNull()) { if (a.value() == "error") emit msgError(e.attributeNode(QString("value")).value()); else if (a.value() == "info") emit msgInfo(e.attributeNode(QString("value")).value()); else if (a.value() == "chat") emit msgChat(e.attributeNode(QString("author")).value(), e.attributeNode(QString("value")).value()); } } else if (e.tagName() == "display") { int estateId = -1; a = e.attributeNode(QString("estateid")); if (!a.isNull()) { estateId = a.value().toInt(); Estate *estate; estate = m_atlanticCore->findEstate(a.value().toInt()); emit displayDetails(e.attributeNode(QString("text")).value(), e.attributeNode(QString("cleartext")).value().toInt(), e.attributeNode(QString("clearbuttons")).value().toInt(), estate); bool hasButtons = false; for( QDomNode nButtons = n.firstChild() ; !nButtons.isNull() ; nButtons = nButtons.nextSibling() ) { QDomElement eButton = nButtons.toElement(); if (!eButton.isNull() && eButton.tagName() == "button") { emit addCommandButton(eButton.attributeNode(QString("command")).value(), eButton.attributeNode(QString("caption")).value(), eButton.attributeNode(QString("enabled")).value().toInt()); hasButtons = true; } } if (!hasButtons) emit addCloseButton(); } } else if (e.tagName() == "client") { a = e.attributeNode(QString("playerid")); if (!a.isNull()) m_playerId = a.value().toInt(); a = e.attributeNode(QString("cookie")); if (!a.isNull()) emit clientCookie(a.value()); } else if (e.tagName() == "configupdate") { int configId = -1; a = e.attributeNode(QString("configid")); if (!a.isNull()) { configId = a.value().toInt(); ConfigOption *configOption; if (!(configOption = m_atlanticCore->findConfigOption(configId))) configOption = m_atlanticCore->newConfigOption( configId ); a = e.attributeNode(QString("name")); if (configOption && !a.isNull()) configOption->setName(a.value()); a = e.attributeNode(QString("description")); if (configOption && !a.isNull()) configOption->setDescription(a.value()); a = e.attributeNode(QString("edit")); if (configOption && !a.isNull()) configOption->setEdit(a.value().toInt()); a = e.attributeNode(QString("value")); if (configOption && !a.isNull()) configOption->setValue(a.value()); if (configOption) configOption->update(); } int gameId = -1; a = e.attributeNode(QString("gameid")); if (!a.isNull()) { gameId = a.value().toInt(); for( QDomNode nOptions = n.firstChild() ; !nOptions.isNull() ; nOptions = nOptions.nextSibling() ) { QDomElement eOption = nOptions.toElement(); if (!eOption.isNull() && eOption.tagName() == "option") emit gameOption(eOption.attributeNode(QString("title")).value(), eOption.attributeNode(QString("type")).value(), eOption.attributeNode(QString("value")).value(), eOption.attributeNode(QString("edit")).value(), eOption.attributeNode(QString("command")).value()); } emit endConfigUpdate(); } } else if (e.tagName() == "deletegame") { a = e.attributeNode(QString("gameid")); if (!a.isNull()) { int gameId = a.value().toInt(); Game *game = m_atlanticCore->findGame(gameId); if (game) m_atlanticCore->removeGame(game); } } else if (e.tagName() == "gameupdate") { int gameId = -1; a = e.attributeNode(QString("gameid")); if (!a.isNull()) { gameId = a.value().toInt(); Player *playerSelf = m_atlanticCore->playerSelf(); if ( playerSelf && playerSelf->game() ) kdDebug() << "gameupdate for " << QString::number(gameId) << " with playerSelf in game " << QString::number(playerSelf->game()->id()) << endl; else kdDebug() << "gameupdate for " << QString::number(gameId) << endl; Game *game = 0; if (gameId == -1) { a = e.attributeNode(QString("gametype")); if ( !a.isNull() && !(game = m_atlanticCore->findGame(a.value())) ) game = m_atlanticCore->newGame(gameId, a.value()); } else if (!(game = m_atlanticCore->findGame(gameId))) game = m_atlanticCore->newGame(gameId); a = e.attributeNode(QString("canbejoined")); if (game && !a.isNull()) game->setCanBeJoined(a.value().toInt()); a = e.attributeNode(QString("description")); if (game && !a.isNull()) game->setDescription(a.value()); a = e.attributeNode(QString("name")); if (game && !a.isNull()) game->setName(a.value()); a = e.attributeNode(QString("players")); if (game && !a.isNull()) game->setPlayers(a.value().toInt()); a = e.attributeNode(QString("master")); if (game && !a.isNull()) { // Ensure setMaster succeeds by creating player if necessary Player *player = m_atlanticCore->findPlayer( a.value().toInt() ); if ( !player ) player = m_atlanticCore->newPlayer( a.value().toInt() ); game->setMaster( player ); } QString status = e.attributeNode(QString("status")).value(); if ( m_serverVersion.left(4) == "0.9." || (playerSelf && playerSelf->game() == game) ) { if (status == "config") emit gameConfig(); else if (status == "init") emit gameInit(); else if (status == "run") emit gameRun(); else if (status == "end") emit gameEnd(); } if (game) game->update(); } } else if (e.tagName() == "deleteplayer") { a = e.attributeNode(QString("playerid")); if (!a.isNull()) { int playerId = a.value().toInt(); Player *player = m_atlanticCore->findPlayer(playerId); if (player) m_atlanticCore->removePlayer(player); } } else if (e.tagName() == "playerupdate") { int playerId = -1; a = e.attributeNode(QString("playerid")); if (!a.isNull()) { playerId = a.value().toInt(); Player *player; if (!(player = m_atlanticCore->findPlayer(playerId))) player = m_atlanticCore->newPlayer( playerId, (m_playerId == playerId) ); // Update player name a = e.attributeNode(QString("name")); if (player && !a.isNull()) player->setName(a.value()); // Update player game a = e.attributeNode(QString("game")); if (player && !a.isNull()) { int gameId = a.value().toInt(); if (gameId == -1) player->setGame( 0 ); else { // Ensure setGame succeeds by creating game if necessary Game *game = m_atlanticCore->findGame(a.value().toInt()); if (!game) game = m_atlanticCore->newGame(a.value().toInt()); // player->setGame( game ); } } // Update player host a = e.attributeNode(QString("host")); if (player && !a.isNull()) player->setHost(a.value()); // Update player image/token a = e.attributeNode(QString("image")); if (player && !a.isNull()) player->setImage(a.value()); // Update player money a = e.attributeNode(QString("money")); if (player && !a.isNull()) player->setMoney(a.value().toInt()); a = e.attributeNode(QString("bankrupt")); if (player && !a.isNull()) player->setBankrupt(a.value().toInt()); a = e.attributeNode(QString("hasdebt")); if (player && !a.isNull()) player->setHasDebt(a.value().toInt()); a = e.attributeNode(QString("hasturn")); if (player && !a.isNull()) player->setHasTurn(a.value().toInt()); // Update whether player can roll a = e.attributeNode(QString("can_roll")); if (player && !a.isNull()) player->setCanRoll(a.value().toInt()); // Update whether player can buy a = e.attributeNode(QString("can_buyestate")); if (player && !a.isNull()) player->setCanBuy(a.value().toInt()); // Update whether player can auction a = e.attributeNode(QString("canauction")); if (player && !a.isNull()) player->setCanAuction(a.value().toInt()); // Update whether player can use a card a = e.attributeNode(QString("canusecard")); if (player && !a.isNull()) player->setCanUseCard(a.value().toInt()); // Update whether player is jailed a = e.attributeNode(QString("jailed")); if (player && !a.isNull()) { player->setInJail(a.value().toInt()); // TODO: emit signal with player ptr so board can setText and display something } // Update player location a = e.attributeNode(QString("location")); if (!a.isNull()) { m_playerLocationMap[player] = a.value().toInt(); bool directMove = false; Estate *estate = m_atlanticCore->findEstate(a.value().toInt()); a = e.attributeNode(QString("directmove")); if (!a.isNull()) directMove = a.value().toInt(); if (player && estate) { if (directMove) player->setLocation(estate); else player->setDestination(estate); } } if (player) player->update(); } } else if (e.tagName() == "estategroupupdate") { a = e.attributeNode(QString("groupid")); if (!a.isNull()) { int groupId = a.value().toInt(); EstateGroup *estateGroup = 0; bool b_newEstateGroup = false; if (!(estateGroup = m_atlanticCore->findEstateGroup(groupId))) { // Create EstateGroup object estateGroup = m_atlanticCore->newEstateGroup(a.value().toInt()); b_newEstateGroup = true; } a = e.attributeNode(QString("name")); if (estateGroup && !a.isNull()) estateGroup->setName(a.value()); // Emit signal so GUI implementations can create view(s) // TODO: port to atlanticcore and create view there if (estateGroup) { if (b_newEstateGroup) emit newEstateGroup(estateGroup); estateGroup->update(); } } } else if (e.tagName() == "estateupdate") { int estateId = -1; a = e.attributeNode(QString("estateid")); if (!a.isNull()) { estateId = a.value().toInt(); Estate *estate = 0; bool b_newEstate = false; // FIXME: allow any estateId, GUI should not use it to determin its geometry if (estateId >= 0 && estateId < 100 && !(estate = m_atlanticCore->findEstate(a.value().toInt()))) { // Create estate object estate = m_atlanticCore->newEstate(estateId); b_newEstate = true; QObject::connect(estate, SIGNAL(estateToggleMortgage(Estate *)), this, SLOT(estateToggleMortgage(Estate *))); QObject::connect(estate, SIGNAL(estateHouseBuy(Estate *)), this, SLOT(estateHouseBuy(Estate *))); QObject::connect(estate, SIGNAL(estateHouseSell(Estate *)), this, SLOT(estateHouseSell(Estate *))); QObject::connect(estate, SIGNAL(newTrade(Player *)), this, SLOT(newTrade(Player *))); // Players without estate should get one Player *player = 0; QPtrList<Player> playerList = m_atlanticCore->players(); for (QPtrListIterator<Player> it(playerList); (player = *it) ; ++it) if (m_playerLocationMap[player] == estate->id()) player->setLocation(estate); } a = e.attributeNode(QString("name")); if (estate && !a.isNull()) estate->setName(a.value()); a = e.attributeNode(QString("color")); if (estate && !a.isNull() && !a.value().isEmpty()) estate->setColor(a.value()); a = e.attributeNode(QString("bgcolor")); if (estate && !a.isNull()) estate->setBgColor(a.value()); a = e.attributeNode(QString("owner")); Player *player = m_atlanticCore->findPlayer(a.value().toInt()); if (estate && !a.isNull()) estate->setOwner(player); a = e.attributeNode(QString("houses")); if (estate && !a.isNull()) estate->setHouses(a.value().toInt()); a = e.attributeNode(QString("mortgaged")); if (estate && !a.isNull()) estate->setIsMortgaged(a.value().toInt()); a = e.attributeNode(QString("group")); if (!a.isNull()) { EstateGroup *estateGroup = m_atlanticCore->findEstateGroup(a.value().toInt()); if (estate) estate->setEstateGroup(estateGroup); } a = e.attributeNode(QString("can_toggle_mortgage")); if (estate && !a.isNull()) estate->setCanToggleMortgage(a.value().toInt()); a = e.attributeNode(QString("can_be_owned")); if (estate && !a.isNull()) estate->setCanBeOwned(a.value().toInt()); a = e.attributeNode(QString("can_buy_houses")); if (estate && !a.isNull()) estate->setCanBuyHouses(a.value().toInt()); a = e.attributeNode(QString("can_sell_houses")); if (estate && !a.isNull()) estate->setCanSellHouses(a.value().toInt()); a = e.attributeNode(QString("price")); if (estate && !a.isNull()) estate->setPrice(a.value().toInt()); a = e.attributeNode(QString("houseprice")); if (estate && !a.isNull()) estate->setHousePrice(a.value().toInt()); a = e.attributeNode(QString("sellhouseprice")); if (estate && !a.isNull()) estate->setHouseSellPrice(a.value().toInt()); a = e.attributeNode(QString("mortgageprice")); if (estate && !a.isNull()) estate->setMortgagePrice(a.value().toInt()); a = e.attributeNode(QString("unmortgageprice")); if (estate && !a.isNull()) estate->setUnmortgagePrice(a.value().toInt()); a = e.attributeNode(QString("money")); if (estate && !a.isNull()) estate->setMoney(a.value().toInt()); // Emit signal so GUI implementations can create view(s) // TODO: port to atlanticcore and create view there if (estate) { if (b_newEstate) emit newEstate(estate); estate->update(); } } }
Expert::Expert( QWidget *parent ) : QTabDialog( parent ) { m_dependencies = new QDict< QList<IInput> >(257); m_dependencies->setAutoDelete(TRUE); m_inputWidgets = new QDict< IInput >; m_switches = new QDict< QObject >; m_changed = FALSE; setHelpButton(); QListIterator<ConfigOption> options = Config::instance()->iterator(); QVBoxLayout *pageLayout = 0; QFrame *page = 0; ConfigOption *option = 0; for (options.toFirst();(option=options.current());++options) { switch(option->kind()) { case ConfigOption::O_Info: { if (pageLayout) pageLayout->addStretch(1); QScrollView *view = new QScrollView(this); view->setVScrollBarMode(QScrollView::Auto); view->setHScrollBarMode(QScrollView::AlwaysOff); view->setResizePolicy(QScrollView::AutoOneFit); page = new QFrame( view->viewport(), option->name() ); pageLayout = new QVBoxLayout(page); pageLayout->setMargin(10); view->addChild(page); addTab(view,option->name()); QWhatsThis::add(page, option->docs().simplifyWhiteSpace() ); QToolTip::add(page, option->docs() ); } break; case ConfigOption::O_String: { ASSERT(page!=0); InputString::StringMode sm=InputString::StringFree; switch(((ConfigString *)option)->widgetType()) { case ConfigString::String: sm=InputString::StringFree; break; case ConfigString::File: sm=InputString::StringFile; break; case ConfigString::Dir: sm=InputString::StringDir; break; } InputString *inputString = new InputString( option->name(), // name page, // widget *((ConfigString *)option)->valueRef(), // variable sm // type ); pageLayout->addWidget(inputString); QWhatsThis::add(inputString, option->docs().simplifyWhiteSpace() ); QToolTip::add(inputString,option->docs()); connect(inputString,SIGNAL(changed()),SLOT(changed())); m_inputWidgets->insert(option->name(),inputString); addDependency(m_switches,option->dependsOn(),option->name()); } break; case ConfigOption::O_Enum: { ASSERT(page!=0); InputString *inputString = new InputString( option->name(), // name page, // widget *((ConfigEnum *)option)->valueRef(), // variable InputString::StringFixed // type ); pageLayout->addWidget(inputString); QStrListIterator sli=((ConfigEnum *)option)->iterator(); for (sli.toFirst();sli.current();++sli) { inputString->addValue(sli.current()); } inputString->init(); QWhatsThis::add(inputString, option->docs().simplifyWhiteSpace() ); QToolTip::add(inputString, option->docs()); connect(inputString,SIGNAL(changed()),SLOT(changed())); m_inputWidgets->insert(option->name(),inputString); addDependency(m_switches,option->dependsOn(),option->name()); } break; case ConfigOption::O_List: { ASSERT(page!=0); InputStrList::ListMode lm=InputStrList::ListString; switch(((ConfigList *)option)->widgetType()) { case ConfigList::String: lm=InputStrList::ListString; break; case ConfigList::File: lm=InputStrList::ListFile; break; case ConfigList::Dir: lm=InputStrList::ListDir; break; case ConfigList::FileAndDir: lm=InputStrList::ListFileDir; break; } InputStrList *inputStrList = new InputStrList( option->name(), // name page, // widget *((ConfigList *)option)->valueRef(), // variable lm // type ); pageLayout->addWidget(inputStrList); QWhatsThis::add(inputStrList, option->docs().simplifyWhiteSpace() ); QToolTip::add(inputStrList, option->docs()); connect(inputStrList,SIGNAL(changed()),SLOT(changed())); m_inputWidgets->insert(option->name(),inputStrList); addDependency(m_switches,option->dependsOn(),option->name()); } break; break; case ConfigOption::O_Bool: { ASSERT(page!=0); InputBool *inputBool = new InputBool( option->name(), // name page, // widget *((ConfigBool *)option)->valueRef() // variable ); pageLayout->addWidget(inputBool); QWhatsThis::add(inputBool, option->docs().simplifyWhiteSpace() ); QToolTip::add(inputBool, option->docs() ); connect(inputBool,SIGNAL(changed()),SLOT(changed())); m_inputWidgets->insert(option->name(),inputBool); addDependency(m_switches,option->dependsOn(),option->name()); } break; case ConfigOption::O_Int: { ASSERT(page!=0); InputInt *inputInt = new InputInt( option->name(), // name page, // widget *((ConfigInt *)option)->valueRef(), // variable ((ConfigInt *)option)->minVal(), // min value ((ConfigInt *)option)->maxVal() // max value ); pageLayout->addWidget(inputInt); QWhatsThis::add(inputInt, option->docs().simplifyWhiteSpace() ); QToolTip::add(inputInt, option->docs() ); connect(inputInt,SIGNAL(changed()),SLOT(changed())); m_inputWidgets->insert(option->name(),inputInt); addDependency(m_switches,option->dependsOn(),option->name()); } break; case ConfigOption::O_Obsolete: break; } } if (pageLayout) pageLayout->addStretch(1); QDictIterator<QObject> di(*m_switches); QObject *obj = 0; for (di.toFirst();(obj=di.current());++di) { connect(obj,SIGNAL(toggle(const char *,bool)),SLOT(toggle(const char *,bool))); // UGLY HACK: assumes each item depends on a boolean without checking! emit toggle(di.currentKey(),((InputBool *)obj)->getState()); } connect(this,SIGNAL(helpButtonPressed()),this,SLOT(handleHelp())); }