| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BIN_NATIVE_SERVICE_H_ | |
| 6 #define BIN_NATIVE_SERVICE_H_ | |
| 7 | |
| 8 #include "include/dart_api.h" | |
| 9 #include "include/dart_native_api.h" | |
| 10 #include "platform/globals.h" | |
| 11 #include "platform/thread.h" | |
| 12 | |
| 13 | |
| 14 namespace dart { | |
| 15 namespace bin { | |
| 16 | |
| 17 // Utility class to set up a native service and allocate Dart native | |
| 18 // ports to interact with it from Dart code. The number of native ports | |
| 19 // allocated for each service is limited. | |
| 20 class NativeService { | |
| 21 public: | |
| 22 // Create a native service with the given name and handler. Allow | |
| 23 // the creation of [number_of_ports] native ports for the service. | |
| 24 // If GetServicePort is called more than [number_of_ports] times | |
| 25 // one of the already allocated native ports will be reused. | |
| 26 NativeService(const char* name, | |
| 27 Dart_NativeMessageHandler handler, | |
| 28 int number_of_ports); | |
| 29 | |
| 30 ~NativeService(); | |
| 31 | |
| 32 // Get a Dart native port for this native service. | |
| 33 Dart_Port GetServicePort(); | |
| 34 | |
| 35 private: | |
| 36 // Name and handler for the native service. | |
| 37 const char* name_; | |
| 38 Dart_NativeMessageHandler handler_; | |
| 39 | |
| 40 // Allocated native ports for the service. Mutex protected since | |
| 41 // the service can be used from multiple isolates. | |
| 42 dart::Mutex mutex_; | |
| 43 int service_ports_size_; | |
| 44 Dart_Port* service_ports_; | |
| 45 int service_ports_index_; | |
| 46 | |
| 47 DISALLOW_IMPLICIT_CONSTRUCTORS(NativeService); | |
| 48 }; | |
| 49 | |
| 50 } // namespace bin | |
| 51 } // namespace dart | |
| 52 | |
| 53 #endif // BIN_NATIVE_SERVICE_H_ | |
| OLD | NEW |