| 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 "platform/globals.h" |
| 10 #include "platform/thread.h" |
| 11 |
| 12 // Utility class to set up a native service and allocate Dart native |
| 13 // ports to interact with it from Dart code. The number of native ports |
| 14 // allocated for each service is limited. |
| 15 class NativeService { |
| 16 public: |
| 17 // Create a native service with the given name and handler. Allow |
| 18 // the creation of [number_of_ports] native ports for the service. |
| 19 // If GetServicePort is called more than [number_of_ports] times |
| 20 // one of the already allocated native ports will be reused. |
| 21 NativeService(const char* name, |
| 22 Dart_NativeMessageHandler handler, |
| 23 int number_of_ports); |
| 24 |
| 25 ~NativeService(); |
| 26 |
| 27 // Get a Dart native port for this native service. |
| 28 Dart_Port GetServicePort(); |
| 29 |
| 30 private: |
| 31 // Name and handler for the native service. |
| 32 const char* name_; |
| 33 Dart_NativeMessageHandler handler_; |
| 34 |
| 35 // Allocated native ports for the service. Mutex protected since |
| 36 // the service can be used from multiple isolates. |
| 37 dart::Mutex mutex_; |
| 38 int service_ports_size_; |
| 39 Dart_Port* service_ports_; |
| 40 int service_ports_index_; |
| 41 |
| 42 DISALLOW_IMPLICIT_CONSTRUCTORS(NativeService); |
| 43 }; |
| 44 |
| 45 #endif // BIN_NATIVE_SERVICE_H_ |
| OLD | NEW |