tHandle cDriverModule::CreateView() { QWidget* pWidget = (QWidget*)m_pViewport->VP_GetWindow(); m_pWidget = new DisplayWidgetDriver(pWidget); connect(m_pWidget, SIGNAL(sendStruct(stateCar, tInt16)), this, SLOT(OnSendState(stateCar, tInt16))); connect(this, SIGNAL(SendRun(int)), m_pWidget, SLOT(OnDriverGo(int))); connect(this, SIGNAL(SendStop(int)), m_pWidget, SLOT(OnDriverStop(int))); connect(this, SIGNAL(SendRequestReady(int)), m_pWidget, SLOT(OnDriverRequestReady(int))); connect(this, SIGNAL(TriggerLoadManeuverList()), this, SLOT(LoadManeuverList())); return (tHandle)m_pWidget; }
//retrieves and sends the requested flight info to the client. void handleMsg(){ loadInFile(); receive(); printf("Handling client %s\n", inet_ntoa(clntAddr.sin_addr)); if(msgFromClient.quit == TRUE){ printf("%s","Exiting Server..."); close(sock); exit(0); } int index = search(msgFromClient.flightID); if(index == -1){ msgToClient.stat = FAIL; sendStruct(); } else{ // get data out array struct flightData info = dataArray[index]; strcpy(msgToClient.flightID,info.flightID); // If the client wants the capacity if(msgFromClient.op == CAP){ if(msgFromClient.seat == ALL){ msgToClient.numberOfSeats = (info.eCap + info.pCap); msgToClient.stat = SUCCESS; } else if (msgFromClient.seat == ECONOMY){ msgToClient.numberOfSeats = info.eCap; msgToClient.stat = SUCCESS; } else if (msgFromClient.seat == PREMIUM){ msgToClient.numberOfSeats = info.pCap; msgToClient.stat = SUCCESS; } } //If the client wants seat availability else if (msgFromClient.op == AVAILABLE){ if(msgFromClient.seat == ALL){ msgToClient.numberOfSeats = (info.availEconCap + info.availPremCap); msgToClient.stat = SUCCESS; } else if (msgFromClient.seat == ECONOMY){ msgToClient.numberOfSeats = info.availEconCap; msgToClient.stat = SUCCESS; } else if (msgFromClient.seat == PREMIUM){ msgToClient.numberOfSeats = info.availPremCap; msgToClient.stat = SUCCESS; } } //If the client wants to purchase seats else if (msgFromClient.op == PURCHASE){ int toPurchase = msgFromClient.numberOfSeats; if (msgFromClient.seat == ECONOMY){ int sum = info.availEconCap - toPurchase; if(sum < 0){ msgToClient.stat = NO_SEAT; msgToClient.numberOfSeats = info.availEconCap; } else{ dataArray[index].availEconCap = sum; msgToClient.numberOfSeats = sum; msgToClient.stat = SUCCESS; } } else if (msgFromClient.seat == PREMIUM){ int sum = info.availPremCap - toPurchase; if(sum < 0){ msgToClient.stat = NO_SEAT; msgToClient.numberOfSeats = info.availPremCap; } else{ dataArray[index].availPremCap = sum; msgToClient.numberOfSeats = sum; msgToClient.stat = SUCCESS; } } } arrayToFile(); sendStruct(); } }