Adding your own process to the IPC bus

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Adding your own process to the IPC bus

Postby daka1 » Mon Mar 02, 2015 7:42 am

Hello,

We have some modules that seem natural to run in their own process. (Might be wrong :? )
That do some heavy multi threaded calculations and such.

Can we create or own process and easily subscribe to the CEF IPC bus?

Then would like to send events and some data strings through the bus:
Code: Select all
SendProcessMessage(MY_OWN_PROCESS_PID, my_message);


I take it we need to extend some CEF class for this...

Is this a good idea?
daka1
Techie
 
Posts: 42
Joined: Fri Feb 20, 2015 4:49 am

Re: Adding your own process to the IPC bus

Postby magreenblatt » Mon Mar 02, 2015 11:38 am

Why do you want to use a separate process instead of just using separate threads in the browser process?

daka1 wrote:Can we create or own process and easily subscribe to the CEF IPC bus?

No, you would need to implement this functionality yourself.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Adding your own process to the IPC bus

Postby daka1 » Mon Mar 02, 2015 12:20 pm

The main concern is separating two different code bases CEF and our (which is used not only for the cef implementation).

An alternative that has been presented internally is to spawn the new child process from CEF

Communication would then occur between CEF and our process using std I/O, pipe/stream.

I see we have a CefExecuteProcess method, but I take it this is not supposed to spawn arbitrary processes as such?

But then again we need to observe the stream to trigger functionality in CEF somehow? callbacks?
daka1
Techie
 
Posts: 42
Joined: Fri Feb 20, 2015 4:49 am

Re: Adding your own process to the IPC bus

Postby magreenblatt » Mon Mar 02, 2015 1:24 pm

The most common reasons for using a separate process are stability (you expect the process to crash) or security (you need to sandbox the process). If the only consideration for your use case is to build a separate non-CEF-related binary then consider designing your binary as a dynamic library (dll, so, dylib/framework) that the CEF-based application can then load. CEF does not currently provide functionality for launching and communicating with arbitrary external processes -- you would need to implement that yourself.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Adding your own process to the IPC bus

Postby daka1 » Wed Mar 04, 2015 6:26 am

I implemented a simple method for firing up an external process from CEF ( since fork(),exec() is NON Windows).

Using CEF's own commands i figure will give me some benefits, http://neugierig.org/software/chromium/notes/2011/08/zygote.html.

It seems to work, now I "only" need to figure out how to setup IPC to the process.
(A simple pipe to stdin could be enough for the process in question)
Any suggestions :?:


Code: Select all
  // Test of process creation using CEF methods (static), might need to be moved.
  void ClientHandler::LaunchExternalProcess(CefString file_exe) {
    if (CefCurrentlyOn(TID_PROCESS_LAUNCHER)) {
      // Create the command line.
      CefRefPtr<CefCommandLine> command_line =
      CefCommandLine::CreateCommandLine();
      command_line->SetProgram(file_exe);
     
      // Launch the process.
      CefLaunchProcess(command_line);
    } else {
      // Execute on the PROCESS_LAUNCHER thread.
      CefPostTask(TID_PROCESS_LAUNCHER,
                  NewCefRunnableFunction(&ClientHandler::LaunchExternalProcess, file_exe));
    }
  }
daka1
Techie
 
Posts: 42
Joined: Fri Feb 20, 2015 4:49 am

Re: Adding your own process to the IPC bus

Postby magreenblatt » Wed Mar 04, 2015 10:44 am

What OS(es) do you need to support? You can use something like a named pipe or shared memory to communicate between processes. The implementation will likely be platform-specific.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Adding your own process to the IPC bus

Postby daka1 » Sun Mar 08, 2015 4:49 am

We would like to support windows and osx. Yes we are looking at creating some platform specific IPC. As a first POC we just fork from CEF and exec our children, we dropped the CEF create process functionality for now, since it did not provide the possibility to connect the childrens stdin/out to our parent, or maybe I just did not see it... :?:

we consider using just pipes to stdin and out to test things out. This will initially be OSX so windows might need some tweaks...

The pipes:
http://stackoverflow.com/questions/2887 ... 0_28875939

We got our first example to message the children through their stdin...
daka1
Techie
 
Posts: 42
Joined: Fri Feb 20, 2015 4:49 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 94 guests