I have an app that communicates through USB with an external device. It works in the background and periodically checks if the device is connected to USB and starts reading data from it. When the device is connected, the app in addition shows a window to the user. The app is installed per user and launches when the user logs in. The app is written in C++ using QT and works on Windows and Mac OS X.
The problem is that if 2 users have the app installed and are logged in in the same time (by the "switch user" feature for example), there are 2 instances of the app running and both of them will start communicating with the device, which causes data corruption.
I'd like to implement a check that prevents the app from starting the communication if the owner of the process isn't currently active. Then only the instance started by the active user will be communicating with the device (this assumes only one user can be active, but it's fine for personal computers). Ideally, I'd be very happy to see a QT based solution that works on both Windows and OS X, but platform specific solution will also be fine.
I was wondering if a solution that activates the app's window and the checks if the window is active after that will work.
Best regards, Michal