Skip to content

Commit

Permalink
chugin dl_info print --chugin-probe; internal CK_LOG_SEVERE --> CK_LO…
Browse files Browse the repository at this point in the history
…G_HERALD
  • Loading branch information
gewang committed Jan 17, 2024
1 parent ae79b36 commit 2570a93
Show file tree
Hide file tree
Showing 18 changed files with 150 additions and 111 deletions.
9 changes: 5 additions & 4 deletions VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ ChucK VERSIONS log

1.5.2.1 (December 2023) patch release
=======
- (added) ChuGL (alpha) is now part of the standard chuck distribution
https://chuck.stanford.edu/chugl/
=======
- (added) chugins can now implement a "info query function" to provide
chugin-specific infomation to be accessible from host, including:
* chugin author(s)
* chugin version (not to be confused with compatbility version)
* chugin description
* chugin URL
* (optional) chugin URL
* (optional) contact email
for example, in the chugin source:
```
// chugin info func
CK_DLL_INFO( MyChugin )
{
// set module name
QUERY->setname(QUERY, "FooBar");

// set info
QUERY->setinfo( QUERY, CHUGIN_INFO_AUTHORS, "Ana B. Croft" );
QUERY->setinfo( QUERY, CHUGIN_INFO_CHUGIN_VERSION, "v3.6.1" );
Expand Down
12 changes: 8 additions & 4 deletions src/core/chuck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ t_CKBOOL ChucK::initCompiler()
if( (cstr_cwd = getcwd(NULL, 0)) == NULL )
{
// uh...
EM_log( CK_LOG_SEVERE, "error: unable to determine current working directory!" );
EM_log( CK_LOG_HERALD, "error: unable to determine current working directory!" );
}
else
{
Expand Down Expand Up @@ -713,7 +713,7 @@ t_CKBOOL ChucK::initChugins()

EM_pushlog();
// print host version
EM_log( CK_LOG_SEVERE, TC::green("host API version: %d.%d", true).c_str(), CK_DLL_VERSION_MAJOR, CK_DLL_VERSION_MINOR );
EM_log( CK_LOG_HERALD, TC::green("host API version: %d.%d", true).c_str(), CK_DLL_VERSION_MAJOR, CK_DLL_VERSION_MINOR );
EM_poplog();

//---------------------------------------------------------------------
Expand Down Expand Up @@ -758,7 +758,7 @@ t_CKBOOL ChucK::initChugins()
std::string filename = *j;

// log
EM_log( CK_LOG_SEVERE, "preloading '%s'...", filename.c_str() );
EM_log( CK_LOG_HERALD, "preloading '%s'...", filename.c_str() );
// push indent
EM_pushlog();

Expand Down Expand Up @@ -829,16 +829,20 @@ void ChucK::probeChugins()
{
// ck files to pre load
std::list<std::string> ck_libs_to_preload;
// host verison
ostringstream ostr; ostr << CK_DLL_VERSION_MAJOR << "." << CK_DLL_VERSION_MINOR;

// print whether chugins enabled
EM_log( CK_LOG_SYSTEM, "chugin system: %s", getParamInt( CHUCK_PARAM_CHUGIN_ENABLE ) ? "ON" : "OFF" );
// print host version
EM_log( CK_LOG_SYSTEM, TC::green("host API version: %d.%d", true).c_str(), CK_DLL_VERSION_MAJOR, CK_DLL_VERSION_MINOR );
EM_log( CK_LOG_SYSTEM, "chugin host API version: %s", TC::green(ostr.str(),true).c_str() );
// push
EM_pushlog();
// print version compatbility information
EM_log( CK_LOG_SYSTEM, "chugin major version must == host major version" );
EM_log( CK_LOG_SYSTEM, "chugin minor version must <= host minor version" );
// print chuck language version
EM_log( CK_LOG_SYSTEM, "language version: %s", TC::green(CHUCK_VERSION_STRING,true).c_str() );
// pop
EM_poplog();

Expand Down
68 changes: 43 additions & 25 deletions src/core/chuck_compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ t_CKBOOL load_module( Chuck_Compiler * compiler, Chuck_Env * env, f_ck_query que
t_CKBOOL load_internal_modules( Chuck_Compiler * compiler )
{
// log
EM_log( CK_LOG_SEVERE, "loading built-in modules..." );
EM_log( CK_LOG_HERALD, "loading built-in modules..." );
// push indent level
EM_pushlog();

Expand All @@ -717,48 +717,48 @@ t_CKBOOL load_internal_modules( Chuck_Compiler * compiler )
#endif // __DISABLE_MIDI__

// load
EM_log( CK_LOG_SEVERE, "module 'math'" );
EM_log( CK_LOG_HERALD, "module 'math'" );
if( !load_module( compiler, env, libmath_query, "math", "global" ) ) goto error;
EM_log( CK_LOG_SEVERE, "module 'osc'" );
EM_log( CK_LOG_HERALD, "module 'osc'" );
load_module( compiler, env, osc_query, "osc", "global" );
EM_log( CK_LOG_SEVERE, "module 'ai'" );
EM_log( CK_LOG_HERALD, "module 'ai'" );
if( !load_module( compiler, env, libai_query, "ai", "global" ) ) goto error;
EM_log( CK_LOG_SEVERE, "module 'extract'" );
EM_log( CK_LOG_HERALD, "module 'extract'" );
load_module( compiler, env, extract_query, "extract", "global" );
EM_log( CK_LOG_SEVERE, "module 'filter'" );
EM_log( CK_LOG_HERALD, "module 'filter'" );
load_module( compiler, env, filter_query, "filter", "global" );
EM_log( CK_LOG_SEVERE, "module 'STK'" );
EM_log( CK_LOG_HERALD, "module 'STK'" );
load_module( compiler, env, stk_query, "stk", "global" );
EM_log( CK_LOG_SEVERE, "module 'xform'" );
EM_log( CK_LOG_HERALD, "module 'xform'" );
load_module( compiler, env, xform_query, "xform", "global" );
EM_log( CK_LOG_SEVERE, "module 'xxx'" );
EM_log( CK_LOG_HERALD, "module 'xxx'" );
load_module( compiler, env, xxx_query, "xxx", "global" );
EM_log( CK_LOG_SEVERE, "module 'std'" );
EM_log( CK_LOG_HERALD, "module 'std'" );
if( !load_module( compiler, env, libstd_query, "std", "global" ) ) goto error;

// load
EM_log( CK_LOG_SEVERE, "module 'machine'" );
EM_log( CK_LOG_HERALD, "module 'machine'" );
if( !load_module( compiler, env, machine_query, "machine", "global" ) ) goto error;

#ifndef __DISABLE_NETWORK__
EM_log( CK_LOG_SEVERE, "module 'opsc'" );
EM_log( CK_LOG_HERALD, "module 'opsc'" );
if( !load_module( compiler, env, opensoundcontrol_query, "opsc", "global" ) ) goto error;
#endif

// deprecated:
// if( !load_module( compiler, env, net_query, "net", "global" ) ) goto error;

#ifndef __DISABLE_HID__
EM_log( CK_LOG_SEVERE, "module 'HID'" );
EM_log( CK_LOG_HERALD, "module 'HID'" );
if( !init_class_HID( env ) ) goto error;
#endif

#ifndef __DISABLE_SERIAL__
EM_log( CK_LOG_SEVERE, "module 'SerialIO'" );
EM_log( CK_LOG_HERALD, "module 'SerialIO'" );
if( !init_class_serialio( env ) ) goto error;
#endif

EM_log( CK_LOG_SEVERE, "module 'CKDoc'" );
EM_log( CK_LOG_HERALD, "module 'CKDoc'" );
if( !load_module( compiler, env, ckdoc_query, "ckdoc", "global" ) ) goto error;

// clear context
Expand Down Expand Up @@ -983,7 +983,7 @@ t_CKBOOL load_external_module_at_path( Chuck_Compiler * compiler,

// log with no newline; print status next
// NOTE this is more informative if the chugin crashes, we can see the name
EM_log_opts( CK_LOG_SEVERE, EM_LOG_NO_NEWLINE, "[%s] %s ", TC::magenta("chugin",true).c_str(), name );
EM_log_opts( CK_LOG_HERALD, EM_LOG_NO_NEWLINE, "[%s] %s ", TC::magenta("chugin",true).c_str(), name );

Chuck_DLL * dll = new Chuck_DLL( compiler->carrier(), name );
t_CKBOOL query_failed = FALSE;
Expand All @@ -997,10 +997,10 @@ t_CKBOOL load_external_module_at_path( Chuck_Compiler * compiler,
if( !dll->compatible() )
{
// print
EM_log_opts( CK_LOG_SEVERE, EM_LOG_NO_PREFIX, "[%s] (API version: %d.%d)", TC::red("FAILED",true).c_str(), dll->versionMajor(), dll->versionMinor() );
EM_log_opts( CK_LOG_HERALD, EM_LOG_NO_PREFIX, "[%s] (API version: %d.%d)", TC::red("FAILED",true).c_str(), dll->versionMajor(), dll->versionMinor() );
// push
EM_pushlog();
EM_log( CK_LOG_SEVERE, "reason: %s", TC::orange(dll->last_error(),true).c_str() );
EM_log( CK_LOG_HERALD, "reason: %s", TC::orange(dll->last_error(),true).c_str() );
EM_poplog();
// go to error for cleanup
goto error;
Expand All @@ -1012,15 +1012,15 @@ t_CKBOOL load_external_module_at_path( Chuck_Compiler * compiler,
if( query_failed || !type_engine_add_dll2( env, dll, "global" ) )
{
// print
EM_log_opts( CK_LOG_SEVERE, EM_LOG_NO_PREFIX, "[%s] (API version: %d.%d)", TC::red("FAILED",true).c_str(), dll->versionMajor(), dll->versionMinor() );
EM_log_opts( CK_LOG_HERALD, EM_LOG_NO_PREFIX, "[%s] (API version: %d.%d)", TC::red("FAILED",true).c_str(), dll->versionMajor(), dll->versionMinor() );
EM_pushlog();
// if add_dll2 failed, an error should have already been output
if( query_failed )
{
// print reason
EM_log( CK_LOG_SEVERE, "reason: %s", TC::orange(dll->last_error(),true).c_str() );
EM_log( CK_LOG_HERALD, "reason: %s", TC::orange(dll->last_error(),true).c_str() );
}
EM_log( CK_LOG_SEVERE, "%s '%s'...", TC::blue("skipping",true).c_str(), dl_path );
EM_log( CK_LOG_HERALD, "%s '%s'...", TC::blue("skipping",true).c_str(), dl_path );
EM_poplog();
// go to error for cleanup
goto error;
Expand All @@ -1029,17 +1029,17 @@ t_CKBOOL load_external_module_at_path( Chuck_Compiler * compiler,
else
{
// print
EM_log_opts( CK_LOG_SEVERE, EM_LOG_NO_PREFIX, "[%s]", TC::red("FAILED",true).c_str() );
EM_log_opts( CK_LOG_HERALD, EM_LOG_NO_PREFIX, "[%s]", TC::red("FAILED",true).c_str() );
// more info
EM_pushlog();
EM_log( CK_LOG_SEVERE, "reason: %s", TC::orange(dll->last_error(),true).c_str() );
EM_log( CK_LOG_HERALD, "reason: %s", TC::orange(dll->last_error(),true).c_str() );
EM_poplog();
// go to error for cleanup
goto error;
}

// print
EM_log_opts( CK_LOG_SEVERE, EM_LOG_NO_PREFIX, "[%s]", TC::green("OK",true).c_str() );
EM_log_opts( CK_LOG_HERALD, EM_LOG_NO_PREFIX, "[%s]", TC::green("OK",true).c_str() );
// add to compiler
compiler->m_dlls.push_back(dll);
// commit operator overloads | 1.5.1.5
Expand Down Expand Up @@ -1073,7 +1073,7 @@ t_CKBOOL load_external_modules_in_directory( Chuck_Compiler * compiler,
vector<string> ckfiles2load;

// print directory to examine
EM_log( CK_LOG_SEVERE, "searching '%s'", format_dir_name_for_display(directory).c_str() );
EM_log( CK_LOG_HERALD, "searching '%s'", format_dir_name_for_display(directory).c_str() );
// push
EM_pushlog();

Expand Down Expand Up @@ -1222,7 +1222,25 @@ t_CKBOOL probe_external_module_at_path( const char * name, const char * dl_path
EM_pushlog();
EM_log( CK_LOG_SYSTEM, "reason: %s", TC::orange(dll->last_error(),true).c_str() );
EM_poplog();
}

// print info if available
string name = dll->name();
string authors = dll->getinfo( CHUGIN_INFO_AUTHORS );
string version = dll->getinfo( CHUGIN_INFO_CHUGIN_VERSION );
string desc = dll->getinfo( CHUGIN_INFO_DESCRIPTION );
string url = dll->getinfo( CHUGIN_INFO_URL );
string email = dll->getinfo( CHUGIN_INFO_EMAIL );

if( authors.length() || version.length() || desc.length() || url.length() )
{
EM_pushlog();
if( version.length() ) EM_log( CK_LOG_SYSTEM, "version: %s", version.c_str() );
if( authors.length() ) EM_log( CK_LOG_SYSTEM, "author: %s", authors.c_str() );
if( desc.length() ) EM_log( CK_LOG_HERALD, "description: %s", desc.c_str() );
if( url.length() ) EM_log( CK_LOG_HERALD, "URL: %s", url.c_str() );
if( email.length() ) EM_log( CK_LOG_INFO, "email: %s", email.c_str() );
EM_poplog();
}
}
else
Expand Down
14 changes: 13 additions & 1 deletion src/core/chuck_dl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ t_CKBOOL CK_DLL_CALL ck_end_class( Chuck_DL_Query * query )
if( !type_engine_add_class_from_dl( query->env(), query->curr_class ) )
{
// should already be message
//EM_log(CK_LOG_SEVERE, "error importing class '%s' into type engine",
//EM_log(CK_LOG_HERALD, "error importing class '%s' into type engine",
// query->curr_class->name.c_str());

// pop
Expand Down Expand Up @@ -1248,6 +1248,18 @@ const char * Chuck_DLL::filepath() const



//-----------------------------------------------------------------------------
// name: getinfo()
// desc: get query info
//-----------------------------------------------------------------------------
string Chuck_DLL::getinfo( const string & key )
{
return ck_getinfo( &m_query, key.c_str() );
}




//-----------------------------------------------------------------------------
// name: versionMajor()
// desc: get version major
Expand Down
4 changes: 4 additions & 0 deletions src/core/chuck_dl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,10 @@ struct Chuck_DLL /* : public Chuck_VM_Object */
// chugin minor version must less than or equal host minor version
t_CKBOOL compatible();

public:
// get info from query
std::string getinfo( const std::string & key );

public:
// constructor
Chuck_DLL( Chuck_Carrier * carrier, const char * xid = NULL )
Expand Down
2 changes: 1 addition & 1 deletion src/core/chuck_emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void emit_engine_track_stmt_refs_cleanup( Chuck_Emitter * emit, Chuck_Instr_Stmt
Chuck_Emitter * emit_engine_init( Chuck_Env * env )
{
// log
EM_log( CK_LOG_SEVERE, "initializing emitter..." );
EM_log( CK_LOG_HERALD, "initializing emitter..." );

// TODO: ensure this in a better way?
// whatever t_CKUINT is defined as, it must be the same size as a pointer
Expand Down
2 changes: 1 addition & 1 deletion src/core/chuck_errmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#define CK_LOG_DEBUG 6 // 1.5.0.5 was: CK_LOG_CONFIG
#define CK_LOG_INFO 5
#define CK_LOG_WARNING 4
#define CK_LOG_SEVERE 3
#define CK_LOG_HERALD 3
#define CK_LOG_SYSTEM 2
#define CK_LOG_CORE 1
#define CK_LOG_NONE 0 // set this to log nothing
Expand Down
14 changes: 7 additions & 7 deletions src/core/chuck_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ t_CKBOOL init_class_io( Chuck_Env * env, Chuck_Type * type )
std::string doc = "Base class for other IO classes such as FileIO, StdOut and StdErr. Besides IO.newline(), it’s unlikely you need to use this class directly.";

// log
EM_log( CK_LOG_SEVERE, "class 'IO'" );
EM_log( CK_LOG_HERALD, "class 'IO'" );

// init as base class
// TODO: ctor/dtor?
Expand Down Expand Up @@ -315,7 +315,7 @@ t_CKBOOL init_class_fileio( Chuck_Env * env, Chuck_Type * type )
Chuck_DL_Func * func = NULL;

// log
EM_log( CK_LOG_SEVERE, "class 'FileIO'" );
EM_log( CK_LOG_HERALD, "class 'FileIO'" );

// init as base class
// TODO: ctor/dtor?
Expand Down Expand Up @@ -530,7 +530,7 @@ t_CKBOOL init_class_chout( Chuck_Env * env, Chuck_Type * type )
Chuck_DL_Func * func = NULL;

// log
EM_log( CK_LOG_SEVERE, "class 'chout'" );
EM_log( CK_LOG_HERALD, "class 'chout'" );

// TODO: ctor/dtor?
if( !type_engine_import_class_begin( env, type, env->global(), NULL, NULL, "Do not instantiate this class directly! Use 'chout' instead." ) )
Expand Down Expand Up @@ -620,7 +620,7 @@ t_CKBOOL init_class_cherr( Chuck_Env * env, Chuck_Type * type )
Chuck_DL_Func * func = NULL;

// log
EM_log( CK_LOG_SEVERE, "class 'cherr'" );
EM_log( CK_LOG_HERALD, "class 'cherr'" );

// TODO: ctor/dtor?
if( !type_engine_import_class_begin( env, type, env->global(), NULL, NULL, "Do not instantiate this class directly! Use 'cherr' instead." ) )
Expand Down Expand Up @@ -5823,7 +5823,7 @@ t_CKBOOL Chuck_IO_Serial::readAsync( t_CKUINT type, t_CKUINT num )
}
else
{
EM_log(CK_LOG_SEVERE, "(SerialIO.readAsync): warning: request buffer overflow, dropping read");
EM_log(CK_LOG_HERALD, "(SerialIO.readAsync): warning: request buffer overflow, dropping read");
return FALSE;
}

Expand Down Expand Up @@ -5996,7 +5996,7 @@ t_CKBOOL Chuck_IO_Serial::get_buffer(t_CKINT timeout_ms)
}
else
{
EM_log(CK_LOG_SEVERE, "(SerialIO::get_buffer): read() returned 0 bytes");
EM_log(CK_LOG_HERALD, "(SerialIO::get_buffer): read() returned 0 bytes");
}
}
else
Expand Down Expand Up @@ -6386,7 +6386,7 @@ void Chuck_IO_Serial::read_cb()
{
if( m_asyncResponses.atMaximum() )
{
EM_log(CK_LOG_SEVERE, "SerialIO.read_cb: error: response buffer overflow, dropping read");
EM_log(CK_LOG_HERALD, "SerialIO.read_cb: error: response buffer overflow, dropping read");
continue;
}

Expand Down
Loading

0 comments on commit 2570a93

Please sign in to comment.