1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_ZIRCON_SDK_EXT_SYSTEM_H_ 6 #define FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_ZIRCON_SDK_EXT_SYSTEM_H_ 7 8 #include <zircon/syscalls.h> 9 10 #include "handle.h" 11 #include "third_party/dart/runtime/include/dart_api.h" 12 #include "third_party/tonic/dart_library_natives.h" 13 #include "third_party/tonic/dart_wrappable.h" 14 #include "third_party/tonic/typed_data/dart_byte_data.h" 15 16 // TODO (kaushikiska): Once fuchsia adds fs to their sdk, 17 // use the rights macros from "fs/vfs.h" 18 19 // Rights 20 // The file may be read. 21 #define ZX_FS_RIGHT_READABLE 0x00000001 22 // The file may be written. 23 #define ZX_FS_RIGHT_WRITABLE 0x00000002 24 25 namespace zircon { 26 namespace dart { 27 28 class System : public fml::RefCountedThreadSafe<System>, 29 public tonic::DartWrappable { 30 DEFINE_WRAPPERTYPEINFO(); 31 FML_FRIEND_REF_COUNTED_THREAD_SAFE(System); 32 FML_FRIEND_MAKE_REF_COUNTED(System); 33 34 public: 35 static Dart_Handle ChannelCreate(uint32_t options); 36 static Dart_Handle ChannelFromFile(std::string path); 37 static zx_status_t ChannelWrite(fml::RefPtr<Handle> channel, 38 const tonic::DartByteData& data, 39 std::vector<Handle*> handles); 40 // TODO(ianloic): Add ChannelRead 41 static Dart_Handle ChannelQueryAndRead(fml::RefPtr<Handle> channel); 42 43 static Dart_Handle EventpairCreate(uint32_t options); 44 45 static Dart_Handle SocketCreate(uint32_t options); 46 static Dart_Handle SocketWrite(fml::RefPtr<Handle> socket, 47 const tonic::DartByteData& data, 48 int options); 49 static Dart_Handle SocketRead(fml::RefPtr<Handle> socket, size_t size); 50 51 static Dart_Handle VmoCreate(uint64_t size, uint32_t options); 52 static Dart_Handle VmoFromFile(std::string path); 53 static Dart_Handle VmoGetSize(fml::RefPtr<Handle> vmo); 54 static zx_status_t VmoSetSize(fml::RefPtr<Handle> vmo, uint64_t size); 55 static zx_status_t VmoWrite(fml::RefPtr<Handle> vmo, 56 uint64_t offset, 57 const tonic::DartByteData& data); 58 static Dart_Handle VmoRead(fml::RefPtr<Handle> vmo, 59 uint64_t offset, 60 size_t size); 61 62 static Dart_Handle VmoMap(fml::RefPtr<Handle> vmo); 63 64 static uint64_t ClockGet(uint32_t clock_id); 65 66 static void RegisterNatives(tonic::DartLibraryNatives* natives); 67 68 static zx_status_t ConnectToService(std::string path, 69 fml::RefPtr<Handle> channel); 70 71 private: 72 static void VmoMapFinalizer(void* isolate_callback_data, 73 Dart_WeakPersistentHandle handle, 74 void* peer); 75 76 static zx::channel CloneChannelFromFileDescriptor(int fd); 77 }; 78 79 } // namespace dart 80 } // namespace zircon 81 82 #endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_ZIRCON_SDK_EXT_SYSTEM_H_ 83