Browse Source

cmDspSys.h/c:Initial add of cmDspRsrcWriteString() and check of cmJsonIsModified() in cmDspSysUnload().

master
kevin 11 years ago
parent
commit
f1dc68364a
2 changed files with 133 additions and 23 deletions
  1. 129
    21
      dsp/cmDspSys.c
  2. 4
    2
      dsp/cmDspSys.h

+ 129
- 21
dsp/cmDspSys.c View File

480
   // finalize the pgm specific JSON tree
480
   // finalize the pgm specific JSON tree
481
   if( cmJsonIsValid(p->ctx.rsrcJsH))
481
   if( cmJsonIsValid(p->ctx.rsrcJsH))
482
   {
482
   {
483
-    //if( cmJsonWrite(p->ctx.rsrcJsH, cmJsonRoot(p->ctx.rsrcJsH), p->rsrcFn ) != kOkJsRC )
484
-    //  rc = cmErrMsg(&p->err,kJsonFailDspRC,"JSON file write failed on '%s'.",cmStringNullGuard(p->rsrcFn));
485
-    //else
486
-    //{
487
-      if( cmJsonFinalize(&p->ctx.rsrcJsH) != kOkJsRC )
488
-        rc = cmErrMsg(&p->err,kJsonFailDspRC,"Resource JSON finalization failed.");
489
-      //}
483
+    // if the JSON tree has been modified.
484
+    if( cmJsonIsModified(p->ctx.rsrcJsH) )
485
+      if( cmJsonWrite(p->ctx.rsrcJsH, cmJsonRoot(p->ctx.rsrcJsH), p->rsrcFn ) != kOkJsRC )
486
+        rc = cmErrMsg(&p->err,kJsonFailDspRC,"JSON resource file write failed on '%s'.",cmStringNullGuard(p->rsrcFn));
487
+    
488
+    if( cmJsonFinalize(&p->ctx.rsrcJsH) != kOkJsRC )
489
+      rc = cmErrMsg(&p->err,kJsonFailDspRC,"Resource JSON finalization failed.");
490
   }
490
   }
491
   
491
   
492
   // release the JSON file name
492
   // release the JSON file name
1850
   return rc;
1850
   return rc;
1851
 }
1851
 }
1852
 
1852
 
1853
+cmDspRC_t _cmDspRsrcWritePath( cmDspSysH_t h, cmChar_t** pathStrRef, cmChar_t** varStrRef, va_list vl )
1854
+{
1855
+  unsigned  i;
1856
+  cmDspRC_t rc        = kOkDspRC;;
1857
+  cmDsp_t*  p         = _cmDspHandleToPtr(h);
1858
+  cmChar_t* path      = NULL;
1859
+  unsigned  maxArgCnt = 10;
1860
+  cmChar_t* prevStr   = NULL;
1861
+
1862
+  *pathStrRef = NULL;
1863
+  *varStrRef  = NULL;
1864
+ 
1865
+  for(i=0; i<maxArgCnt; ++i )
1866
+  {
1867
+    cmChar_t* str;
1868
+
1869
+    if((str = va_arg(vl,cmChar_t* )) == NULL )
1870
+      break;
1871
+    
1872
+    if( prevStr != NULL )
1873
+      path = cmTextAppendSS(path,"/");
1874
+    path = cmTextAppendSS(path,prevStr);    
1875
+
1876
+    prevStr = str;    
1877
+  }
1878
+
1879
+  if( i >= maxArgCnt )
1880
+  {
1881
+    rc = cmErrMsg(&p->err,kJsonFailDspRC,"A resource path, beginning with '%25s', does not contain a terminating NULL.", cmStringNullGuard(path) );
1882
+    goto errLabel;
1883
+  }
1884
+
1885
+  // duplicate the string onto the program linked heap
1886
+  if( path != NULL )
1887
+    *pathStrRef = cmLhAllocStr( cmDspSysLHeap(h), path);
1888
+
1889
+  *varStrRef  = prevStr;
1890
+
1891
+ errLabel:
1892
+  cmMemFree(path);
1893
+
1894
+  return rc;
1895
+
1896
+}
1897
+
1853
 cmDspRC_t cmDspRsrcBoolV(    cmDspSysH_t h, bool* vp, va_list vl )
1898
 cmDspRC_t cmDspRsrcBoolV(    cmDspSysH_t h, bool* vp, va_list vl )
