/* * 1 - Initialize company. * 2 - Update map. * 3 - Wake up planes. * 4 - Update planes. * 5 - Send map updates. */ void companyStart(Map* initialMap, Company* cmp) { company = cmp; sprintf(cmpSemName, "c%d", company->id); map = initialMap; initializeCompany(); updateMap(); S_POST("companyReady");// Tell the server that this company has been created. createInactivePlanesBitMask(); do { S_WAIT(cmpSemName); log_debug("[Company %d] Started turn---------------->", company->id); updateMap(); wakeUpPlanes(); waitUntilPlanesReady(); updateDestinations(); updateServer(); log_debug("[Company %d] Finished turn---------------->", company->id); S_POST("server"); } while (HAS_ACTIVE_PLANES); CompanyUpdatePackage update; update.companyId = company->id; update.status = FALSE; log_warning("Company %d died", company->id); serializer_write(&update, company->id + 1, serverId, PACKAGE_TYPE_COMPANY_UPDATE); company_free(company, TRUE); }
static void np_byte_write(void* obj, byte_array_t* bytes, size_t* offset) { neighbor_pairing_t* np = obj; // Write the name. int name_len = strlen(np->name); byte_array_write_ints(bytes, 1, &name_len, offset); byte_array_write_chars(bytes, name_len, np->name, offset); // Write the offsets, indices, weights. byte_array_write_ints(bytes, 1, &np->num_pairs, offset); byte_array_write_ints(bytes, 2*np->num_pairs, np->pairs, offset); if (np->weights != NULL) { byte_array_write_ints(bytes, 1, &np->num_pairs, offset); byte_array_write_real_ts(bytes, np->num_pairs, np->weights, offset); } else { int zero = 0; byte_array_write_ints(bytes, 1, &zero, offset); } // Exchanger. serializer_t* ser = exchanger_serializer(); serializer_write(ser, np->ex, bytes, offset); ser = NULL; }
/* * Plane is supposed to just have arrived to its target. * 1 - City needs to be updated * 2 - Sends up-date package to the server. */ void updateMapItems(Map* map, Plane* plane) { CityUpdatePackage update; for (int i = 0; i < plane->itemCount; ++i) { int cityStock = map->city[plane->cityIdFrom]->itemStock[i]; int planeStock = plane->itemStock[i]; if (cityStock < 0 && planeStock > 0) { int supplies = min(-cityStock, planeStock); plane->itemStock[i] -= supplies; map->city[plane->cityIdFrom]->itemStock[i] += supplies; update.cityId = plane->cityIdFrom; update.itemId = i; update.amount = supplies; serializer_write(&update, PLANE_COMPANY_ID(plane->id) + 1, serverId, PACKAGE_TYPE_CITY_UPDATE); } } }
void MulticastDataLink::syn_received_no_session(MulticastPeer source, ACE_Message_Block* data, bool swap_bytes) { Serializer serializer_read(data, swap_bytes); MulticastPeer local_peer; serializer_read >> local_peer; if (local_peer != local_peer_) { return; } VDBG_LVL((LM_DEBUG, "(%P|%t) MulticastDataLink[%C]::syn_received_no_session " "send_synack local 0x%x remote 0x%x\n", config_->name().c_str(), local_peer, source), 2); ACE_Message_Block* synack_data = new ACE_Message_Block(sizeof(MulticastPeer)); Serializer serializer_write(synack_data); serializer_write << source; DataSampleHeader header; ACE_Message_Block* control = create_control(MULTICAST_SYNACK, header, synack_data); const int error = send_control(header, control); if (error != SEND_CONTROL_OK) { ACE_ERROR((LM_ERROR, "(%P|%t) MulticastDataLink::syn_received_no_session: " "ERROR: send_control failed: %d!\n", error)); return; } transport_->passive_connection(local_peer, source); }
/* * Write to the server the changes on this company. * In this case we serialize the whole company. */ void updateServer() { serializer_write(company, company->id + 1, serverId, PACKAGE_TYPE_COMPANY); }