| OLD | NEW |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 #include "src/vm/service_api_impl.h" | 5 #include "src/vm/service_api_impl.h" |
| 6 | 6 |
| 7 #include "src/vm/natives.h" | 7 #include "src/vm/natives.h" |
| 8 #include "src/vm/port.h" | 8 #include "src/vm/port.h" |
| 9 #include "src/vm/process.h" | 9 #include "src/vm/process.h" |
| 10 #include "src/vm/scheduler.h" | 10 #include "src/vm/scheduler.h" |
| 11 #include "src/vm/thread.h" | 11 #include "src/vm/thread.h" |
| 12 | 12 |
| 13 static const int kRequestHeaderSize = 32; | 13 static const int kRequestHeaderSize = 32; |
| 14 | 14 |
| 15 namespace fletch { | 15 namespace dartino { |
| 16 | 16 |
| 17 class ServiceRegistry { | 17 class ServiceRegistry { |
| 18 public: | 18 public: |
| 19 ServiceRegistry() : monitor_(Platform::CreateMonitor()), service_(NULL) {} | 19 ServiceRegistry() : monitor_(Platform::CreateMonitor()), service_(NULL) {} |
| 20 | 20 |
| 21 ~ServiceRegistry() { | 21 ~ServiceRegistry() { |
| 22 while (service_ != NULL) { | 22 while (service_ != NULL) { |
| 23 Service* tmp = service_; | 23 Service* tmp = service_; |
| 24 service_ = service_->next(); | 24 service_ = service_->next(); |
| 25 delete tmp; | 25 delete tmp; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 Port* port = Port::FromDartObject(port_instance); | 170 Port* port = Port::FromDartObject(port_instance); |
| 171 if (port == NULL) return Failure::illegal_state(); | 171 if (port == NULL) return Failure::illegal_state(); |
| 172 char* name = AsForeignString(arguments[0]); | 172 char* name = AsForeignString(arguments[0]); |
| 173 if (name == NULL) return Failure::illegal_state(); | 173 if (name == NULL) return Failure::illegal_state(); |
| 174 Service* service = new Service(name, port); | 174 Service* service = new Service(name, port); |
| 175 service_registry->Register(service); | 175 service_registry->Register(service); |
| 176 return process->program()->null_object(); | 176 return process->program()->null_object(); |
| 177 } | 177 } |
| 178 END_NATIVE() | 178 END_NATIVE() |
| 179 | 179 |
| 180 } // namespace fletch | 180 } // namespace dartino |
| 181 | 181 |
| 182 void ServiceApiSetup() { | 182 void ServiceApiSetup() { |
| 183 fletch::service_registry = new fletch::ServiceRegistry(); | 183 dartino::service_registry = new dartino::ServiceRegistry(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void ServiceApiTearDown() { | 186 void ServiceApiTearDown() { |
| 187 delete fletch::service_registry; | 187 delete dartino::service_registry; |
| 188 fletch::service_registry = NULL; | 188 dartino::service_registry = NULL; |
| 189 } | 189 } |
| 190 | 190 |
| 191 ServiceId ServiceApiLookup(const char* name) { | 191 ServiceId ServiceApiLookup(const char* name) { |
| 192 fletch::Service* service = fletch::service_registry->LookupService(name); | 192 dartino::Service* service = dartino::service_registry->LookupService(name); |
| 193 return reinterpret_cast<ServiceId>(service); | 193 return reinterpret_cast<ServiceId>(service); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void ServiceApiInvoke(ServiceId service_id, MethodId method, void* buffer, | 196 void ServiceApiInvoke(ServiceId service_id, MethodId method, void* buffer, |
| 197 int size) { | 197 int size) { |
| 198 fletch::Service* service = reinterpret_cast<fletch::Service*>(service_id); | 198 dartino::Service* service = reinterpret_cast<dartino::Service*>(service_id); |
| 199 intptr_t method_id = reinterpret_cast<intptr_t>(method); | 199 intptr_t method_id = reinterpret_cast<intptr_t>(method); |
| 200 service->Invoke(method_id, buffer, size); | 200 service->Invoke(method_id, buffer, size); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void ServiceApiInvokeAsync(ServiceId service_id, MethodId method, | 203 void ServiceApiInvokeAsync(ServiceId service_id, MethodId method, |
| 204 ServiceApiCallback callback, void* buffer, | 204 ServiceApiCallback callback, void* buffer, |
| 205 int size) { | 205 int size) { |
| 206 fletch::Service* service = reinterpret_cast<fletch::Service*>(service_id); | 206 dartino::Service* service = reinterpret_cast<dartino::Service*>(service_id); |
| 207 intptr_t method_id = reinterpret_cast<intptr_t>(method); | 207 intptr_t method_id = reinterpret_cast<intptr_t>(method); |
| 208 service->InvokeAsync(method_id, callback, buffer, size); | 208 service->InvokeAsync(method_id, callback, buffer, size); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void ServiceApiTerminate(ServiceId service_id) { | 211 void ServiceApiTerminate(ServiceId service_id) { |
| 212 char buffer[kRequestHeaderSize]; | 212 char buffer[kRequestHeaderSize]; |
| 213 ServiceApiInvoke(service_id, kTerminateMethodId, buffer, sizeof(buffer)); | 213 ServiceApiInvoke(service_id, kTerminateMethodId, buffer, sizeof(buffer)); |
| 214 fletch::Service* service = reinterpret_cast<fletch::Service*>(service_id); | 214 dartino::Service* service = reinterpret_cast<dartino::Service*>(service_id); |
| 215 fletch::service_registry->Unregister(service); | 215 dartino::service_registry->Unregister(service); |
| 216 } | 216 } |
| OLD | NEW |