Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*max@home*/
Toshihiro Shimizu 890ddd
#ifdef __cplusplus
Toshihiro Shimizu 890ddd
extern "C" {
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef NOTE
Shinya Kitaoka 120a6e
ConvertOneValue2Enum() potrebbe essere fonte di errore se
Shinya Kitaoka 120a6e
    DCItemSize[one_value.ItemType] >
Shinya Kitaoka 120a6e
    DCItemSize[TW_INT8] e si utilizzano i bit piu significativi di one_value
Shinya Kitaoka 120a6e
        .Item
Shinya Kitaoka 120a6e
    ConvertEnumeration2Range() potrebbe restituire valori di StepSize non
Shinya Kitaoka 120a6e
    appropriati se enumeration.ItemType e TW_FIX32 potrebbe
Shinya Kitaoka 120a6e
    restituire valori MinValue non corretti se DCItemSize[xxx.ItemType] >
Shinya Kitaoka 120a6e
    DCItemSize[TW_INT8] e si utilizzano i bit piu significativi di xxx.Item
Shinya Kitaoka 120a6e
    ConvertEnum2OneValue ritorna(ovviamente) solo il valore corrente
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <assert.h></assert.h>
Toshihiro Shimizu 890ddd
#include <string.h></string.h>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ttwain_capability.h"
Toshihiro Shimizu 890ddd
#include "ttwain_conversion.h"
Toshihiro Shimizu 890ddd
#include "ttwain_error.h"
Toshihiro Shimizu 890ddd
#include "ttwain_state.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ttwain_global_def.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    /*---------------------------------------------------------------------------*/
Shinya Kitaoka 120a6e
    static const size_t DCItemSize[13] = {
Shinya Kitaoka 120a6e
    sizeof(TW_INT8),   sizeof(TW_INT16),  sizeof(TW_INT32), sizeof(TW_UINT8),
Shinya Kitaoka 120a6e
    sizeof(TW_UINT16), sizeof(TW_UINT32), sizeof(TW_BOOL),  sizeof(TW_FIX32),
Shinya Kitaoka 120a6e
    sizeof(TW_FRAME),  sizeof(TW_STR32),  sizeof(TW_STR64), sizeof(TW_STR128),
Shinya Kitaoka 120a6e
    sizeof(TW_STR255),
Toshihiro Shimizu 890ddd
}; /* see twain.h */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
#define TWON_TWON(TYPE1, TYPE2) (((TYPE1) << 8) | (TYPE2))
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
static int ConvertOneValue2Range(TW_ONEVALUE one_value, TW_RANGE *range);
Shinya Kitaoka 120a6e
static int ConvertEnumeration2Range(TW_ENUMERATION enumeration,
Shinya Kitaoka 120a6e
                                    TW_RANGE *range);
Toshihiro Shimizu 890ddd
static int ConvertOneValue2Enum(TW_ONEVALUE one_value, TW_ENUMERATION *tw_enum);
Toshihiro Shimizu 890ddd
static int ConvertEnum2OneValue(TW_ENUMERATION tw_enum, TW_ONEVALUE *one_value);
Toshihiro Shimizu 890ddd
static int ConvertEnum2Array(TW_ENUMERATION tw_enum, TW_ARRAY *array);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
static TUINT32 GetContainerSize(int nFormat, unsigned twty, TW_UINT32 nItems);
Shinya Kitaoka 120a6e
static int TTWAIN_GetCapability(TW_INT16 msgType, TW_UINT16 cap_id,
Shinya Kitaoka 120a6e
                                TW_UINT16 conType, void *data,
Shinya Kitaoka 120a6e
                                TUINT32 *cont_size);
Toshihiro Shimizu 890ddd
/*------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
int TTWAIN_GetCap(TW_UINT16 cap_id, TW_UINT16 conType, void *data,
Shinya Kitaoka 120a6e
                  TUINT32 *cont_size) {
Shinya Kitaoka 120a6e
  return TTWAIN_GetCapability(MSG_GET, cap_id, conType, data, cont_size);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
int TTWAIN_GetCapCurrent(TW_UINT16 cap_id, TW_UINT16 conType, void *data,
Shinya Kitaoka 120a6e
                         TUINT32 *cont_size) {
Shinya Kitaoka 120a6e
  return TTWAIN_GetCapability(MSG_GETCURRENT, cap_id, conType, data, cont_size);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*------------------------------------------------------------------------*/
Shinya Kitaoka 120a6e
int TTWAIN_GetCapQuery(TW_UINT16 cap_id, TW_UINT16 *pattern) {
Shinya Kitaoka 120a6e
  int rc;
Shinya Kitaoka 120a6e
  TW_ONEVALUE data;
Shinya Kitaoka 120a6e
  rc = TTWAIN_GetCapability(MSG_QUERYSUPPORT, cap_id, TWON_ONEVALUE, &data, 0);
Shinya Kitaoka 120a6e
  if (!rc) return FALSE;
Shinya Kitaoka 120a6e
  *pattern = (TW_UINT16)data.Item;
Shinya Kitaoka 120a6e
  return TRUE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*------------------------------------------------------------------------*/
Shinya Kitaoka 120a6e
static int TTWAIN_GetCapability(TW_INT16 msgType, TW_UINT16 cap_id,
Shinya Kitaoka 120a6e
                                TW_UINT16 conType, void *data,
Shinya Kitaoka 120a6e
                                TUINT32 *cont_size) {
Shinya Kitaoka 120a6e
  TW_CAPABILITY cap;
Shinya Kitaoka 120a6e
  void *pv;
Shinya Kitaoka 120a6e
  TW_ENUMERATION *my_enum;
Shinya Kitaoka 120a6e
  TW_ARRAY *my_array;
Shinya Kitaoka 120a6e
  TW_ONEVALUE *my_one;
Shinya Kitaoka 120a6e
  TW_RANGE *my_range;
Shinya Kitaoka 120a6e
  TUINT32 size = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (!data && !cont_size) return FALSE;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (TTWAIN_GetState() < TWAIN_SOURCE_OPEN) {
Shinya Kitaoka 120a6e
    TTWAIN_ErrorBox("Attempt to get capability value below State 4.");
Shinya Kitaoka 120a6e
    return FALSE;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /* Fill in capability structure */
Shinya Kitaoka 120a6e
  cap.Cap = cap_id; /* capability id */
Shinya Kitaoka 120a6e
  cap.ConType =
Shinya Kitaoka 120a6e
      TWON_DONTCARE16; /* favorite type of container (should be ignored...) */
Shinya Kitaoka 120a6e
  cap.hContainer = NULL;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (TTWAIN_DS(DG_CONTROL, DAT_CAPABILITY, msgType, (TW_MEMREF)&cap) !=
Shinya Kitaoka 120a6e
      TWRC_SUCCESS)
Shinya Kitaoka 120a6e
    return FALSE;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (!cap.hContainer) return FALSE;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (msgType == MSG_QUERYSUPPORT) {
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  pv       = GLOBAL_LOCK(cap.hContainer);
Shinya Kitaoka 120a6e
  my_enum  = (TW_ENUMERATION *)pv;
Shinya Kitaoka 120a6e
  my_array = (TW_ARRAY *)pv;
Shinya Kitaoka 120a6e
  my_one   = (TW_ONEVALUE *)pv;
Shinya Kitaoka 120a6e
  my_range = (TW_RANGE *)pv;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (cont_size) {
Shinya Kitaoka 120a6e
    switch (TWON_TWON(cap.ConType, conType)) {
Shinya Kitaoka 120a6e
    case TWON_TWON(TWON_ENUMERATION, TWON_ENUMERATION):
Shinya Kitaoka 120a6e
      *cont_size = GetContainerSize(TWON_ENUMERATION, my_enum->ItemType,
Shinya Kitaoka 120a6e
                                    my_enum->NumItems);
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case TWON_TWON(TWON_ONEVALUE, TWON_ENUMERATION):
Shinya Kitaoka 120a6e
      *cont_size = GetContainerSize(TWON_ENUMERATION, my_one->ItemType, 1);
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case TWON_TWON(TWON_ARRAY, TWON_ARRAY):
Shinya Kitaoka 120a6e
      *cont_size =
Shinya Kitaoka 120a6e
          GetContainerSize(TWON_ARRAY, my_array->ItemType, my_array->NumItems);
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case TWON_TWON(TWON_ONEVALUE, TWON_ONEVALUE):
Shinya Kitaoka 120a6e
      *cont_size = GetContainerSize(TWON_ONEVALUE, my_one->ItemType, 1);
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    case TWON_TWON(TWON_ENUMERATION, TWON_ARRAY):
Shinya Kitaoka 120a6e
      *cont_size =
Shinya Kitaoka 120a6e
          GetContainerSize(TWON_ARRAY, my_enum->ItemType, my_enum->NumItems);
Shinya Kitaoka 120a6e
      break;
Shinya Kitaoka 120a6e
    default:
Shinya Kitaoka 120a6e
      /*      tmsg_error("Unable to convert type %d to %d (cap 0x%x)\n",
Shinya Kitaoka 120a6e
       * cap.ConType, conType,cap_id);*/
Shinya Kitaoka 120a6e
      assert(0);
Shinya Kitaoka 120a6e
      GLOBAL_UNLOCK(cap.hContainer);
Shinya Kitaoka 120a6e
      GLOBAL_FREE(cap.hContainer);
Shinya Kitaoka 120a6e
      return FALSE;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    GLOBAL_UNLOCK(cap.hContainer);
Shinya Kitaoka 120a6e
    GLOBAL_FREE(cap.hContainer);
Shinya Kitaoka 120a6e
    return TRUE;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  switch (TWON_TWON(cap.ConType, conType)) {
Shinya Kitaoka 120a6e
  case TWON_TWON(TWON_ENUMERATION, TWON_ENUMERATION):
Shinya Kitaoka 120a6e
    size = GetContainerSize(cap.ConType, my_enum->ItemType, my_enum->NumItems);
Shinya Kitaoka 120a6e
    memcpy(data, my_enum, size);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case TWON_TWON(TWON_ENUMERATION, TWON_RANGE):
Shinya Kitaoka 120a6e
    ConvertEnumeration2Range(*my_enum, (TW_RANGE *)data);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case TWON_TWON(TWON_ENUMERATION, TWON_ONEVALUE):
Shinya Kitaoka 120a6e
    ConvertEnum2OneValue(*my_enum, (TW_ONEVALUE *)data);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case TWON_TWON(TWON_ARRAY, TWON_ARRAY):
Shinya Kitaoka 120a6e
    size =
Shinya Kitaoka 120a6e
        GetContainerSize(cap.ConType, my_array->ItemType, my_array->NumItems);
Shinya Kitaoka 120a6e
    memcpy(data, my_array, size);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case TWON_TWON(TWON_ONEVALUE, TWON_ONEVALUE):
Shinya Kitaoka 120a6e
    memcpy(data, my_one, sizeof(TW_ONEVALUE));
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case TWON_TWON(TWON_ONEVALUE, TWON_RANGE):
Shinya Kitaoka 120a6e
    ConvertOneValue2Range(*my_one, (TW_RANGE *)data);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case TWON_TWON(TWON_ONEVALUE, TWON_ENUMERATION):
Shinya Kitaoka 120a6e
    ConvertOneValue2Enum(*my_one, (TW_ENUMERATION *)data);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case TWON_TWON(TWON_RANGE, TWON_RANGE):
Shinya Kitaoka 120a6e
    memcpy(data, my_range, sizeof(TW_RANGE));
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case TWON_TWON(TWON_ENUMERATION, TWON_ARRAY):
Shinya Kitaoka 120a6e
    ConvertEnum2Array(*my_enum, (TW_ARRAY *)data);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  default:
Shinya Kitaoka 120a6e
    assert(0);
Shinya Kitaoka 120a6e
    GLOBAL_UNLOCK(cap.hContainer);
Shinya Kitaoka 120a6e
    GLOBAL_FREE(cap.hContainer);
Shinya Kitaoka 120a6e
    return FALSE;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  GLOBAL_UNLOCK(cap.hContainer);
Shinya Kitaoka 120a6e
  GLOBAL_FREE(cap.hContainer);
Shinya Kitaoka 120a6e
  return TRUE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Shinya Kitaoka 120a6e
static int ConvertOneValue2Range(TW_ONEVALUE one_value, TW_RANGE *range) {
Shinya Kitaoka 120a6e
  range->ItemType     = one_value.ItemType;
Shinya Kitaoka 120a6e
  range->MinValue     = one_value.Item;
Shinya Kitaoka 120a6e
  range->MaxValue     = one_value.Item;
Shinya Kitaoka 120a6e
  range->StepSize     = 0;
Shinya Kitaoka 120a6e
  range->DefaultValue = one_value.Item;
Shinya Kitaoka 120a6e
  range->CurrentValue = one_value.Item;
Shinya Kitaoka 120a6e
  return TRUE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Shinya Kitaoka 120a6e
static int ConvertEnumeration2Range(TW_ENUMERATION enumeration,
Shinya Kitaoka 120a6e
                                    TW_RANGE *range) {
Shinya Kitaoka 120a6e
  range->ItemType = enumeration.ItemType;
Shinya Kitaoka 120a6e
  range->MinValue = enumeration.ItemList[0];
Shinya Kitaoka 120a6e
  range->MaxValue = enumeration.ItemList[enumeration.NumItems - 1];
Shinya Kitaoka 120a6e
  range->StepSize = (range->MaxValue - range->MinValue) / enumeration.NumItems;
Shinya Kitaoka 120a6e
  if (range->MaxValue < range->MinValue) {
Shinya Kitaoka 120a6e
    range->MaxValue = range->MinValue;
Shinya Kitaoka 120a6e
    range->StepSize = 0;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  range->DefaultValue = enumeration.ItemList[enumeration.DefaultIndex];
Shinya Kitaoka 120a6e
  range->CurrentValue = enumeration.ItemList[enumeration.CurrentIndex];
Shinya Kitaoka 120a6e
  return TRUE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Shinya Kitaoka 120a6e
static int ConvertOneValue2Enum(TW_ONEVALUE one_value,
Shinya Kitaoka 120a6e
                                TW_ENUMERATION *tw_enum) {
Shinya Kitaoka 120a6e
  tw_enum->ItemType     = one_value.ItemType;
Shinya Kitaoka 120a6e
  tw_enum->NumItems     = 1;
Shinya Kitaoka 120a6e
  tw_enum->CurrentIndex = 0; /* Current value is in ItemList[CurrentIndex] */
Shinya Kitaoka 120a6e
  tw_enum->DefaultIndex = 0; /* Powerup value is in ItemList[DefaultIndex] */
Shinya Kitaoka 120a6e
  tw_enum->ItemList[0]  = (TW_UINT8)one_value.Item;
Shinya Kitaoka 120a6e
  return TRUE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Shinya Kitaoka 120a6e
static int ConvertEnum2OneValue(TW_ENUMERATION tw_enum,
Shinya Kitaoka 120a6e
                                TW_ONEVALUE *one_value) {
Shinya Kitaoka 120a6e
  unsigned char *base;
Shinya Kitaoka 120a6e
  TW_UINT32 ofs;
Shinya Kitaoka 120a6e
  TW_UINT32 itemSize;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  itemSize = DCItemSize[tw_enum.ItemType];
Shinya Kitaoka 120a6e
  base     = tw_enum.ItemList;
Shinya Kitaoka 120a6e
  ofs      = tw_enum.CurrentIndex * itemSize;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  one_value->ItemType = tw_enum.ItemType;
Shinya Kitaoka 120a6e
  one_value->Item     = 0;
Shinya Kitaoka 120a6e
  memcpy(&(one_value->Item), &(base[ofs]), itemSize);
Shinya Kitaoka 120a6e
  return TRUE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Shinya Kitaoka 120a6e
static int ConvertEnum2Array(TW_ENUMERATION tw_enum, TW_ARRAY *array) {
Shinya Kitaoka 120a6e
  TW_UINT32 itemSize;
Shinya Kitaoka 120a6e
  TW_UINT32 listSize;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  itemSize        = DCItemSize[tw_enum.ItemType];
Shinya Kitaoka 120a6e
  listSize        = itemSize * tw_enum.NumItems;
Shinya Kitaoka 120a6e
  array->ItemType = tw_enum.ItemType;
Shinya Kitaoka 120a6e
  array->NumItems = tw_enum.NumItems;
Shinya Kitaoka 120a6e
  memcpy(&(array->ItemList), &(tw_enum.ItemList), listSize);
Shinya Kitaoka 120a6e
  return TRUE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/*	      SET CAP							     */
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
int TTWAIN_SetCap(TW_UINT16 cap_id, TW_UINT16 conType, TW_UINT16 itemType,
Shinya Kitaoka 120a6e
                  TW_UINT32 *value) {
Shinya Kitaoka 120a6e
  int rc = FALSE;
Shinya Kitaoka 120a6e
  TUINT32 size;
Shinya Kitaoka 120a6e
  TW_CAPABILITY *capability = 0;
Shinya Kitaoka 120a6e
  TW_HANDLE capabilityH     = 0;
Shinya Kitaoka 120a6e
  TW_ONEVALUE *container    = 0;
Shinya Kitaoka 120a6e
  TW_HANDLE containerH      = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  size       = GetContainerSize(conType, itemType, 1);
Shinya Kitaoka 120a6e
  containerH = GLOBAL_ALLOC(GMEM_FIXED, size);
Shinya Kitaoka 120a6e
  if (!containerH) goto done;
Shinya Kitaoka 120a6e
  container = (TW_ONEVALUE *)GLOBAL_LOCK(containerH);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  container->ItemType = itemType;
Shinya Kitaoka 120a6e
  container->Item     = *value;
Shinya Kitaoka 120a6e
  capabilityH         = GLOBAL_ALLOC(GMEM_FIXED, sizeof(TW_CAPABILITY));
Shinya Kitaoka 120a6e
  if (!capabilityH) {
Shinya Kitaoka 120a6e
    GLOBAL_UNLOCK(containerH);
Shinya Kitaoka 120a6e
    GLOBAL_FREE(containerH);
MichaƂ Janiszewski 1d0596
    containerH = NULL;
Shinya Kitaoka 120a6e
    goto done;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  capability             = (TW_CAPABILITY *)GLOBAL_LOCK(capabilityH);
Shinya Kitaoka 120a6e
  capability->ConType    = conType;
Shinya Kitaoka 120a6e
  capability->hContainer = containerH;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (TTWAIN_GetState() < TWAIN_SOURCE_OPEN) {
Shinya Kitaoka 120a6e
    /*TTWAIN_ErrorBox("Setting capability in State < 4.");*/
Shinya Kitaoka 120a6e
    TTWAIN_OpenSourceManager(0); /* Bring up to state 4 */
Shinya Kitaoka 120a6e
                                 /*goto done;*/
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  capability->Cap = cap_id; /* capability id */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  rc = (TTWAIN_DS(DG_CONTROL, DAT_CAPABILITY, MSG_SET, (TW_MEMREF)capability) ==
Shinya Kitaoka 120a6e
        TWRC_SUCCESS);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
done:
Shinya Kitaoka 120a6e
  if (containerH) {
Shinya Kitaoka 120a6e
    GLOBAL_UNLOCK(containerH);
Shinya Kitaoka 120a6e
    GLOBAL_FREE(containerH);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (capabilityH) {
Shinya Kitaoka 120a6e
    GLOBAL_UNLOCK(capabilityH);
Shinya Kitaoka 120a6e
    GLOBAL_FREE(capabilityH);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return rc;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Shinya Kitaoka 120a6e
static TUINT32 GetContainerSize(int nFormat, unsigned twty, TW_UINT32 nItems) {
Shinya Kitaoka 120a6e
  TUINT32 size;
Shinya Kitaoka 120a6e
  switch (nFormat) {
Shinya Kitaoka 120a6e
  case TWON_ONEVALUE:
Shinya Kitaoka 120a6e
    size = sizeof(TW_ONEVALUE);
Shinya Kitaoka 120a6e
    if (DCItemSize[twty] > sizeof(TW_UINT32)) {
Shinya Kitaoka 120a6e
      size += DCItemSize[twty] - sizeof(TW_UINT32);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case TWON_RANGE:
Shinya Kitaoka 120a6e
    size = sizeof(TW_RANGE);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case TWON_ENUMERATION:
Shinya Kitaoka 120a6e
    size =
Shinya Kitaoka 120a6e
        sizeof(TW_ENUMERATION) + DCItemSize[twty] * nItems - sizeof(TW_UINT8);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  case TWON_ARRAY:
Shinya Kitaoka 120a6e
    size = sizeof(TW_ARRAY) + DCItemSize[twty] * nItems - sizeof(TW_UINT8);
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  default:
Shinya Kitaoka 120a6e
    size = 0;
Shinya Kitaoka 120a6e
    break;
Shinya Kitaoka 120a6e
  } /* switch */
Shinya Kitaoka 120a6e
  return size;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef __cplusplus
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#endif