浏览代码

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

master
kevin 11 年前
父节点
当前提交
81e55deee4
共有 3 个文件被更改,包括 191 次插入36 次删除
  1. 2
    2
      Makefile.am
  2. 107
    0
      cmUiDrvr.c
  3. 82
    34
      cmUiDrvr.h

+ 2
- 2
Makefile.am 查看文件

@@ -30,8 +30,8 @@ cmSRC += src/libcm/cmMidiFilePlay.c src/libcm/cmMidiPort.c src/libcm/cmMidiFile.
30 30
 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 
31 31
 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
32 32
 
33
-cmHDR += src/libcm/cmDevCfg.h src/libcm/cmUi.h src/libcm/cmUiDrvr.h
34
-cmSRC += src/libcm/cmDevCfg.c src/libcm/cmUi.c
33
+cmHDR += src/libcm/cmDevCfg.h src/libcm/cmUi.h src/libcm/cmUiDrvr.h src/libcm/cmUiAudioSysMstr.h
34
+cmSRC += src/libcm/cmDevCfg.c src/libcm/cmUi.c src/libcm/cmUiDrvr.c src/libcm/cmUiAudioSysMstr.c
35 35
 
36 36
 cmHDR += src/libcm/cmFrameFile.h src/libcm/cmFeatFile.h src/libcm/cmCsv.h src/libcm/cmAudLabelFile.h src/libcm/cmTagFile.h
37 37
 cmSRC += src/libcm/cmFrameFile.c src/libcm/cmFeatFile.c src/libcm/cmCsv.c src/libcm/cmAudLabelFile.c src/libcm/cmTagFile.c

+ 107
- 0
cmUiDrvr.c 查看文件

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

+ 82
- 34
cmUiDrvr.h 查看文件

