I am trying to enable some basic IPC between chromium embedded framework (C++) and another binary. I want basically to fire up the child binary from CEF and communicate through pipes.
CEF does not seem to support connecting our own code to the already existing high level IPC. Neither does it seem to contain functionality that can be used to fire up external binaries in an arbitrary process. http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=12715
I guess what I am looking for is an example where you actually connect two different binaries.
I will need to pass messages with strings and commands to the binary. These commands and string will for example cause the binary to init, getData from an url using cURL and destroy itself.
Soooo, looking at this I have tried using some basic fork(),exec(), pipe() functionality. The impression i get is that this is rather low level...
UPDATE: They don't work on windows either, so I have switched to looking at extending/using existing CEF functionality, see bottom
I need to control the child process in terms of some states, init and destroy as well as handle status messages FROM it.
I have managed to spawn a binary, next step would be to create some basic IPC.
Is this ( fork(),exec(), pipe() ) a reasonable approach for accomplishing the task of integrating the CEF binary with an other binary?
//This codes fires of a binary, with some basic functionality in a separate process
printf("Parent PID %d\n",getpid());
signal(SIGCHLD, SIG_IGN);
pid_t pid=fork();
if (pid==0) { /* child process */
NSString *processString= [[NSString stringWithFormat:@"p %d",getpid()] autorelease];
static char *argv[]={(char*)[processString UTF8String],/*(char*)"echo",(char*)"Foo is my name.",*/NULL};
//execv("/bin/ps",argv);
execv("/Users/thisUser/Library/Developer/Xcode/DerivedData/mychildbinary/Build/Products/Debug/mychildbinary",argv);
exit(127); /* only if execv fails */
}
else { /* pid!=0; parent process */
//waitpid(pid,0,0); /* wait for child to exit */
}
Here is a basic program that writes and reads pipes: http://www.gnu.org/software/libc/manual/html_node/Creating-a-Pipe.html
Update:
Since fork(),pipe() does not apply cross platform. I have written a LaunchExternalProcess method, however I still lack the feature of IPC, the below code launches an external process from the file_exe (full path to binary):
  // Test of process creation using CEF methods (static), might need to be moved.
  void ClientHandler::LaunchExternalProcess(CefString file_exe) {
    if (CefCurrentlyOn(TID_PROCESS_LAUNCHER)) {
      // Retrieve the current executable path.
      //CefString file_exe;
      //if (!CefGetPath(PK_FILE_EXE, file_exe))
      //  return;
      // Create the command line.
      CefRefPtr<CefCommandLine> command_line =
      CefCommandLine::CreateCommandLine();
      command_line->SetProgram(file_exe);
      //command_line->AppendSwitchWithValue(cefclient::kUrl, url);
      // Launch the process.
      CefLaunchProcess(command_line);
    } else {
      // Execute on the PROCESS_LAUNCHER thread.
      CefPostTask(TID_PROCESS_LAUNCHER,
                  NewCefRunnableFunction(&ClientHandler::LaunchExternalProcess, file_exe));
    }
  } 
Any clue on a simple communication between these processes can be made?
I don't get PID or anything from the LaunchExternalProcess method...
We did this using 0mq for the IPC between our CEF process and a non-cef process.
We used a simple timer to poll the 0mq message queue for IPC messages to dispatch within CEF and ran CefRunMessageLoop() as normal. This allowed us to have both sending and receiving 0mq sockets without blocking, and we got excellent results for the amount of traffic we were sending/receiving.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With