1854
 {
1899
 {
1855
   assert(vp != NULL);
1900
   assert(vp != NULL);
1861
     return rc;
1906
     return rc;
1862
 
1907
 
1863
   if((rc = cmJsonPathToBool( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, vp )) != kOkJsRC )
1908
   if((rc = cmJsonPathToBool( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, vp )) != kOkJsRC )
1864
-    return cmErrMsg(&p->err,kJsonFailDspRC,"'bool' resource not found at path:'%s'.",cmStringNullGuard(path));
1909
+    rc =  cmErrMsg(&p->err,kJsonFailDspRC,"'bool' resource not found at path:'%s'.",cmStringNullGuard(path));
1910
+
1911
+  cmLhFree(cmDspSysLHeap(h),path);
1865
 
1912
 
1866
   return rc;
1913
   return rc;
1867
 }
1914
 }
1877
     return rc;
1924
     return rc;
1878
 
1925
 
1879
   if((rc = cmJsonPathToInt( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, vp )) != kOkJsRC )
1926
   if((rc = cmJsonPathToInt( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, vp )) != kOkJsRC )
1880
-    return cmErrMsg(&p->err,kJsonFailDspRC,"'int' resource not found at path:'%s'.",cmStringNullGuard(path));
1927
+    rc = cmErrMsg(&p->err,kJsonFailDspRC,"'int' resource not found at path:'%s'.",cmStringNullGuard(path));
1928
+
1929
+  cmLhFree(cmDspSysLHeap(h),path);
1881
 
1930
 
1882
   return rc;  
1931
   return rc;  
1883
 }
1932
 }
1893
     return rc;
1942
     return rc;
1894
 
1943
 
1895
   if((rc = cmJsonPathToUInt( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, vp )) != kOkJsRC )
1944
   if((rc = cmJsonPathToUInt( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, vp )) != kOkJsRC )
1896
-    return cmErrMsg(&p->err,kJsonFailDspRC,"'uint' resource not found at path:'%s'.",cmStringNullGuard(path));
1945
+    rc = cmErrMsg(&p->err,kJsonFailDspRC,"'uint' resource not found at path:'%s'.",cmStringNullGuard(path));
1946
+
1947
+  cmLhFree(cmDspSysLHeap(h),path);
1897
 
1948
 
1898
   return rc;  
1949
   return rc;  
1899
 }
1950
 }
1909
     return rc;
1960
     return rc;
1910
 
1961
 
1911
   if((rc = cmJsonPathToReal( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, vp )) != kOkJsRC )
1962
   if((rc = cmJsonPathToReal( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, vp )) != kOkJsRC )
1912
-    return cmErrMsg(&p->err,kJsonFailDspRC,"'real' resource not found at path:'%s'.",cmStringNullGuard(path));
1963
+    rc = cmErrMsg(&p->err,kJsonFailDspRC,"'real' resource not found at path:'%s'.",cmStringNullGuard(path));
1964
+
1965
+  cmLhFree(cmDspSysLHeap(h),path);
1913
 
1966
 
1914
   return rc;  
1967
   return rc;  
1915
 }
1968
 }
1926
     return rc;
1979
     return rc;
1927
 
1980
 
1928
   if((rc = cmJsonPathToReal( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, &dval )) != kOkJsRC )
1981
   if((rc = cmJsonPathToReal( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, &dval )) != kOkJsRC )
1929
-    return cmErrMsg(&p->err,kJsonFailDspRC,"'real' resource not found at path:'%s'.",cmStringNullGuard(path));
1982
+    rc = cmErrMsg(&p->err,kJsonFailDspRC,"'real' resource not found at path:'%s'.",cmStringNullGuard(path));
1983
+  else
1984
+    *vp = dval;
1930
 
1985
 
1931
-  *vp = dval;
1986
+  cmLhFree(cmDspSysLHeap(h),path);
1932
 
1987
 
1933
   return rc;  
1988
   return rc;  
1934
 }
1989
 }
1944
     return rc;
1999
     return rc;
1945
 
2000
 
1946
   if((rc = cmJsonPathToString( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, vp )) != kOkJsRC )
2001
   if((rc = cmJsonPathToString( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, vp )) != kOkJsRC )
1947
-    return cmErrMsg(&p->err,kJsonFailDspRC,"'string' resource not found at path:'%s'.",cmStringNullGuard(path));
2002
+    rc = cmErrMsg(&p->err,kJsonFailDspRC,"'string' resource not found at path:'%s'.",cmStringNullGuard(path));
2003
+
2004
+  cmLhFree(cmDspSysLHeap(h),path);
1948
 
2005
 
1949
   return rc;  
