cmUiDrvr.h/c: cmUiDrvr.c initial commit. Added files for accessing and serializing cmUiDriverArg_t.

This commit is contained in:
kevin 2013-03-31 22:11:53 -07:00
parent 0b83fdad25
commit 81e55deee4
3 changed files with 191 additions and 36 deletions

View File

@ -30,8 +30,8 @@ cmSRC += src/libcm/cmMidiFilePlay.c src/libcm/cmMidiPort.c src/libcm/cmMidiFile.
cmHDR += src/libcm/cmAudioFile.h src/libcm/cmAudioFileMgr.h src/libcm/cmMsgProtocol.h src/libcm/cmAudioSys.h src/libcm/cmAudioPortFile.h src/libcm/cmAudioFileDev.h
cmSRC += src/libcm/cmAudioFile.c src/libcm/cmAudioFileMgr.c src/libcm/cmMsgProtocol.c src/libcm/cmAudioSys.c src/libcm/cmAudioPortFile.c src/libcm/cmAudioFileDev.c
cmHDR += src/libcm/cmDevCfg.h src/libcm/cmUi.h src/libcm/cmUiDrvr.h
cmSRC += src/libcm/cmDevCfg.c src/libcm/cmUi.c
cmHDR += src/libcm/cmDevCfg.h src/libcm/cmUi.h src/libcm/cmUiDrvr.h src/libcm/cmUiAudioSysMstr.h
cmSRC += src/libcm/cmDevCfg.c src/libcm/cmUi.c src/libcm/cmUiDrvr.c src/libcm/cmUiAudioSysMstr.c
cmHDR += src/libcm/cmFrameFile.h src/libcm/cmFeatFile.h src/libcm/cmCsv.h src/libcm/cmAudLabelFile.h src/libcm/cmTagFile.h
cmSRC += src/libcm/cmFrameFile.c src/libcm/cmFeatFile.c src/libcm/cmCsv.c src/libcm/cmAudLabelFile.c src/libcm/cmTagFile.c

107
cmUiDrvr.c Normal file
View File

@ -0,0 +1,107 @@
#include "cmGlobal.h"
#include "cmUiDrvr.h"
void cmUiDriverArgSetup( cmUiDriverArg_t* a,
cmUiDId_t dId,
unsigned appId,
unsigned usrId,
unsigned panelId,
cmUiCId_t cId,
unsigned flags,
int ival,
double fval,
const cmChar_t* sval,
int x,
int y,
int w,
int h
)
{
flags = cmEnaFlag(flags,kSvalUiFl,sval!=NULL);
a->dId = dId;
a->appId = appId;
a->usrId = usrId;
a->panelId = panelId;
a->cId = cId;
a->flags = flags;
a->ival = ival;
a->fval = fval;
a->sval = sval;
a->x = x;
a->y = y;
a->w = w;
a->h = h;
}
unsigned cmUiDriverArgSerializeBufByteCount( const cmUiDriverArg_t* a )
{
unsigned n = sizeof(*a);
if( cmIsFlag(a->flags,kSvalUiFl) && a->sval != NULL )
n += strlen(a->sval) + 1;
return n;
}
cmUiRC_t cmUiDriverArgSerialize( const cmUiDriverArg_t* a, void* buf, unsigned bufByteCnt )
{
if( bufByteCnt < cmUiDriverArgSerializeBufByteCount(a))
return kBufTooSmallUiRC;
memcpy(buf,a,sizeof(*a));
if( cmIsFlag(a->flags,kSvalUiFl) && a->sval != NULL )
strcpy( (char*)buf + sizeof(*a), a->sval );
return kOkUiRC;
}
cmUiRC_t cmUiDriverArgDeserialize( cmUiDriverArg_t* a, void* buf, unsigned bufByteCnt )
{
bool fl = bufByteCnt >= sizeof(*a);
assert( fl );
if( !fl )
return kBufTooSmallUiRC;
memcpy(a,buf,sizeof(*a));
fl = a->cId < kMaxUiCId && a->dId < kMaxDId;
assert(fl );
if( !fl )
return kBufCorruptUiRC;
if( cmIsFlag(a->flags,kSvalUiFl) && a->sval != NULL )
a->sval = (char*)buf + sizeof(*a);
return kOkUiRC;
}
int cmUiDriverArgGetInt( const cmUiDriverArg_t* a )
{
if( a->flags & kIvalUiFl )
return a->ival;
if( a->flags & kFvalUiFl )
return round(a->fval);
assert(0);
return -1;
}
double cmUiDriverArgGetDouble( const cmUiDriverArg_t* a )
{
if( a->flags & kIvalUiFl )
return a->ival;
if( a->flags & kFvalUiFl )
return a->fval;
assert(0);
return -1;
}
const cmChar_t* cmUiDriverArgGetString( const cmUiDriverArg_t* a )
{
return a->flags & kSvalUiFl ? a->sval : NULL;
}

View File

