bool FareTicket::isAvailable(const graph::ServicePointer* newService, const graph::ServicePointer* lastService) { if((newService == NULL) || (_fare == NULL) || (!_available)) return false; // test continuity if(_fare->isRequiredContinuity() && lastService != NULL && lastService != getLastService()) { return false; } // test the number of permitted connections if(_fare->getPermittedConnectionsNumber() && _fare->getPermittedConnectionsNumber() <= getNumberOfConnections()) { return false; } // test validity period of the ticket boost::posix_time::time_duration period = newService->getArrivalDateTime() - getStartTime(); if(_fare->getValidityPeriod() < period.minutes()) return false; return true; }
// TODO: Still need to close connections that we kick out! int indexOfNewConnection(struct protocolAndAddress* connection) { int connectionIndex = indexForNewConnection(); connections[connectionIndex] = *connection; connections[connectionIndex].use = 1; printf("Now have %d connections.\n", getNumberOfConnections()); return connectionIndex; }