Topic
2 replies Latest Post - ‏2012-11-11T16:22:46Z by SystemAdmin
SystemAdmin
SystemAdmin
3180 Posts
ACCEPTED ANSWER

Pinned topic Limit DXL script GUI to only one instance without disabling rest of DOORS

‏2012-11-09T17:40:42Z |
I'm running a script from the PS Toolbox called Insert Dynamic History Column. The default behavior of this script is the ability to open as many instances of the script as you want at the same time. What I need is to restrict the script to only one instance at a time, without disabling the rest of DOORS (like the block() command does). The reason behind this need is that users are getting confused.

An example of this functionality working can be seen in the DOORS Edit > Attributes window. It doesn't demand your attention by disabling the rest of DOORS, but it only allows one instance of the Attributes window to be open at a time.

Thanks in advance for any insight you can provide!
Updated on 2012-11-11T16:22:46Z at 2012-11-11T16:22:46Z by SystemAdmin
  • Mathias Mamsch
    Mathias Mamsch
    1734 Posts
    ACCEPTED ANSWER

    Re: Limit DXL script GUI to only one instance without disabling rest of DOORS

    ‏2012-11-11T12:59:29Z  in response to SystemAdmin

    You need some kind of semaphore - you could think of several things (open a socket, create a registry key, etc). You can also create a file and keep a writable lock on the file (i.e. keep it open for write). I guess that would be the easiest and most reliable way, since the file lock will automatically vanish when the DXL ends, so there is no problem with locks hanging around after the DXL ends.
     

    string sFilename = (getenv "TEMP") "\\my_gui_lock.txt"
     
    // Check if the file already exists
    Stat stLockFile = create sFilename
     
    // If the lockfile does not exist, or we can rename it, there is no write lock on the file, i.e.
    // if the lockfile exists and we cannot rename it, then there is a write lock on the file!
    if (!null stLockFile && "" != renameFile(sFilename, sFilename ".lock") ) {
        ack "Script is already open!"
            halt
    }
     
    // if the rename was successful, delete the file
    noError() 
    deleteFile sFilename ".lock"
    lastError()
     
    // Keep a write lock on the file, until we quit, so it cannot be renamed
    Stream stLock = write binary sFilename
     
    // on close of the gui release the lock
    void onClose(DB x) {
        hide x
        // close stLock  // This is not mandatory, since file will automatically closed when DXL / DOORS ends
    }
     
    DB gui = create("Test")
    close (gui, false, onClose)
     
    show gui
    

     


    Please note that there is a race condition between creating and renaming the file, so this code does not suit as a general semaphore, but for checking if a GUI already existis on the users screen it should be fine. Hope that helps, regards, Mathias

     

     


    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

     

    Updated on 2014-01-09T10:37:07Z at 2014-01-09T10:37:07Z by iron-man
    • SystemAdmin
      SystemAdmin
      3180 Posts
      ACCEPTED ANSWER

      Re: Limit DXL script GUI to only one instance without disabling rest of DOORS

      ‏2012-11-11T16:22:46Z  in response to Mathias Mamsch
      Thanks Mathias, excellent idea!