Beispiel #1
0
	void StoreScreen::onEvent(InventoryEvent *e)
	{
		if (!e)
		{
			return;
		}
		game::Item *item = e->getItem();
		if (!item)
		{
			return;
		}
		/*if (mBuyer && mStore)
		{
			unsigned int value = item->getItemValue();
			CoinPurse *buyerPurse = mBuyer->getCoinPurse();
			if (!buyerPurse)
			{
				am_log("STORE", "Buyer does not have a purse!");
				return;
			}
			CoinPurse *ownerPurse = mStore->getStoreOwner()->getCoinPurse();
			if (!ownerPurse)
			{
				am_log("STORE", "Owner does not have a purse!");
				return;
			}
		}*/
		// CHANGE THIS, 
		if (e->getInventoryEventType() == ui::Inventory::INVENTORY_BEFORE_REMOVE)
		{
			base::ReturnCode result = mStore->buyItem(mBuyer, e->getItem(), 1.5f);
			am_log("BUY", getErrorName(result));
			if (result != base::SUCCESS)
			{
				e->stopPropagation();
			}
		}
		else if (e->getInventoryEventType() == ui::Inventory::INVENTORY_BEFORE_ADD)
		{
			base::ReturnCode result = mStore->sellItem(mBuyer, e->getItem(), 0.75f, true, true);
			am_log("SELL", getErrorName(result));
			if (result != base::SUCCESS)
			{
				e->stopPropagation();
			}
		}
		am_log("STORE", e->getType());
	}
void
error_handler(jboolean fatal, jvmtiError error,
              const char *message, const char *file, int line)
{
    char *error_name;

    if ( message==NULL ) {
        message = "";
    }
    if ( error != JVMTI_ERROR_NONE ) {
        error_name = getErrorName(error);
        if ( error_name == NULL ) {
            error_name = "?";
        }
        error_message("HPROF ERROR: %s (JVMTI Error %s(%d)) [%s:%d]\n",
                      message, error_name, error,
                      source_basename(file), line);
    } else {
        error_message("HPROF ERROR: %s [%s:%d]\n", message,
                      source_basename(file), line);
    }
    if ( fatal || gdata->errorexit ) {
        /* If it's fatal, or the user wants termination on any error, die */
        terminate_everything(9);
    }
}
//! \brief Sends a message of 5 bytes to the USBDM device over EP0.
//!
//!  An immediate response is expected
//!
//! @param data - Entry \n
//!    data[0]    = N, the number of bytes to receive from the device \n
//!    data[1]    = Command byte \n
//!    data[2..5] = parameter(s) for OSBDM command \n
//! @note data must be an array of at least 5 bytes even if there are no parameters!
//!
//! @param data - Exit \n
//!    data[0]      = cmd response from OSBDM\n
//!    data[1..N-1] = data response from the device (cleared on error)\n
//!
//! @return \n
//!    == BDM_RC_OK (0)     => Success, OK response from device\n
//!    == BDM_RC_USB_ERROR  => USB failure \n
//!    == else              => Error code from Device
//!
USBDM_ErrorCode bdm_usb_recv_ep0(unsigned char *data, unsigned *actualRxSize) {
    unsigned char size = data[0];   // Transfer size is the first byte
    unsigned char cmd  = data[1];   // OSBDM/TBDML Command byte
    int rc;
    int retry = 5;

    *actualRxSize = 0;

    if (usbDeviceHandle == NULL) {
        print("bdm_usb_recv_ep0() - ERROR : Device handle NULL!\n");
        data[0] = BDM_RC_DEVICE_NOT_OPEN;
        return BDM_RC_DEVICE_NOT_OPEN;
    }

#ifdef LOG_LOW_LEVEL
    print("============================\n");
    print("bdm_usb_recv_ep0(%s, size=%d) - \n", getCommandName(cmd), size);
    if (data[1] == CMD_USBDM_DEBUG)
        print("bdm_usb_recv_ep0() - Debug cmd = %s\n", getDebugCommandName(data[2]));
    printDump(data, 6);
#endif // LOG_LOW_LEVEL

    do {
        rc = libusb_control_transfer(usbDeviceHandle,
                                     LIBUSB_REQUEST_TYPE_VENDOR|EP_CONTROL_IN,      // bmRequestType
                                     cmd,                                           // bRequest
                                     data[2]+(data[3]<<8),                          // wValue
                                     data[4]+(data[5]<<8),                          // wIndex
                                     (unsigned char*)data,                          // ptr to data buffer (for Rx)
                                     size,                                          // wLength = size of transfer
                                     5*timeoutValue                                 // timeout
                                    );
        if (rc < 0) {
            print("bdm_usb_recv_ep0(size=%d) - Transfer error (USB error = %s) - retry %d \n", size, libusb_strerror((libusb_error)rc), retry);
            milliSleep(100); // So we don't monopolise the USB
        }
    } while ((rc < 0) && (--retry>0));

    if (rc < 0) {
        print("bdm_usb_recv_ep0() - Transfer failed (USB error = %s)\n", libusb_strerror((libusb_error)rc));
        data[0] = BDM_RC_USB_ERROR;
        *actualRxSize = 0;
    }
    else {
        *actualRxSize = (unsigned) rc;
    }
    if ((data[0] != BDM_RC_OK) && (data[0] != cmd)) { // Error at BDM?
        print("bdm_usb_recv_ep0() - Cmd Failed (%s):\n", getErrorName(data[0]));
        printDump(data,*actualRxSize);
        memset(&data[1], 0x00, size-1);
        return (USBDM_ErrorCode)data[0];
    }
#ifdef LOG_LOW_LEVEL
    print("bdm_usb_recv_ep0(size = %d, recvd = %d):\n", size, rc);
    printDump(data,rc);
#endif // LOG_LOW_LEVEL

    return(BDM_RC_OK);
}
Beispiel #4
0
/**
 * Check the return status for errors. If there is an error, then terminate.
 **/
