2023-01-31 00:38:11 +00:00
|
|
|
|
2022-11-11 18:13:35 +00:00
|
|
|
#include "cwCommon.h"
|
|
|
|
#include "cwLog.h"
|
|
|
|
#include "cwCommonImpl.h"
|
|
|
|
#include "cwMem.h"
|
|
|
|
#include "cwCmInterface.h"
|
|
|
|
|
|
|
|
#include "cmGlobal.h"
|
|
|
|
#include "cmFloatTypes.h"
|
|
|
|
#include "cmRpt.h"
|
|
|
|
#include "cmErr.h"
|
|
|
|
#include "cmCtx.h"
|
|
|
|
#include "cmMem.h"
|
|
|
|
#include "cmMallocDebug.h"
|
|
|
|
#include "cmLinkedHeap.h"
|
|
|
|
#include "cmTime.h"
|
|
|
|
#include "cmMidi.h"
|
|
|
|
#include "cmSymTbl.h"
|
|
|
|
#include "cmScore.h"
|
|
|
|
#include "cmText.h"
|
|
|
|
#include "cmFileSys.h"
|
2023-01-31 00:38:11 +00:00
|
|
|
#include "cmProcObj.h"
|
2022-11-11 18:13:35 +00:00
|
|
|
|
|
|
|
extern "C" {
|
2023-01-31 00:38:11 +00:00
|
|
|
|
|
|
|
|
2022-11-11 18:13:35 +00:00
|
|
|
void _cm_print_info( void* arg, const char* text )
|
|
|
|
{
|
|
|
|
cwLogInfo(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _cm_print_error( void* arg, const char* text )
|
|
|
|
{
|
|
|
|
cwLogError(cw::kOpFailRC,text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace cw
|
|
|
|
{
|
|
|
|
namespace cm
|
|
|
|
{
|
2023-01-31 00:38:11 +00:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
typedef struct cm_str
|
|
|
|
{
|
|
|
|
cmCtx_t ctx;
|
|
|
|
cmSymTblH_t symTblH;
|
|
|
|
cmLHeapH_t lhH;
|
|
|
|
cmProcCtx* procCtx;
|
|
|
|
|
|
|
|
} cm_t;
|
|
|
|
}
|
|
|
|
|
2022-11-11 18:13:35 +00:00
|
|
|
cm_t* _handleToPtr( handle_t h )
|
|
|
|
{ return handleToPtr<handle_t,cm_t>(h); }
|
|
|
|
|
|
|
|
rc_t _destroy( cm_t* p )
|
|
|
|
{
|
|
|
|
if( p != nullptr )
|
|
|
|
{
|
|
|
|
cmTsFinalize();
|
|
|
|
cmFsFinalize();
|
|
|
|
cmMdReport( kIgnoreNormalMmFl );
|
|
|
|
cmMdFinalize();
|
|
|
|
|
2023-01-31 00:38:11 +00:00
|
|
|
cmLHeapDestroy(&p->lhH);
|
|
|
|
cmSymTblDestroy(&p->symTblH);
|
|
|
|
cmProcCtxFree(&p->procCtx);
|
|
|
|
|
2022-11-11 18:13:35 +00:00
|
|
|
mem::release(p);
|
|
|
|
}
|
|
|
|
return kOkRC;
|
|
|
|
}
|
2023-01-31 00:38:11 +00:00
|
|
|
|
|
|
|
rc_t _create_proc_ctx( cm_t* p, cmCtx_t* ctx )
|
|
|
|
{
|
|
|
|
rc_t rc = kOkRC;
|
|
|
|
|
|
|
|
// create the linked heap
|
|
|
|
if(cmLHeapIsValid( p->lhH = cmLHeapCreate(1024,ctx)) == false)
|
|
|
|
{
|
|
|
|
rc = cwLogError(kOpFailRC,"The cm linked heap allocation failed.");
|
|
|
|
goto errLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// intialize the symbol table
|
|
|
|
if( cmSymTblIsValid( p->symTblH = cmSymTblCreate(cmSymTblNullHandle,1,ctx)) == false )
|
|
|
|
{
|
|
|
|
rc = cwLogError(kOpFailRC,"The cm linked heap allocation failed.");
|
|
|
|
goto errLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialize the proc context
|
|
|
|
if( (p->procCtx = cmProcCtxAlloc(NULL,&ctx->rpt,p->lhH,p->symTblH)) == NULL )
|
|
|
|
{
|
|
|
|
rc = cwLogError(kOpFailRC,"The cm proc context allocation failed.");
|
|
|
|
goto errLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
errLabel:
|
|
|
|
return rc;
|
|
|
|
}
|
2022-11-11 18:13:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cw::rc_t cw::cm::create( handle_t& hRef )
|
|
|
|
{
|
|
|
|
rc_t rc = kOkRC;
|
|
|
|
cm_t* p = nullptr;
|
|
|
|
bool memDebugFl = 0; //cmDEBUG_FL;
|
|
|
|
unsigned memGuardByteCnt = memDebugFl ? 8 : 0;
|
|
|
|
unsigned memAlignByteCnt = 16;
|
|
|
|
unsigned memFlags = memDebugFl ? kTrackMmFl | kDeferFreeMmFl | kFillUninitMmFl : 0;
|
|
|
|
const cmChar_t* appTitle = "cwtest";
|
|
|
|
|
|
|
|
if((rc = destroy(hRef)) != kOkRC )
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
p = mem::allocZ<cm_t>();
|
|
|
|
|
|
|
|
cmCtxSetup(&p->ctx,appTitle,_cm_print_info,_cm_print_error,NULL,memGuardByteCnt,memAlignByteCnt,memFlags);
|
|
|
|
|
|
|
|
cmMdInitialize( memGuardByteCnt, memAlignByteCnt, memFlags, &p->ctx.rpt );
|
|
|
|
|
|
|
|
cmFsInitialize( &p->ctx, appTitle);
|
|
|
|
|
|
|
|
cmTsInitialize( &p->ctx );
|
|
|
|
|
2023-01-31 00:38:11 +00:00
|
|
|
if((rc = _create_proc_ctx(p, &p->ctx )) == kOkRC )
|
|
|
|
hRef.set(p);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_destroy(p);
|
|
|
|
rc = cwLogError(rc,"cm Interface context create failed.");
|
|
|
|
}
|
|
|
|
|
2022-11-11 18:13:35 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
cw::rc_t cw::cm::destroy( handle_t& hRef )
|
|
|
|
{
|
|
|
|
rc_t rc = kOkRC;
|
|
|
|
cm_t* p = nullptr;
|
|
|
|
if( !hRef.isValid() )
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
p = _handleToPtr(hRef);
|
|
|
|
|
|
|
|
if((rc = _destroy(p)) != kOkRC )
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
hRef.clear();
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-01-31 00:38:11 +00:00
|
|
|
extern "C" {
|
|
|
|
struct cmCtx_str* cw::cm::context( handle_t h )
|
|
|
|
{
|
|
|
|
cm_t* p = _handleToPtr(h);
|
|
|
|
return &p->ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cmProcCtx_str* cw::cm::proc_context( handle_t h )
|
|
|
|
{
|
|
|
|
cm_t* p = _handleToPtr(h);
|
|
|
|
return p->procCtx;
|
|
|
|
}
|
|
|
|
|
2022-11-11 18:13:35 +00:00
|
|
|
}
|