Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Photon App/Resource Manager: Page 1 of 2 (12 Items)
   
Photon App/Resource Manager  
(Has anyone | is it possible to) create an application that is both a Photon App and a resource manager? I can think of 
all sorts of ways to make this work, and I'm just curious if anyone has gone down this path before.
Re: Photon App/Resource Manager  
Hi,

It's definitely possible, we do something similar to this.   For our project we ended up writing a thin resource manager
 analogue [same basic concept but connections are stateless] that we frequently use in components with integrated Photon
 code.   This architecture made things a bit easier for our users as they didn't have to remember to launch both the 
instrument hardware interface module and the relevant UI code seperately - if you had one running, you always had the 
other.   Usually we treated them internally as if they were seperate components though, just bundled together for 
convenience - it made it somewhat easier to handle potential concurrency issues if the Photon code interacted with the 
RM through the usual open/close/etc. API.

One of the gotchas to look out for is making sure that PhAB doesn't PtExit() your application when the last visible UI 
window is closed, though!

-Will
Re: Photon App/Resource Manager  
Cool. Which event loop did you use?
Re: Photon App/Resource Manager  
> Cool. Which event loop did you use?

You need both, each in its own thread(s).

Depending on what Photon features you try to use, it may just work, require some trickery, or be completely impossible. 
 In a nutshell, anything that makes the Photon library want a channel will conflict with the resource manager's channel.


If you search the docs for "name_attach() and PtAppAddInput()", you'll find a bit of an explanation of that conflict.  
But the recommendation that works for name_attach() (let Photon use the channel created by name_attach()) doesn't work 
for resource manager.  You will really need two separate channels to run the two event loops.  Since the kernel only 
allows one channel per process to have the flags that both Photon and resmgr want, you'll have to cripple one of them.  
The only one that has the API to allow you to cripple it is Photon -- you'll need to create a channel by hand, forcing 
it *not* to have the flags that conflict with resmgr, and then pass it on to Photon.  This will break some obscure 
features of the Photon library, but hopefully you're not planning to use them in this project.  :-(
Re: Photon App/Resource Manager  
I should probably have mentioned that in general it's safer to just run resmgr and the GUI as two separate processes.  
In addition to avoiding the ugly channel conflict, this gives you the option of letting the resmgr run without a GUI or 
with multiple GUIs and to dynamically attach GUIs from different Photons to the same resmgr.

(But I imagine that in some cases it doesn't make sense to have the resmgr part without the Photon part -- my example is
 a terminal window that wants to be a genuine device in the system (like wterm was in the ancient QNX Windows) instead 
of using a pseudoterminal (like pterm does).)
Re: Photon App/Resource Manager  
This is all very useful information. Having read your previous posting, I was leaning toward separate processes. What 
I'm looking at is a GUI app to which I'd like to add a POSIX command channel (something you can open() and write() to 
under program control).

I actually already have an implementation where the command channel device is handled by a separate process and the 
Photon GUI app reads from the command channel device using PtAddFd(), and it may be that I can't improve on that. My 
motivation for exploring other options was that I would like to increase the amount of data I push through that channel,
 and I thought it could be more efficient writing directly to the app.

In any event, thanks so much for sharing your experience!
Re: Photon App/Resource Manager  
Yeah, in cases where the resmgr is just an API to the GUI app, rather than the Photon being a UI to the resmgr, it feels
 more natural to have them in the same process.

Would a forked pair of processes be close enough?
Re: Photon App/Resource Manager  
Yeah, that would be the logical choice. I just need to decide whether that constitutes a gain versus the current 
approach.
Re: Photon App/Resource Manager  
We did as Wojtek described - we run two independent event loops.    That said, we aren't using the actual resource 
manager framework though; we use a custom dispatcher implementation with our own messaging protocol that is 
architecturally similar but not the same.  Consequently we don't run in to any problems with the per-process channel 
flags, as our implementation doesn't need them.
Re: Photon App/Resource Manager  
For completely custom messages, it's also possible to plug in your message handler into Photon's main loop using 
PtAppAddInputHandler(), and avoid threads altogether.