void checkStatus(
    DDS::ReturnCode_t status,
    const char *info ) {

    if (status != DDS::RETCODE_OK && status != DDS::RETCODE_NO_DATA) {
        cerr << "Error in " << info << ": " << getErrorName(status) << endl;
        exit (1);
    }
}
Beispiel #5
0
/**
 * Check the return status for errors. If there is an error, then terminate.
 **/
bool checkStatus(DDS::ReturnCode_t status, const char *info)
{
	if (status != DDS::RETCODE_OK && status != DDS::RETCODE_NO_DATA)
	{
		cerr << "Error in " << info << ": " << getErrorName(status).c_str() << endl;
		return false;
	}
	return true;
}
Beispiel #6
0
/**
 * Check the return status for errors. If there is an error, then terminate.
 **/
void checkStatus(
    DDS_ReturnCode_t status,
    const char *info ) {

    if (status != DDS_RETCODE_OK && status != DDS_RETCODE_NO_DATA) {
        fprintf(stderr, "Error in %s: %s\n", info, getErrorName(status));
        exit (1);
    }
}
Beispiel #7
0
/**
 * Check the return status for errors. If there is an error, then terminate.
 **/
void checkStatus(
    DDS_ReturnCode_t status,
    const char *info)
{
    if ((status == DDS_RETCODE_OK) || (status == DDS_RETCODE_NO_DATA)) {
        return; /* no problems */
    }
    fprintf(stderr, "Error in %s: %s\n", info, getErrorName(status));
    /* If status==RETCODE_ALREADY_DELETED the application is already being
     * disconnected from the OpenSplice DDS domain
     */
    if (status != DDS_RETCODE_ALREADY_DELETED) {
        /* Generate Ctrl-C event to terminate process */
        GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
    }
    /* Wait in infinite loop as process will be terminated,
     * This is needed on windows as calling exit() or ExitProcess()
     * will fail to cleanup resources properly.
     */
    for (;;) {
        Sleep(300000); /* 5 minutes */
    }
}
//! \brief Executes an USB transaction.
//! This consists of a transmission of a command and reception of the response
//!
//! @param txSize = size of transmitted packet
//!
//! @param rxSize = maximum size of received packet
//!
//! @param data   = IN/OUT buffer for data                           \n
//!    Transmission                                                  \n
//!    ===================================                           \n
//!    data[0]    = reserved for USB layer                           \n
//!    data[1]    = command                                          \n
//!    data[2..N] = data                                             \n
//!                                                                  \n
//!    Reception                                                     \n
//!    ============================================================= \n
//!    data[0]    = response code (error code - see \ref USBDM_ErrorCode) \n
//!    data[1..N] = command response
//!
//! @param timeout      = timeout in ms
//! @param actualRxSize = number of bytes actually received (may be NULL if not required)
//!
//! @return                                                          \n
//!    == BDM_RC_OK (0)     => Success, OK response from device      \n
//!    == BDM_RC_USB_ERROR  => USB failure                           \n
//!    == else              => Error code from BDM
//!
USBDM_ErrorCode bdm_usb_transaction( unsigned int   txSize,
                                     unsigned int   rxSize,
                                     unsigned char *data,
                                     unsigned int   timeout,
                                     unsigned int  *actualRxSize) {
    USBDM_ErrorCode rc;
    unsigned tempRxSize;
    uint8_t command = data[1];

    if (usbDeviceHandle==NULL) {
        print("bdm_usb_transaction(): device not open\n");
        return BDM_RC_DEVICE_NOT_OPEN;
    }
    timeoutValue = timeout;

    if (bdmState.useOnlyEp0) {
        rc = bdmJB16_usb_transaction( txSize, rxSize, data, &tempRxSize);
    }
    else {
        rc = bdmJMxx_usb_transaction( txSize, rxSize, data, &tempRxSize);
    }
    if (actualRxSize != NULL) {
        // Variable size data expected
        *actualRxSize = tempRxSize;
    }
    else if ((rc == 0) && (tempRxSize != rxSize)) {
        // Expect exact data size
        print("bdm_usb_transaction() - cmd = %s, Expected %d; received %d\n",
              getCommandName(command), rxSize, tempRxSize);
        rc = BDM_RC_UNEXPECTED_RESPONSE;
    }
    if (rc != BDM_RC_OK) {
        print("bdm_usb_transaction() - Failed, cmd = %s, rc = %s\n",
              getCommandName(command), getErrorName(rc));
    }
    return rc;
}
Beispiel #9
0
/**
 * Check the return status for errors. If there is an error, then terminate.
 **/
