cmUiDrvr.h/c: cmUiDrvr.c initial commit. Added files for accessing and serializing cmUiDriverArg_t.
This commit is contained in:
parent
0b83fdad25
commit
81e55deee4
@ -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
|
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
|
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
|
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
|
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
|
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
|
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
107
cmUiDrvr.c
Normal 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;
|
||||||
|
}
|
96
cmUiDrvr.h
96
cmUiDrvr.h
@ -7,6 +7,7 @@ extern "C" {
|
|||||||
|
|
||||||
typedef unsigned cmUiRC_t;
|
typedef unsigned cmUiRC_t;
|
||||||
|
|
||||||
|
// cmUi result codes
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
kOkUiRC = cmOkRC,
|
kOkUiRC = cmOkRC,
|
||||||
@ -18,9 +19,12 @@ extern "C" {
|
|||||||
kInvalidCtlOpUiRC,
|
kInvalidCtlOpUiRC,
|
||||||
kInvalidColRowUiRC,
|
kInvalidColRowUiRC,
|
||||||
kInvalidIdUiRC,
|
kInvalidIdUiRC,
|
||||||
|
kSubSysFailUiRC,
|
||||||
|
kBufTooSmallUiRC,
|
||||||
|
kBufCorruptUiRC
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Built-in control types.
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
kInvalidUiCId,
|
kInvalidUiCId,
|
||||||
@ -37,46 +41,55 @@ extern "C" {
|
|||||||
kMeterUiCId,
|
kMeterUiCId,
|
||||||
kFilenameUiCId,
|
kFilenameUiCId,
|
||||||
kDirUiCId,
|
kDirUiCId,
|
||||||
|
kMaxUiCId
|
||||||
} cmUiCId_t;
|
} cmUiCId_t;
|
||||||
|
|
||||||
|
// Control selector id's
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
kInvalidDId,
|
kInvalidDId,
|
||||||
kCreateCtlDId,
|
kCreateCtlDId,
|
||||||
kDestroyCtlDId,
|
kDestroyCtlDId,
|
||||||
kSetValDId,
|
kSetValDId,
|
||||||
kDestroyAllDId
|
kDestroyAllDId,
|
||||||
|
kMaxDId
|
||||||
} cmUiDId_t;
|
} cmUiDId_t;
|
||||||
|
|
||||||
|
// Control flags.
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
// All controls recognize kValUiFl and kLblUiFl
|
// All controls recognize kValUiFl and kLblUiFl
|
||||||
kValUiFl = 0x000001,
|
kValUiFl = 0x0000001,
|
||||||
kLblUiFl = 0x000002,
|
kLblUiFl = 0x0000002,
|
||||||
|
|
||||||
// Flags for Number,Progress,Meter
|
// Flags for Number,Progress,Meter
|
||||||
kMinUiFl = 0x00004,
|
kMinUiFl = 0x000004,
|
||||||
kMaxUiFl = 0x00010,
|
kMaxUiFl = 0x000010,
|
||||||
kIncUiFl = 0x00020,
|
kIncUiFl = 0x000020,
|
||||||
kNumMask = kValUiFl | kMinUiFl | kMaxUiFl | kIncUiFl,
|
kNumMask = kValUiFl | kMinUiFl | kMaxUiFl | kIncUiFl,
|
||||||
kHorzUiFl = 0x00040,
|
kHorzUiFl = 0x000040,
|
||||||
kVertUiFl = 0x00080,
|
kVertUiFl = 0x000080,
|
||||||
|
|
||||||
// Flags for Filename and Dir
|
// Flags for Filename and Dir
|
||||||
kFnPatUiFl = 0x00100, // file pattern string
|
kFnPatUiFl = 0x000100, // file pattern string
|
||||||
kFnDirUiFl = 0x00200, // toggle file btn type
|
kFnDirUiFl = 0x000200, // toggle file btn type
|
||||||
kFnMask = kFnPatUiFl | kFnDirUiFl,
|
kFnMask = kFnPatUiFl | kFnDirUiFl,
|
||||||
|
|
||||||
// Append list or menu element.
|
// Append list or menu element.
|
||||||
kAppendUiFl = 0x00400,
|
kAppendUiFl = 0x000400,
|
||||||
|
|
||||||
kLeftUiFl = 0x01000,
|
kLeftUiFl = 0x001000,
|
||||||
kTopUiFl = 0x02000,
|
kTopUiFl = 0x002000,
|
||||||
kRightUiFl = 0x04000,
|
kRightUiFl = 0x004000,
|
||||||
kBottomUiFl = 0x08000,
|
kBottomUiFl = 0x008000,
|
||||||
kHCtrUiFl = 0x10000,
|
kHCtrUiFl = 0x010000,
|
||||||
kVCtrUiFl = 0x20000,
|
kVCtrUiFl = 0x020000,
|
||||||
kInsideUiFl = 0x40000,
|
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.
|
// because they are used internally as indexes.
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
void* cbArg; //
|
|
||||||
cmUiDId_t dId; // function selector id
|
cmUiDId_t dId; // function selector id
|
||||||
unsigned appId; // app id (plug-in instance id)
|
unsigned appId; // app id (plug-in instance id)
|
||||||
unsigned usrId; // ctl id
|
unsigned usrId; // ctl id
|
||||||
unsigned panelId; // parent panel id
|
unsigned panelId; // parent panel id
|
||||||
cmUiCId_t cId; // UI control type
|
cmUiCId_t cId; // UI control type
|
||||||
unsigned flags; // See kXXXUiFl above.
|
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 x;
|
||||||
int y;
|
int y;
|
||||||
int w;
|
int w;
|
||||||
int h;
|
int h;
|
||||||
int ival;
|
|
||||||
double fval;
|
|
||||||
const char* sval;
|
|
||||||
} cmUiDriverArg_t;
|
} 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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user