2006
   return rc;  
1950
 }
2007
 }
1961
     return rc;
2018
     return rc;
1962
 
2019
 
1963
   if((rc = cmJsonPathToArray( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, &np )) != kOkJsRC )
2020
   if((rc = cmJsonPathToArray( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, &np )) != kOkJsRC )
1964
-    return cmErrMsg(&p->err,kJsonFailDspRC,"'array' resource not found at path:'%s'.",cmStringNullGuard(path));
2021
+    rc = cmErrMsg(&p->err,kJsonFailDspRC,"'array' resource not found at path:'%s'.",cmStringNullGuard(path));
2022
+  else
2023
+    *n = cmJsonChildCount(np);
2024
+
2025
+  cmLhFree(cmDspSysLHeap(h),path);
1965
 
2026
 
1966
-  *n = cmJsonChildCount(np);
1967
   return rc;  
2027
   return rc;  
1968
 
2028
 
1969
 }
2029
 }
1979
     return rc;
2039
     return rc;
1980
 
2040
 
1981
   if((rc = cmJsonPathToArray( jsH, NULL, NULL, path, npp )) != kOkJsRC )
2041
   if((rc = cmJsonPathToArray( jsH, NULL, NULL, path, npp )) != kOkJsRC )
1982
-    return cmErrMsg(&p->err,kJsonFailDspRC,"'array' resource not found at path:'%s'.",cmStringNullGuard(path));
2042
+    rc = cmErrMsg(&p->err,kJsonFailDspRC,"'array' resource not found at path:'%s'.",cmStringNullGuard(path));
2043
+  else
2044
+  {
2045
+    if((*np = cmJsonChildCount(*npp)) != 0 )
2046
+      *pathPtrPtr = path;
1983
 
2047
 
1984
-  if((*np = cmJsonChildCount(*npp)) == 0 )
1985
-    return rc;
2048
+  }
1986
 
2049
 
1987
-  *pathPtrPtr = path;
2050
+  cmLhFree(cmDspSysLHeap(h),path);
1988
 
2051
 
1989
   return rc;
2052
   return rc;
1990
 }
2053
 }
2012
   *vpp = vp;
2075
   *vpp = vp;
2013
   *np  = n;
2076
   *np  = n;
2014
 
2077
 
2078
+  cmLhFree(cmDspSysLHeap(h),path);
2079
+
2015
   return rc;
2080
   return rc;
2016
 }
2081
 }
2017
 
2082
 
2038
   *vpp = vp;
2103
   *vpp = vp;
2039
   *np  = n;
2104
   *np  = n;
2040
 
2105
 
2106
+  cmLhFree(cmDspSysLHeap(h),path);
2107
+
2041
   return rc;
2108
   return rc;
2042
 }
2109
 }
2043
 
2110
 
2064
   *vpp = vp;
2131
   *vpp = vp;
2065
   *np  = n;
2132
   *np  = n;
2066
 
2133
 
2134
+  cmLhFree(cmDspSysLHeap(h),path);
2135
+
2067
   return rc;
2136
   return rc;
2068
 }
2137
 }
2069
 
2138
 
2090
   *vpp = vp;
2159
   *vpp = vp;
2091
   *np  = n;
2160
   *np  = n;
2092
 
2161
 
2093
-  return rc;
2162
+  cmLhFree(cmDspSysLHeap(h),path);
2094
 
2163
 
2164
+  return rc;
2095
 }
2165
 }
2096
 
2166
 
2097
 cmDspRC_t cmDspRsrcRealArrayV(  cmDspSysH_t h, unsigned* np, cmReal_t** vpp, va_list vl )
2167
 cmDspRC_t cmDspRsrcRealArrayV(  cmDspSysH_t h, unsigned* np, cmReal_t** vpp, va_list vl )
2122
   *vpp = vp;
2192
   *vpp = vp;
2123
   *np  = n;
2193
   *np  = n;
2124
 
2194
 
2195
+  cmLhFree(cmDspSysLHeap(h),path);
2196
+
2125
   return rc;
2197
   return rc;
2126
 }
2198
 }
2127
 
2199
 
2148
   *vpp = vp;
2220
   *vpp = vp;
2149
   *np  = n;
2221
   *np  = n;
2150
 
2222
 
2223
+  cmLhFree(cmDspSysLHeap(h),path);
2224
+
2151
   return rc;
2225
   return rc;
2152
 }
2226
 }
2153
 
2227
 
2258
   va_end(vl);
2332
   va_end(vl);
