Index: services/nacl/pexe_translator_app.cc |
diff --git a/services/nacl/pexe_translator_app.cc b/services/nacl/pexe_translator_app.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..95a9d9f671800e76867cd7f5905806fa5cd218cc |
--- /dev/null |
+++ b/services/nacl/pexe_translator_app.cc |
@@ -0,0 +1,67 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
Mark Seaborn
2015/10/20 22:28:58
Nit: Can you name this using similar naming to the
Sean Klein
2015/10/22 21:50:01
Done.
|
+#include <fcntl.h> |
+ |
+#include "base/files/file_util.h" |
+#include "mojo/nacl/nonsfi/nexe_launcher_nonsfi.h" |
+#include "mojo/public/c/system/main.h" |
+#include "mojo/public/cpp/application/application_connection.h" |
+#include "mojo/public/cpp/application/application_delegate.h" |
+#include "mojo/public/cpp/application/application_runner.h" |
+#include "mojo/public/cpp/application/interface_factory.h" |
+#include "mojo/public/cpp/bindings/strong_binding.h" |
+#include "services/nacl/pexe_translator.mojom.h" |
+ |
+namespace mojo { |
+namespace nacl { |
+ |
+class PexeTranslatorImpl : public PexeTranslator { |
+ public: |
+ void PexeTranslate(ScopedMessagePipeHandle handle) override { |
Mark Seaborn
2015/10/20 22:28:58
Nit: fix indentation -- this is indented by 3
Sean Klein
2015/10/22 21:50:01
Done.
|
+// int nexe_fd = open("native_client/toolchain/linux_x86/pnacl_translator" |
+// "/translator/x86-32-nonsfi/bin/pnacl-llc.nexe", |
+ int nexe_fd = open("sean_out/pnacl-llc.nexe", O_RDONLY); |
+ if (nexe_fd < 0) |
+ LOG(FATAL) << "Could not open compiler nexe"; |
Mark Seaborn
2015/10/20 22:28:58
It would be nice to report the filename in these e
Sean Klein
2015/10/22 21:50:01
Done.
|
+ ::nacl::MojoLaunchNexeNonsfi(nexe_fd, handle.Pass().get().value()); |
Mark Seaborn
2015/10/20 22:28:58
I think you can do handle.release().value() instea
Sean Klein
2015/10/22 21:50:01
Done.
|
+ } |
+}; |
+ |
+class StrongBindingPexeTranslatorImpl : public PexeTranslatorImpl { |
Mark Seaborn
2015/10/20 22:28:58
How come this is a separate class from PexeTransla
Sean Klein
2015/10/22 21:50:01
This is based on the echo server's model here: htt
|
+ public: |
+ explicit StrongBindingPexeTranslatorImpl(InterfaceRequest<PexeTranslator> |
+ request) |
+ : strong_binding_(this, request.Pass()) {} |
+ |
+ private: |
+ StrongBinding<PexeTranslator> strong_binding_; |
+}; |
+ |
+class MultiPexeTranslator : public mojo::ApplicationDelegate, |
Mark Seaborn
2015/10/20 22:28:58
What does the "Multi" part mean? If we try to tra
Sean Klein
2015/10/22 21:50:01
As I mentioned earlier, I followed a similar struc
|
+ public mojo::InterfaceFactory<PexeTranslator> { |
+ public: |
+ MultiPexeTranslator() {} |
+ |
+ // From ApplicationDelegate |
+ bool ConfigureIncomingConnection( |
+ mojo::ApplicationConnection* connection) override { |
+ connection->AddService<PexeTranslator>(this); |
+ return true; |
+ } |
+ |
+ // From InterfaceFactory |
+ void Create(mojo::ApplicationConnection* connection, |
+ mojo::InterfaceRequest<PexeTranslator> request) override { |
+ new StrongBindingPexeTranslatorImpl(request.Pass()); |
+ } |
+}; |
+ |
+} // namespace nacl |
+} // namespace mojo |
+ |
+MojoResult MojoMain(MojoHandle application_request) { |
+ mojo::ApplicationRunner runner(new mojo::nacl::MultiPexeTranslator()); |
+ return runner.Run(application_request); |
+} |