Przeglądaj źródła

cmDspBuiltIn.c: Added 'rsrcWr' and tested with 'string' inputs.

master
kevin 11 lat temu
rodzic
commit
9b529cd4b9
1 zmienionych plików z 115 dodań i 0 usunięć
  1. 115
    0
      dsp/cmDspBuiltIn.c

+ 115
- 0
dsp/cmDspBuiltIn.c Wyświetl plik

@@ -13,6 +13,7 @@
13 13
 #include "cmFileSys.h"
14 14
 #include "cmSymTbl.h"
15 15
 #include "cmJson.h"
16
+#include "cmText.h"
16 17
 #include "cmPrefs.h"
17 18
 #include "cmProcObj.h"
18 19
 #include "cmDspValue.h"
@@ -5166,6 +5167,119 @@ struct cmDspClass_str* cmNetSendClassCons( cmDspCtx_t* ctx )
5166 5167
 }
5167 5168
 
5168 5169
 //==========================================================================================================================================
5170
+enum
5171
+{
5172
+  kBaseInPtsId,
5173
+};
5174
+
5175
+cmDspClass_t _cmRsrcWrDC;
5176
+
5177
+typedef struct
5178
+{
5179
+  cmDspInst_t inst;
5180
+  char**      pathArray;
5181
+  unsigned    pathCnt;
5182
+} cmDspRsrcWr_t;
5183
+
5184
+cmDspInst_t*  _cmDspRsrcWrAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
5185
+{
5186
+  va_list       vl1;
5187
+  va_copy(vl1,vl);
5188
+
5189
+  if( va_cnt < 1 )
5190
+  {
5191
+    cmDspClassErr(ctx,classPtr,kVarArgParseFailDspRC,"The 'RsrcWr' constructor argument list must contain at least one resource path specificiation.");
5192
+    return NULL;
5193
+  }
5194
+
5195
+  unsigned      pathCnt    = va_cnt;
5196
+  unsigned      argCnt    = pathCnt;
5197
+  cmDspVarArg_t args[argCnt+1];
5198
+
5199
+  char**       pathArray   = cmMemAllocZ(char*,pathCnt);
5200
+
5201
+  unsigned i;
5202
+
5203
+  for(i=0; i<pathCnt; ++i)
5204
+  {
5205
+    // get the path
5206
+    const cmChar_t* pathLabel = va_arg(vl,const char*);
5207
+    assert( pathLabel != NULL );
5208
+
5209
+    // store the path name
5210
+    pathArray[i] = cmMemAllocStr(pathLabel);
5211
+
5212
+    cmDspArgSetup(ctx, args+kBaseInPtsId+i, pathLabel, cmInvalidId, kBaseInPtsId+i, 0, 0, kInDsvFl  | kTypeDsvMask, cmTsPrintfH(ctx->lhH,"%s Input.",pathLabel) );
5213
+
5214
+  }
5215
+
5216
+  cmDspArgSetupNull(args + argCnt);
5217
+
5218
+  cmDspRsrcWr_t* p = cmDspInstAlloc(cmDspRsrcWr_t,ctx,classPtr,args,instSymId,id,storeSymId,0,vl1);
5219
+
5220
+  p->pathCnt     = pathCnt;
5221
+  p->pathArray   = pathArray;
5222
+
5223
+
5224
+  return &p->inst;
5225
+}
5226
+
5227
+cmDspRC_t _cmDspRsrcWrFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
5228
+{
5229
+  cmDspRsrcWr_t* p = (cmDspRsrcWr_t*)inst;
5230
+  int i;
5231
+  for(i=0; i<p->pathCnt; ++i)
5232
+    cmMemFree(p->pathArray[i]);
5233
+  cmMemFree(p->pathArray);
5234
+
5235
+  return kOkDspRC;
5236
+}
5237
+
5238
+cmDspRC_t _cmDspRsrcWrReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
5239
+{
5240
+  return kOkDspRC;
5241
+}
5242
+
5243
+
5244
+cmDspRC_t _cmDspRsrcWrRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
5245
+{
5246
+  cmDspRsrcWr_t* p = (cmDspRsrcWr_t*)inst;
5247
+  cmDspRC_t rc = kOkDspRC;
5248
+
5249
+    
5250
+  // if a msg of any type is recieved on an input port - send out the associated symbol
5251
+  if( kBaseInPtsId <= evt->dstVarId && evt->dstVarId < kBaseInPtsId + p->pathCnt )
5252
+  {
5253
+    unsigned idx = evt->dstVarId - kBaseInPtsId;
5254
+    assert( idx < p->pathCnt );
5255
+
5256
+    if( cmDsvIsStrz(evt->valuePtr) )
5257
+    {
5258
+      rc = cmDspRsrcWriteString( ctx->dspH, cmDsvStrz(evt->valuePtr), p->pathArray[idx], NULL );
5259
+    }
5260
+
5261
+  }
5262
+
5263
+  return rc;
5264
+}
5265
+
5266
+struct cmDspClass_str* cmRsrcWrClassCons( cmDspCtx_t* ctx )
5267
+{
5268
+  cmDspClassSetup(&_cmRsrcWrDC,ctx,"RsrcWr",
5269
+    NULL,
5270
+    _cmDspRsrcWrAlloc,
5271
+    _cmDspRsrcWrFree,
5272
+    _cmDspRsrcWrReset,
5273
+    NULL,
5274
+    _cmDspRsrcWrRecv,
5275
+    NULL,
5276
+    NULL,
5277
+    "Set the value of a resource variable.");
5278
+
5279
+  return &_cmRsrcWrDC;
5280
+}
5281
+
5282
+//==========================================================================================================================================
5169 5283
 
5170 5284
 //==========================================================================================================================================
5171 5285
 
@@ -5205,6 +5319,7 @@ cmDspClassConsFunc_t _cmDspClassBuiltInArray[] =
5205 5319
 
5206 5320
   cmShiftBufClassCons,
5207 5321
   cmNetSendClassCons,
5322
+  cmRsrcWrClassCons,
5208 5323
 
5209 5324
   cmDelayClassCons,
5210 5325
   cmPShiftClassCons,

Ładowanie…
Anuluj
Zapisz