Ejemplo n.º 1
0
int32_t SharedVariant::getSpaceUsage() const {
  int32_t size = sizeof(SharedVariant);
  if (!IS_REFCOUNTED_TYPE(m_type)) return size;
  switch (m_type) {
  case KindOfObject:
    if (getIsObj()) {
      return size + m_data.obj->getSpaceUsage();
    }
    // fall through
  case KindOfString:
    size += sizeof(StringData) + m_data.str->size();
    break;
  default:
    assert(is(KindOfArray));
    if (getSerializedArray()) {
      size += sizeof(StringData) + m_data.str->size();
    } else if (isPacked()) {
      auto size = m_data.packed->size();
      size += sizeof(ImmutablePackedArray) + size * sizeof(SharedVariant*);
      for (size_t i = 0, n = m_data.packed->size(); i < n; i++) {
        size += m_data.packed->vals()[i]->getSpaceUsage();
      }
    } else {
      auto array = m_data.array;
      size += array->getStructSize();
      for (size_t i = 0, n = array->size(); i < n; i++) {
        size += array->getKeyIndex(i)->getSpaceUsage();
        size += array->getValIndex(i)->getSpaceUsage();
      }
    }
    break;
  }
  return size;
}
Ejemplo n.º 2
0
void SharedVariant::getStats(SharedVariantStats *stats) const {
  stats->initStats();
  stats->variantCount = 1;
  switch (m_type) {
  case KindOfUninit:
  case KindOfNull:
  case KindOfBoolean:
  case KindOfInt64:
  case KindOfDouble:
  case KindOfStaticString:
    stats->dataSize = sizeof(m_data.dbl);
    stats->dataTotalSize = sizeof(SharedVariant);
    break;
  case KindOfObject:
    if (getIsObj()) {
      SharedVariantStats childStats;
      m_data.obj->getSizeStats(&childStats);
      stats->addChildStats(&childStats);
      break;
    }
    // fall through
  case KindOfString:
    stats->dataSize = m_data.str->size();
    stats->dataTotalSize = sizeof(SharedVariant) + sizeof(StringData) +
                           stats->dataSize;
    break;
  default:
    assert(is(KindOfArray));
    if (getSerializedArray()) {
      stats->dataSize = m_data.str->size();
      stats->dataTotalSize = sizeof(SharedVariant) + sizeof(StringData) +
                             stats->dataSize;
      break;
    }
    if (isPacked()) {
      stats->dataTotalSize = sizeof(SharedVariant) +
                             sizeof(ImmutablePackedArray);
      auto size = m_data.packed->size();
      stats->dataTotalSize += sizeof(SharedVariant*) * size;
      for (size_t i = 0; i < size; i++) {
        SharedVariant *v = m_data.packed->vals()[i];
        SharedVariantStats childStats;
        v->getStats(&childStats);
        stats->addChildStats(&childStats);
      }
    } else {
      auto array = m_data.array;
      stats->dataTotalSize = sizeof(SharedVariant) + array->getStructSize();
      for (size_t i = 0, n = array->size(); i < n; i++) {
        SharedVariantStats childStats;
        array->getKeyIndex(i)->getStats(&childStats);
        stats->addChildStats(&childStats);
        array->getValIndex(i)->getStats(&childStats);
        stats->addChildStats(&childStats);
      }
    }
    break;
  }
}
Ejemplo n.º 3
0
std::vector<SDL_Rect> VideoManager::GetAvailableModes() {

	/* All possible width
	 */
	#define EXPAND_VIDEO_MODE(name, width, height)			\
		width,

	static int wL[] = {
		#include "VideoModes.h"
	};
	#undef EXPAND_VIDEO_MODE

	/* All possible height
	 */
	#define EXPAND_VIDEO_MODE(name, width, height)			\
		height,

	static int hL[] = {
		#include "VideoModes.h"
	};
	#undef EXPAND_VIDEO_MODE


	// If the mode is supported, it will be added to the return list
	std::vector<SDL_Rect> modes;
	for (unsigned int i = 0; i < getStructSize(wL); i++) {
		if (isModeAvailable(wL[i], hL[i], 16, true, NULL)) {
			SDL_Rect r;
			r.w = wL[i];
			r.h = hL[i];
			modes.push_back(r);
		}
	}

	return modes;
}
Ejemplo n.º 4
0
Void roveCmdCntrl(UArg arg0, UArg arg1) {

    //const FOREVER hack to kill the 'unreachable statement' compiler warning

    extern const uint8_t FOREVER;

    //initialized in main

    extern PWM_Handle motor_0;
    extern PWM_Handle motor_1;
    extern PWM_Handle motor_2;
    extern PWM_Handle motor_3;
    extern PWM_Handle motor_4;
    extern PWM_Handle motor_5;

    base_station_msg_struct fromBaseMsg;

    char commandBuffer[MAX_COMMAND_SIZE + 4];

    int messageSize;
    int deviceJack;
    int motor_speed = 0;

    int16_t arm_speed = 0;

    int i = 0;

    System_printf("roveCmdCntrlr		init! \n\n");

    System_flush();

    while (FOREVER) {

//		System_printf("CmdCntrl Is PENDING FOR MAIL!\n\n");
//		System_flush();

        Mailbox_pend(fromBaseStationMailbox, &fromBaseMsg, BIOS_WAIT_FOREVER);

        switch (fromBaseMsg.id) {

        // case 0 hack to make a happy switch
        case 0:
            break;

        case motor_right_id:

            //the left motors must be the negative of the right motors. Their phase is backwards
            motor_speed =
                    -(((struct motor_control_struct*) (&fromBaseMsg))->speed);

            DriveMotor(motor_0, motor_speed);
            DriveMotor(motor_1, motor_speed);
            DriveMotor(motor_2, -motor_speed);

            break;

            // end drive motor_right_id

        case motor_left_id:

            motor_speed =
                    (((struct motor_control_struct*) (&fromBaseMsg))->speed);

            DriveMotor(motor_3, -motor_speed);
            DriveMotor(motor_4, motor_speed);
            DriveMotor(motor_5, -motor_speed);

            break;

            //end drive motor_left_id

        case bms_emergency_command_id:
        	if((((struct bms_emergency_command*) (&fromBaseMsg)) -> command)
        			== 1)
        	{
        		digitalWrite(SOFT_RESET_GPIO_PIN, HIGH);
        	}
        	break;

        default:
            deviceJack = getDeviceJack(fromBaseMsg.id);
            // flag for invalid struct size
            if (getStructSize(fromBaseMsg.id) != -1) {
                messageSize = buildSerialStructMessage((void *) &fromBaseMsg,
                        commandBuffer);

                deviceWrite(deviceJack, commandBuffer, messageSize);
            }
            break;
        } //endswitch

        //debugging only:

//		i = 0;
//
//		System_printf("Cmd Cntrl Just Sent!: ");
//
//		while (i < (messageSize)) {
//
//			System_printf("%d, ", commandBuffer[i]);
//			i++;
//
//		} //end while
    }
    System_flush();

    System_printf("Rove Cmd Cntrl Task Error: Forced Exit\n");
    System_flush();

    Task_exit();

} //endfnct:		roveCmdCntrl() Task Thread