2259
   return rc;
2333
   return rc;
2260
 }
2334
 }
2335
+
2336
+cmDspRC_t cmDspRsrcWriteStringV( cmDspSysH_t h, const cmChar_t*  v, va_list vl )
2337
+{
2338
+  cmDsp_t*      p                = _cmDspHandleToPtr(h);
2339
+  cmChar_t*     pathStr          = NULL;
2340
+  cmChar_t*     varStr           = NULL;
2341
+  cmJsonH_t     jsH              = cmDspSysPgmRsrcHandle(h);
2342
+  cmJsonNode_t* parentObjNodePtr = NULL;
2343
+  cmDspRC_t     rc;
2344
+
2345
+  if((rc = _cmDspRsrcWritePath(h,&pathStr,&varStr,vl)) != kOkDspRC )
2346
+    goto errLabel;
2347
+
2348
+  if((parentObjNodePtr = cmJsonFindPathValue( jsH, pathStr, cmJsonRoot(jsH), kPairTId )) == NULL )
2349
+    rc = cmErrMsg(&p->err,kJsonFailDspRC,"The parent object '%s' for variable '%s' could not be found.",cmStringNullGuard(pathStr),cmStringNullGuard(varStr)); 
2350
+
2351
+  if( cmJsonInsertOrReplacePairString( jsH, parentObjNodePtr, varStr, kStringTId, v ) != kOkJsRC )
2352
+    rc = cmErrMsg(&p->err,kJsonFailDspRC,"Write 'string' resource value failed for path '%s' and variable '%s'",cmStringNullGuard(pathStr),cmStringNullGuard(varStr)); 
2353
+
2354
+ errLabel:
2355
+  if( pathStr != NULL )
2356
+    cmLhFree(cmDspSysLHeap(h),pathStr);
2357
+
2358
+  return rc;    
2359
+}
2360
+
2361
+cmDspRC_t cmDspRsrcWriteString( cmDspSysH_t h, const cmChar_t* v, ... )
2362
+{
2363
+  va_list vl;
2364
+  va_start(vl,v);
2365
+  cmDspRC_t rc = cmDspRsrcWriteStringV(h,v,vl);
2366
+  va_end(vl);
2367
+  return rc;
2368
+}

+ 4
- 2
dsp/cmDspSys.h View File

57
   const cmChar_t* cmDspSysPresetGroupLabel(    cmDspSysH_t h, unsigned groupIdx );
57
   const cmChar_t* cmDspSysPresetGroupLabel(    cmDspSysH_t h, unsigned groupIdx );
58
   cmDspRC_t       cmDspSysPresetGroupJsonList( cmDspSysH_t h, cmJsonH_t* jsHPtr );
58
   cmDspRC_t       cmDspSysPresetGroupJsonList( cmDspSysH_t h, cmJsonH_t* jsHPtr );
59
   
59
   
60
-  // A 'preset' is a collection of stored DSP instances and there variables.  A preset belongs
60
+  // A 'preset' is a collection of stored DSP instances and their variables.  A preset belongs
61
   // to a group.  A given group may have multiple presets. Each preset represents a saved
61
   // to a group.  A given group may have multiple presets. Each preset represents a saved
62
   // instance/var state.
62
   // instance/var state.
63
   unsigned        cmDspSysPresetPresetCount(   cmDspSysH_t h, unsigned groupIdx );
63
   unsigned        cmDspSysPresetPresetCount(   cmDspSysH_t h, unsigned groupIdx );
266
   cmDspRC_t cmDspRsrcRealArray(   cmDspSysH_t h, unsigned* np, cmReal_t**  vpp, ... );
266
   cmDspRC_t cmDspRsrcRealArray(   cmDspSysH_t h, unsigned* np, cmReal_t**  vpp, ... );
267
   cmDspRC_t cmDspRsrcStringArray( cmDspSysH_t h, unsigned* np, const cmChar_t*** vpp, ... );
267
   cmDspRC_t cmDspRsrcStringArray( cmDspSysH_t h, unsigned* np, const cmChar_t*** vpp, ... );
268
  
268
  
269
-  
269
+
270
+  cmDspRC_t cmDspRsrcWriteStringV( cmDspSysH_t h, const cmChar_t* v, va_list vl );
271
+  cmDspRC_t cmDspRsrcWriteString(  cmDspSysH_t h, const cmChar_t* v, ... );
270
 
272
 
271
 
273
 
272
 #ifdef __cplusplus
274
 #ifdef __cplusplus

Loading…
Cancel
Save