#include #include #include #include "misc.h" #include "misc.m" static const char *cur_module = "core"; void message_def_setcurmodule (const char *module) { if (module == NULL) module = "core"; cur_module = module; } static ARRAY_OBJS tbmsg; class MESSAGE_DEF_PRIVATE{ public: char *module; const char *msg; const char **argnames; MESSAGE_DEF_PRIVATE( const char *_module, const char *_msg, const char **_argnames) { module = strdup(_module); msg = _msg; if (_argnames == NULL){ static const char *tbnull[]={NULL}; argnames = tbnull; }else{ argnames = _argnames; } } ~MESSAGE_DEF_PRIVATE() { free (module); } }; PUBLIC MESSAGE_DEF::MESSAGE_DEF( const char *msg, const char *argnames[]) { priv = new MESSAGE_DEF_PRIVATE (cur_module,msg,argnames); tbmsg.neverdelete(); tbmsg.add (this); } PUBLIC MESSAGE_DEF::MESSAGE_DEF( const char *msg) { priv = new MESSAGE_DEF_PRIVATE (cur_module,msg,NULL); tbmsg.neverdelete(); tbmsg.add (this); } PUBLIC MESSAGE_DEF::~MESSAGE_DEF() { delete priv; tbmsg.remove (this); } /* Return the name of the message */ PUBLIC const char *MESSAGE_DEF::getmsg() const { return priv->msg; } /* Return the module which defines (send) this message */ PUBLIC const char *MESSAGE_DEF::getmodule() const { return priv->module; } static int cmp_msg (const ARRAY_OBJ *o1, const ARRAY_OBJ *o2) { MESSAGE_DEF *m1 = (MESSAGE_DEF*)o1; MESSAGE_DEF *m2 = (MESSAGE_DEF*)o2; int ret = strcmp(m1->getmodule(),m2->getmodule()); if (ret == 0){ ret = strcmp(m1->getmsg(),m2->getmsg()); } return ret; } /* Return the arguments definition of a message (end with NULL) */ PUBLIC const char **MESSAGE_DEF::getargs() const { return priv->argnames; } /* Show all defined inter-module messages */ void module_showmsgs() { tbmsg.sort (cmp_msg); printf (MSG_U(I_SHOWMSGS,"Module Message Arguments...\n")); for (int i=0; igetmodule(),d->getmsg()); const char **argnames = d->getargs(); for (int j=0; argnames[j] != NULL; j++){ if (j > 0) printf ("\t"); printf ("%s",argnames[j]); } printf ("\n"); } }