int main() { auto adam=Person::makePerson("Adam"); adam->print(std::cout); auto eve=Person::makePerson("Eve"); eve->print(std::cout); addson("Cain",adam, eve); addson("Abel",adam, eve); addson("Seth",adam, eve); adam->print(std::cout); eve->print(std::cout); // how to have Cain kill Abel? { auto abel=eve->findChild("Abel"); eve->killChild(abel); adam->killChild(abel); abel->print(std::cout); } eve->print(std::cout); // how can we kill Adam and Eve? { adam->killMe(); adam->print(std::cout); adam.reset(); } eve->print(std::cout); auto cain=eve->findChild("Cain"); if (cain) cain->print(std::cout); eve->killMe(); // avoid memory leak eve->print(std::cout); eve.reset(); }
void AmmoAFK47::onCollision(SpaceObject* with, Vector2f const& location, Vector2f const& direction, Vector2f const& velocity) { float strength = (velocity-velocity_).length(); if (strength > 50.f) { switch (with->type()) { case spaceObjects::oShip: sound::playSound(sound::LaserCollide, location, (strength-50)/3); break; case spaceObjects::oBall: sound::playSound(sound::LaserCollide, location, (strength-50)/3); break; case spaceObjects::oPlanet: case spaceObjects::oHome: sound::playSound(sound::LaserCollide, location, (strength-50)/3); break; case spaceObjects::oSun: sound::playSound(sound::LaserCollide, location, (strength-50)/3); break; default:; } } if (with->type() != spaceObjects::oMiniAmmoFlubba) killMe(); }
void unixUsbDriver::usbSendControl(uint8_t RequestType, uint8_t Request, uint16_t Value, uint16_t Index, uint16_t Length, unsigned char *LDATA){ //qDebug("Sending Control packet! 0x%x,\t0x%x,\t%u,\t%u,\t%d,\t%u", RequestType, Request, Value, Index, LDATA, Length); unsigned char *controlBuffer; if(!connected){ qDebug() << "Control packet requested before device has connected!"; return; } if (LDATA==NULL){ controlBuffer = inBuffer; } else controlBuffer = LDATA; int error = libusb_control_transfer(handle, RequestType, Request, Value, Index, controlBuffer, Length, 4000); if(error<0){ qDebug() << "Error number:" << error; qDebug("unixUsbDriver::usbSendControl FAILED with error %s", libusb_error_name(error)); } //else qDebug() << "unixUsbDriver::usbSendControl SUCCESS"; if((error == LIBUSB_ERROR_NO_DEVICE) && (Request!=0xa7)){ //Bootloader Jump won't return; this is expected behaviour. qDebug() << "Device not found. Becoming an hero."; connectedStatus(false); killMe(); } return; }
void MfConnection::killMe() { if (state == StateWaitingSession) { // Unable to delete the instance before the session creation is done QTimer::singleShot(10, this, SLOT(killMe())); } else { // Schedule the deletion deleteLater(); } }
MfConnection::MfConnection(QLocalSocket *connection, QObject *parent) : QObject(parent), state(StateClientSetup), socket(connection), session(NULL), clientFeedbackProtocolVersion(Unknown) { // Let's reparent the connect and take the ownership instead of // the QLocalServer to avoid double delete of the object socket->setParent(this); connect(socket, SIGNAL(readyRead()), SLOT(readSocketData())); // The deleteLater() signal triggers the deletion of the MfConnection // object along with the associated socket (QLocalSocket) instance. // Let's use the killMe wrapper function because the deletion can be triggered during // session setup if the sample upload in the backend uses a // local main loop and goes to deadlock. connect(socket, SIGNAL(disconnected()), SLOT(killMe())); if (socket->bytesAvailable() > 0) { // Avoid the setup during the ctor call setup(); } }