libcm is a C development framework with an emphasis on audio signal processing applications.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

cmUiDrvr.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "cmGlobal.h"
  2. #include "cmUiDrvr.h"
  3. void cmUiDriverArgSetup( cmUiDriverArg_t* a,
  4. cmUiDId_t dId,
  5. unsigned appId,
  6. unsigned usrId,
  7. unsigned panelId,
  8. cmUiCId_t cId,
  9. unsigned flags,
  10. int ival,
  11. double fval,
  12. const cmChar_t* sval,
  13. int x,
  14. int y,
  15. int w,
  16. int h
  17. )
  18. {
  19. flags = cmEnaFlag(flags,kSvalUiFl,sval!=NULL);
  20. a->dId = dId;
  21. a->appId = appId;
  22. a->usrId = usrId;
  23. a->panelId = panelId;
  24. a->cId = cId;
  25. a->flags = flags;
  26. a->ival = ival;
  27. a->fval = fval;
  28. a->sval = sval;
  29. a->x = x;
  30. a->y = y;
  31. a->w = w;
  32. a->h = h;
  33. }
  34. unsigned cmUiDriverArgSerializeBufByteCount( const cmUiDriverArg_t* a )
  35. {
  36. unsigned n = sizeof(*a);
  37. if( cmIsFlag(a->flags,kSvalUiFl) && a->sval != NULL )
  38. n += strlen(a->sval) + 1;
  39. return n;
  40. }
  41. cmUiRC_t cmUiDriverArgSerialize( const cmUiDriverArg_t* a, void* buf, unsigned bufByteCnt )
  42. {
  43. if( bufByteCnt < cmUiDriverArgSerializeBufByteCount(a))
  44. return kBufTooSmallUiRC;
  45. memcpy(buf,a,sizeof(*a));
  46. if( cmIsFlag(a->flags,kSvalUiFl) && a->sval != NULL )
  47. strcpy( (char*)buf + sizeof(*a), a->sval );
  48. return kOkUiRC;
  49. }
  50. cmUiRC_t cmUiDriverArgDeserialize( cmUiDriverArg_t* a, void* buf, unsigned bufByteCnt )
  51. {
  52. bool fl = bufByteCnt >= sizeof(*a);
  53. assert( fl );
  54. if( !fl )
  55. return kBufTooSmallUiRC;
  56. memcpy(a,buf,sizeof(*a));
  57. fl = a->cId < kMaxUiCId && a->dId < kMaxDId;
  58. assert(fl );
  59. if( !fl )
  60. return kBufCorruptUiRC;
  61. if( cmIsFlag(a->flags,kSvalUiFl) && a->sval != NULL )
  62. a->sval = (char*)buf + sizeof(*a);
  63. return kOkUiRC;
  64. }
  65. int cmUiDriverArgGetInt( const cmUiDriverArg_t* a )
  66. {
  67. if( a->flags & kIvalUiFl )
  68. return a->ival;
  69. if( a->flags & kFvalUiFl )
  70. return round(a->fval);
  71. assert(0);
  72. return -1;
  73. }
  74. double cmUiDriverArgGetDouble( const cmUiDriverArg_t* a )
  75. {
  76. if( a->flags & kIvalUiFl )
  77. return a->ival;
  78. if( a->flags & kFvalUiFl )
  79. return a->fval;
  80. assert(0);
  81. return -1;
  82. }
  83. const cmChar_t* cmUiDriverArgGetString( const cmUiDriverArg_t* a )
  84. {
  85. return a->flags & kSvalUiFl ? a->sval : NULL;
  86. }