void
checkStatus(
    DDS::ReturnCode_t status,
    const char *info )
{
    if ((status == DDS::RETCODE_OK) || (status == DDS::RETCODE_NO_DATA)) {
        return; /* no problems */
    }
    cerr << "Error in " << info << ": " << getErrorName(status) << endl;
    /* If status==RETCODE_ALREADY_DELETED the application is already being
     * disconnected from the OpenSplice DDS domain
     */
    if (status != DDS::RETCODE_ALREADY_DELETED) {
        /* Call os_procExit to terminate process */
       os_procExit(OS_EXIT_SUCCESS);
    }
    /* Wait in infinite loop as process will be terminated,
     * This is needed on windows as calling exit() or ExitProcess()
     * will fail to cleanup resources properly.
     */
    for (;;) {
        Sleep(300000); /* 5 minutes */
    }
}
Beispiel #10
0
void reportError(UErrorCode *status) {
    u_fprintf(outerr, "Error %d(%s) : %U happened!\n", *status, u_errorName(*status), getErrorName(*status));
}
/** 
The error handling method called if VERBOSE_ERROR_HANDLING is defined. You can customize this if desired.
@param methodId which method caused the error
@param errorCode the cause of the error
*/
void handleError(moduleResult_t errorCode, uint16_t methodId)
{
    printf("<Err 0x%02X (%s) in method 0x%04X>\r\n", errorCode, getErrorName(errorCode), methodId);
} // NOTE: to trap errors in the debugger then #define VERBOSE_ERROR_HANDLING and optionally set a hardware breakpoint right here
//! \brief Receives a response from the USBDM device over the In Bulk Endpoint
//! Responses are retried to allow for target execution
//!
//! @param count = Maximum number of bytes to receive
//!
//! @param data
//!    IN                                       \n
//!    ======================================== \n
//!    data[0]      = error code (= rc)         \n
//!    data[1..N]   = data received             \n
//!
//! @param actualCount = Actual number of bytes received
//!
//! @return                                                       \n
//!    == BDM_RC_OK (0)     => Success, OK response from device   \n
//!    == BDM_RC_USB_ERROR  => USB failure                        \n
//!    == else              => Error code from Device
//!
USBDM_ErrorCode bdm_usb_recv_epIn(unsigned count, unsigned char *data, unsigned *actualCount) {
    int rc;
    int retry = 40; // ~4s of retries
    int transferCount;

    *actualCount = 0; // Assume failure

    if (usbDeviceHandle==NULL) {
        print("bdm_usb_recv_epIn(): device not open\n");
        return BDM_RC_DEVICE_NOT_OPEN;
    }

#ifdef LOG_LOW_LEVEL
    print("bdm_usb_recv_epIn(%d, ...)\n", count);
#endif // LOG_LOW_LEVEL

#if OLD
    do {
        rc = libusb_bulk_transfer(usbDeviceHandle,
                                  EP_IN,                         // Endpoint & direction
                                  (unsigned char *)dummyBuffer,  // ptr to Rx data
                                  sizeof(dummyBuffer)-5,         // number of bytes to Rx
                                  &transferCount,                // number of bytes actually Rx
                                  timeoutValue                   // timeout
                                 );
        if (rc != LIBUSB_SUCCESS) {
            print("bdm_usb_recv_epIn(count=%d) - Transfer timeout (USB error = %s, timeout=%d) - retry\n", count, libusb_strerror((libusb_error)rc), timeoutValue);
            milliSleep(100); // So we don't monopolise the USB
        }
    } while ((rc!=LIBUSB_SUCCESS) && (--retry>0));
#else
    do {
        rc = libusb_bulk_transfer(usbDeviceHandle,
                                  EP_IN,                         // Endpoint & direction
                                  (unsigned char *)dummyBuffer,  // ptr to Rx data
                                  sizeof(dummyBuffer)-5,         // number of bytes to Rx
                                  &transferCount,                // number of bytes actually Rx
                                  timeoutValue                   // timeout
                                 );
        if ((rc == LIBUSB_SUCCESS)  && (dummyBuffer[0] == BDM_RC_BUSY)) {
            // The BDM has indicated it's busy for a while - try again in 1/10 second
            print("bdm_usb_recv_epIn(retry=%d) - BDM Busy - retry\n", retry);
            milliSleep(100); // So we don't monopolise the USB
        }
    } while ((rc == LIBUSB_SUCCESS) && (dummyBuffer[0] == BDM_RC_BUSY)  && (--retry>0));
#endif
    if (rc != LIBUSB_SUCCESS) {
        print("bdm_usb_recv_epIn(count=%d) - Transfer failed (USB error = %s)\n", count, libusb_strerror((libusb_error)rc));
        data[0] = BDM_RC_USB_ERROR;
        memset(&data[1], 0x00, count-1);
        return BDM_RC_USB_ERROR;
    }

    memcpy(data, dummyBuffer, transferCount);
    rc = data[0]&0x7F;

    if (rc != BDM_RC_OK) {
        print("bdm_usb_recv_epIn() - Error Return %d (%s):\n", rc, getErrorName(rc));
        print("bdm_usb_recv_epIn(size = %d, recvd = %d):\n", count, transferCount);
        printDump(data, transferCount);
        memset(&data[1], 0x00, count-1);
    }

#ifdef LOG_LOW_LEVEL
    printDump(data, transferCount);
#endif // LOG_LOW_LEVEL

    *actualCount = transferCount;

    return (USBDM_ErrorCode)(rc);
}