How to handle cell library change event

Hi, There,

My application needs to know if the users try to change the attached cell lib. I coded as follows according to MDL program manual document:

mdlSystem_setFunction (SYSTEM_CELL_LIBRARY_CHANGE, handleLibChange);

void handleLibChange
(
CellLibAsyncMsgP cellLibAsyncMsg
)
{ int ii, evenType, handled = TRUE;
char msg[512];

evenType = mdlCellLibAsync_getLibPath(name,MAXNAMELENGTH,cellLibAsyncMsg);

handleUnload(0);
return 0; // return 0 to grant unloading

switch (evenType)
{
case CELL_LIBRARY_PRE_ATTACH: // The cell library path returned by mdlCellLibAsync_getLibPath will be the cell libary about to be attached.
sprintf(msg,"INFO: you are about to attach a new cell lib.");
break;
case CELL_LIBRARY_POST_ATTACH: // The cell library path returned by mdlCellLibAsync_getLibPath is the cell library that was attached.
sprintf(msg,"INFO: you have attached a new cell lib.");
break;
case CELL_LIBRARY_PRE_DETACH: // The cell library path returned by mdlCellLibAsync_getLibPath is the cell library about to be detached.
sprintf(msg,"INFO: you are about to de-attach a new cell lib.");
break;
case CELL_LIBRARY_POST_DETACH: // The cell library path returned by mdlCellLibAsync_getLibPath is the cell libary that was detached.
. sprintf(msg,"INFO: you are have de-attached a new cell libb");
break;
case CELL_LIBRARY_PRE_CREATE: // The cell library path returned by mdlCellLibAsync_getLibPath is the cell library about to be created.
sprintf(msg,"INFO: you are about to create a new cell lib.");
break;
case CELL_LIBRARY_POST_CREATE: //
sprintf(msg,"INFO: you have created a new cell lib.");
break;
defaut:
handled = FALSE;
break;
} // end of switch (evenType)
// Unload the cellconfig application:
if ( TRUE == handled )
mdlDialog_openInfoBox(rsdsObj.msgBuf);

return;
} /* end handleUnload() */
Those comments after each case are from the MDL manual. However, call to mdlCellLibAsync_getLibPath return only SUCCESS or ERROR, not as documented return the event types.
Also, this function was called multiple types, rather than only PRE and POST.
Any suggestions will be greatly appreciated.
Regards,
Ken
Parents
  • void handleLibChange
    (
    CellLibAsyncMsgP cellLibAsyncMsg
    )
    {
      int eventType = -1;
      int handled = TRUE;
      char msg[512];
      
       //eventType = mdlCellLibAsync_getLibPath (name,MAXNAMELENGTH, cellLibAsyncMsg);
      mdlCellLibAsync_getMessageType (&eventType, cellLibAsyncMsg);
      
      switch (eventType)
      {
         case CELL_LIBRARY_PRE_ATTACH: // The cell library path returned by mdlCellLibAsync_getLibPath will be the cell libary about to be attached.
          sprintf (msg, "INFO: you are about to attach a new cell lib.");
         break;
         case CELL_LIBRARY_POST_ATTACH: // The cell library path returned by mdlCellLibAsync_getLibPath is the cell library that was attached.
          sprintf (msg, "INFO: you have attached a new cell lib.");
         break;
         case CELL_LIBRARY_PRE_DETACH: // The cell library path returned by mdlCellLibAsync_getLibPath is the cell library about to be detached.
          sprintf (msg, "INFO: you are about to de-attach a new cell lib.");
         break;
         case CELL_LIBRARY_POST_DETACH: // The cell library path returned by mdlCellLibAsync_getLibPath is the cell libary that was detached.
          sprintf (msg, "INFO: you are have de-attached a new cell libb");
         break;
         case CELL_LIBRARY_PRE_CREATE: // The cell library path returned by mdlCellLibAsync_getLibPath is the cell library about to be created.
          sprintf (msg, "INFO: you are about to create a new cell lib.");
         break;
         case CELL_LIBRARY_POST_CREATE:
          sprintf (msg, "INFO: you have created a new cell lib.");
         break;
         defaut:
            handled = FALSE;
         break;
      } // end of switch (eventType)
      
      if (handled)
         mdlDialog_openInfoBox (msg);
      
      return handled? SUCCESS: ERROR; } /* end handleUnload() */

     
    Regards, Jon Summers
    LA Solutions

  • Hi, Jon,

    Thanks for your rely. So the MDL manual is wrong again.

    How can I stop the call back from my application if it needs to manipulate the attached cell lib itself without triggering the call back?

    Regards,

    Ken

  • Unknown said:
    The MDL manual is wrong again

    mdlCellLibAsync_getLibPath  is documented in V8i help as returning SUCCESS or ERROR.

    Unknown said:
    How can I stop the call back from my application if it needs to manipulate the attached cell lib itself without triggering the call back?

    I'm not sure exactly what you're asking.  This callback is called before a cell library is detached, attached or created. It is also called after a cell library is detached, attached or created.

    The way to stop the callback is simply not to establish it (i.e. don't call mdlSystem_setFunction ()).

     
    Regards, Jon Summers
    LA Solutions

  • Hi, Jon,

    Thanks for the reply.

    I need to stop users changing attached cell lib. So I set up the call back. However, in some cases, my application need to change the attached cell lib and I do not want to trigger the call back.  Can the call back tell who is changed the cell lib?

    Regards,

    Ken

  • I dont' think that the callback is knowing "who's calling".

    Nevertheless you might be aware of a callback in your function that attaches the lib.

    You should save the old callback (it might be not yours) and set the callback to NULL (returns the old function pointer), attach your lib and set the callback to what was installed before.

    HTH Michael



  • Hi, Michael,

    Thanks for your reply.

    Could you please advise if the following code is what you suggested

    Assuming my call back function is handleLibChange

       MdlFunctionP myLibCB = handleLibChange;  // store the call back

       mdlSystem_setFunction (SYSTEM_CELL_LIBRARY_CHANGE, myLibCB);    // set the call back

       MdlFunctionP myOldLibCB = myLibCB; // Store the call back before NULL it.

       myLibCB = NULL;  // NULL the call back, this will stop it being triggered.

    Best Regards,

    Ken

  • Unknown said:
    Could you please advise if the following code is what you suggested?

    You would typically set up your mdlSystem_setFunction calls in your main(), then unset them in your OnUnload().

    //main.mc

    Private MdlFunctionP m_previousLibChangeHandler = NULL;

    int main (...)
    {
       m_previousLibChangeHandler = mdlSystem_setFunction (SYSTEM_CELL_LIBRARY_CHANGE, myLibCB);
       mdlSystem_setFunction (SYSTEM_UNLOAD_PROGRAM, OnUnload);
    }
    void OnUnload (...)
    {
       mdlSystem_setFunction (SYSTEM_CELL_LIBRARY_CHANGE, m_previousLibChangeHandler);
    }

    In your critical section where you want to manipulate the cell library, turn off the SYSTEM_CELL_LIBRARY_CHANGE handler, then restore it when you've finished …

    void CellLibHandler ()
    {
       mdlSystem_setFunction (SYSTEM_CELL_LIBRARY_CHANGE, NULL);
       // Your code that does something with a cell library
       ...
       // End of your code that does something with a cell library
       mdlSystem_setFunction (SYSTEM_CELL_LIBRARY_CHANGE, myLibCB);
    }

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • Ken, Jon

    Jon's advice is nearly what I tried to suggest to you (a small change Jon ^^)

    void CellLibHandler ()
    {
       MdlFunctionP  oldCallback mdlSystem_setFunction (SYSTEM_CELL_LIBRARY_CHANGE, NULL);
       // Your code that does something with a cell library (i.e. change attached)

       ...

       // End of your code that does something with a cell library
       mdlSystem_setFunction (SYSTEM_CELL_LIBRARY_CHANGE, oldCallback);
    }

    so, no matter if your own callback was set or anyone else had a callback installed (don't suppose you're alone) it will be temporarily switched of and back on after your changes.

    Michael



  • Hi, Jon & Michael,

    Thanks for your invaluable suggestions. I have made it work! Now, I now understand why mdlSystem_setFunction returns the previous callback functions. It is intended for us to switch them inside our application.

    Thanks again

    Ken

Reply Children
No Data