@ -7,6 +7,7 @@ extern "C" {
typedef unsigned cmUiRC_t;
// cmUi result codes
enum
{
kOkUiRC = cmOkRC,
@ -18,9 +19,12 @@ extern "C" {
kInvalidCtlOpUiRC,
kInvalidColRowUiRC,
kInvalidIdUiRC,
kSubSysFailUiRC,
kBufTooSmallUiRC,
kBufCorruptUiRC
};
// Built-in control types.
typedef enum
{
kInvalidUiCId,
@ -37,46 +41,55 @@ extern "C" {
kMeterUiCId,
kFilenameUiCId,
kDirUiCId,
kMaxUiCId
} cmUiCId_t;
// Control selector id's
typedef enum
{
kInvalidDId,
kCreateCtlDId,
kDestroyCtlDId,
kSetValDId,
kDestroyAllDId
kDestroyAllDId,
kMaxDId
} cmUiDId_t;
// Control flags.
enum
{
// All controls recognize kValUiFl and kLblUiFl
kValUiFl = 0x000001,
kLblUiFl = 0x000002,
kValUiFl = 0x0000001,
kLblUiFl = 0x0000002,
// Flags for Number,Progress,Meter
kMinUiFl = 0x00004,
kMaxUiFl = 0x00010,
kIncUiFl = 0x00020,
kMinUiFl = 0x000004,
kMaxUiFl = 0x000010,
kIncUiFl = 0x000020,
kNumMask = kValUiFl | kMinUiFl | kMaxUiFl | kIncUiFl,
kHorzUiFl = 0x00040,
kVertUiFl = 0x00080,
kHorzUiFl = 0x000040,
kVertUiFl = 0x000080,
// Flags for Filename and Dir
kFnPatUiFl = 0x00100, // file pattern string
kFnDirUiFl = 0x00200, // toggle file btn type
kFnPatUiFl = 0x000100, // file pattern string
kFnDirUiFl = 0x000200, // toggle file btn type
kFnMask = kFnPatUiFl | kFnDirUiFl,
// Append list or menu element.
kAppendUiFl = 0x00400,
kAppendUiFl = 0x000400,
kLeftUiFl = 0x01000,
kTopUiFl = 0x02000,
kRightUiFl = 0x04000,
kBottomUiFl = 0x08000,
kHCtrUiFl = 0x10000,
kVCtrUiFl = 0x20000,
kInsideUiFl = 0x40000,
kLeftUiFl = 0x001000,
kTopUiFl = 0x002000,
kRightUiFl = 0x004000,
kBottomUiFl = 0x008000,
kHCtrUiFl = 0x010000,
kVCtrUiFl = 0x020000,
kInsideUiFl = 0x040000,
// Value flags indicate which value fields are valid
kIvalUiFl = 0x100000,
kFvalUiFl = 0x200000,
kSvalUiFl = 0x400000
};
@ -88,23 +101,58 @@ extern "C" {
// because they are used internally as indexes.
typedef struct
{
void* cbArg; //
cmUiDId_t dId; // function selector id
unsigned appId; // app id (plug-in instance id)
unsigned usrId; // ctl id
unsigned panelId; // parent panel id
cmUiCId_t cId; // UI control type
unsigned flags; // See kXXXUiFl above.
int x;
int y;
int w;
int h;
int ival;
double fval;
const char* sval;
cmUiDId_t dId; // function selector id
unsigned appId; // app id (plug-in instance id)
unsigned usrId; // ctl id
unsigned panelId; // parent panel id
cmUiCId_t cId; // UI control type
unsigned flags; // See kXXXUiFl above.
int ival; // Valid if kIvalUiFl is set.
double fval; // Valid if kFvalUiFl is set.
const cmChar_t* sval; // Valid if kSvalUiFl is set.
int x;
int y;
int w;
int h;
} cmUiDriverArg_t;
typedef cmUiRC_t (*cmUiDriverFunc_t)( const cmUiDriverArg_t* a );
typedef cmUiRC_t (*cmUiDriverFunc_t)( void* arg, const cmUiDriverArg_t* a );
void cmUiDriverArgSetup( cmUiDriverArg_t* a,
cmUiDId_t dId,
unsigned appId,
unsigned usrId,
unsigned panelId,
cmUiCId_t cId,
unsigned flags,
int ival,
double fval,
const cmChar_t* sval,
int x,
int y,
int w,
int h
);
unsigned cmUiDriverArgSerializeBufByteCount( const cmUiDriverArg_t* a );
// Returns kBufTooSmallUiRC if the buffer is too small otherwise returns kOkUiRC.
// This function does not call cmErrMsg() on error
// the caller is therefore responsible for generating errors.
cmUiRC_t cmUiDriverArgSerialize( const cmUiDriverArg_t* a, void* buf, unsigned bufByteCnt );
// Return kBufTooSmallUiRC or kBufCorruptUiRC if buffer corruption is detected
// otherwise returns kOkUiRC. This function does not call cmErrMsg() on error
// the caller is therefore responsible for generating errors.
cmUiRC_t cmUiDriverArgDeserialize( cmUiDriverArg_t* a, void* buf, unsigned bufByteCnt );
// Return an arg. value converted to the requiested type.
// Note that numeric values will be automatically converted but
// values will not be converted between string and numeric values.
int cmUiDriverArgGetInt( const cmUiDriverArg_t* a );
double cmUiDriverArgGetDouble( const cmUiDriverArg_t* a );
const cmChar_t* cmUiDriverArgGetString( const cmUiDriverArg_t* a );
#ifdef __cplusplus
}