@@ -7,6 +7,7 @@ extern "C" {
7 7
 
8 8
   typedef unsigned cmUiRC_t;
9 9
 
10
+  // cmUi result codes
10 11
   enum
11 12
   {
12 13
     kOkUiRC = cmOkRC,
@@ -18,9 +19,12 @@ extern "C" {
18 19
     kInvalidCtlOpUiRC,
19 20
     kInvalidColRowUiRC,
20 21
     kInvalidIdUiRC,
22
+    kSubSysFailUiRC,
23
+    kBufTooSmallUiRC,
24
+    kBufCorruptUiRC
21 25
   };
22 26
 
23
-
27
+  // Built-in control types.
24 28
   typedef enum
25 29
   {
26 30
     kInvalidUiCId,
@@ -37,46 +41,55 @@ extern "C" {
37 41
     kMeterUiCId,
38 42
     kFilenameUiCId,
39 43
     kDirUiCId,
44
+    kMaxUiCId
40 45
   } cmUiCId_t;
41 46
 
47
+  // Control selector id's
42 48
   typedef enum
43 49
   {
44 50
     kInvalidDId,
45 51
     kCreateCtlDId,
46 52
     kDestroyCtlDId,
47 53
     kSetValDId,
48
-    kDestroyAllDId
54
+    kDestroyAllDId,
55
+    kMaxDId
49 56
   } cmUiDId_t;
50 57
 
58
+  // Control flags.
51 59
   enum
52 60
   {
53 61
     // All controls recognize kValUiFl and kLblUiFl
54
-    kValUiFl   = 0x000001,
55
-    kLblUiFl   = 0x000002,
62
+    kValUiFl   = 0x0000001,
63
+    kLblUiFl   = 0x0000002,
56 64
 
57 65
     // Flags for Number,Progress,Meter
58
-    kMinUiFl   = 0x00004,
59
-    kMaxUiFl   = 0x00010,
60
-    kIncUiFl   = 0x00020,
66
+    kMinUiFl   = 0x000004,
67
+    kMaxUiFl   = 0x000010,
68
+    kIncUiFl   = 0x000020,
61 69
     kNumMask   = kValUiFl | kMinUiFl | kMaxUiFl | kIncUiFl,
62
-    kHorzUiFl  = 0x00040,
63
-    kVertUiFl  = 0x00080,
70
+    kHorzUiFl  = 0x000040,
71
+    kVertUiFl  = 0x000080,
64 72
 
65 73
     // Flags for Filename and Dir
66
-    kFnPatUiFl = 0x00100, // file pattern string
67
-    kFnDirUiFl = 0x00200, // toggle file btn type 
74
+    kFnPatUiFl = 0x000100, // file pattern string
75
+    kFnDirUiFl = 0x000200, // toggle file btn type 
68 76
     kFnMask    = kFnPatUiFl | kFnDirUiFl,
69 77
 
70 78
     // Append list or menu element.
71
-    kAppendUiFl = 0x00400,
79
+    kAppendUiFl = 0x000400,
80
+
81
+    kLeftUiFl   = 0x001000,
82
+    kTopUiFl    = 0x002000,
83
+    kRightUiFl  = 0x004000,
84
+    kBottomUiFl = 0x008000,
85
+    kHCtrUiFl   = 0x010000,
86
+    kVCtrUiFl   = 0x020000,
87
+    kInsideUiFl = 0x040000,
72 88
 
73
-    kLeftUiFl   = 0x01000,
74
-    kTopUiFl    = 0x02000,
75
-    kRightUiFl  = 0x04000,
76
-    kBottomUiFl = 0x08000,
77
-    kHCtrUiFl   = 0x10000,
78
-    kVCtrUiFl   = 0x20000,
79
-    kInsideUiFl = 0x40000,
89
+    // Value flags indicate which value fields are valid
90
+    kIvalUiFl   = 0x100000,
91
+    kFvalUiFl   = 0x200000,
92
+    kSvalUiFl   = 0x400000
80 93
 
81 94
   };
82 95
 
@@ -88,23 +101,58 @@ extern "C" {
88 101
   // because they are used internally as indexes.
89 102
   typedef struct
90 103
   {
91
-    void*       cbArg;        //
92
-    cmUiDId_t   dId;          // function selector id
93
-    unsigned    appId;        // app id (plug-in instance id)
94
-    unsigned    usrId;        // ctl id
95
-    unsigned    panelId;      // parent panel id   
96
-    cmUiCId_t   cId;          // UI control type 
97
-    unsigned    flags;        // See kXXXUiFl above.
98
-    int         x; 
99
-    int         y; 
100
-    int         w; 
101
-    int         h;
102
-    int         ival;
103
-    double      fval;
104
-    const char* sval;
104
+    cmUiDId_t       dId;        // function selector id
105
+    unsigned        appId;      // app id (plug-in instance id)
106
+    unsigned        usrId;      // ctl id
107
+    unsigned        panelId;    // parent panel id   
108
+    cmUiCId_t       cId;        // UI control type 
109
+    unsigned        flags;      // See kXXXUiFl above.
110
+    int             ival;       // Valid if kIvalUiFl is set.
111
+    double          fval;       // Valid if kFvalUiFl is set.
112
+    const cmChar_t* sval;       // Valid if kSvalUiFl is set.
113
+    int             x; 
114
+    int             y; 
115
+    int             w; 
116
+    int             h;
105 117
   } cmUiDriverArg_t;
106 118
   
107
-  typedef cmUiRC_t (*cmUiDriverFunc_t)( const cmUiDriverArg_t* a );
119
+  typedef cmUiRC_t (*cmUiDriverFunc_t)( void* arg, const cmUiDriverArg_t* a );
120
+
121
+  void cmUiDriverArgSetup( cmUiDriverArg_t* a, 
122
+    cmUiDId_t dId,
123
+    unsigned  appId,
124
+    unsigned  usrId,
125
+    unsigned  panelId,
126
+    cmUiCId_t cId,
127
+    unsigned  flags,
128
+    int       ival,
129
+    double    fval,
130
+    const cmChar_t* sval,
131
+    int       x,
132
+    int       y,
133
+    int       w,
134
+    int       h
135
+ );
136
+
137
+  unsigned cmUiDriverArgSerializeBufByteCount( const cmUiDriverArg_t* a );
138
+
139
+  // Returns kBufTooSmallUiRC if the buffer is too small otherwise returns kOkUiRC.
140
+  // This function does not call cmErrMsg() on error
141
+  // the caller is therefore responsible for generating errors.
142
+  cmUiRC_t cmUiDriverArgSerialize( const cmUiDriverArg_t* a, void* buf, unsigned bufByteCnt );
143
+
144
+  // Return kBufTooSmallUiRC or kBufCorruptUiRC if buffer corruption is detected 
145
+  // otherwise returns kOkUiRC.  This function does not call cmErrMsg() on error
146
+  // the caller is therefore responsible for generating errors.
147
+  cmUiRC_t cmUiDriverArgDeserialize( cmUiDriverArg_t* a, void* buf, unsigned bufByteCnt );
148
+
149
+  // Return an arg. value converted to the requiested type.
150
+  // Note that numeric values will be automatically converted but
151
+  // values will not be converted between string and numeric values.
152
+  int             cmUiDriverArgGetInt(    const cmUiDriverArg_t* a );
153
+  double          cmUiDriverArgGetDouble( const cmUiDriverArg_t* a );
154
+  const cmChar_t* cmUiDriverArgGetString( const cmUiDriverArg_t* a );
155
+
108 156
 
109 157
 #ifdef __cplusplus
110 158
 }

正在加载...
取消
保存