Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart 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 file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bin/directory.h" | 5 #include "bin/directory.h" |
| 6 | 6 |
| 7 #include "bin/dartutils.h" | 7 #include "bin/dartutils.h" |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 | 10 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 Dart_EnterScope(); | 122 Dart_EnterScope(); |
| 123 Dart_Handle path = Dart_GetNativeArgument(args, 0); | 123 Dart_Handle path = Dart_GetNativeArgument(args, 0); |
| 124 if (Dart_IsString(path)) { | 124 if (Dart_IsString(path)) { |
| 125 bool deleted = Directory::Delete(DartUtils::GetStringValue(path)); | 125 bool deleted = Directory::Delete(DartUtils::GetStringValue(path)); |
| 126 Dart_SetReturnValue(args, Dart_NewBoolean(deleted)); | 126 Dart_SetReturnValue(args, Dart_NewBoolean(deleted)); |
| 127 } else { | 127 } else { |
| 128 Dart_SetReturnValue(args, Dart_NewBoolean(false)); | 128 Dart_SetReturnValue(args, Dart_NewBoolean(false)); |
| 129 } | 129 } |
| 130 Dart_ExitScope(); | 130 Dart_ExitScope(); |
| 131 } | 131 } |
| 132 | |
| 133 | |
| 134 void DirectoryCreateService(Dart_Port dest_port_id, | |
| 135 Dart_Port reply_port_id, | |
| 136 Dart_CMessage* message) { | |
| 137 Dart_CMessage response; | |
|
Mads Ager (google)
2012/02/03 14:09:32
We should streamline this. 5 lines just to create
Søren Gjesse
2012/02/15 15:09:39
Working on adding dartutil stuff for this while po
| |
| 138 Dart_CObject object; | |
| 139 response.root = &object; | |
| 140 object.type = Dart_CObject::kBool; | |
| 141 object.value.as_bool = false; | |
| 142 | |
| 143 if (message->root->type == Dart_CObject::kString) { | |
| 144 bool created = Directory::Create(message->root->value.as_string); | |
| 145 object.value.as_bool = created; | |
| 146 } | |
| 147 | |
| 148 Dart_PostCMessage(reply_port_id, &response); | |
| 149 } | |
| 150 | |
| 151 | |
| 152 void DirectoryDeleteService(Dart_Port dest_port_id, | |
| 153 Dart_Port reply_port_id, | |
| 154 Dart_CMessage* message) { | |
| 155 Dart_CMessage response; | |
| 156 Dart_CObject object; | |
| 157 response.root = &object; | |
| 158 object.type = Dart_CObject::kBool; | |
| 159 object.value.as_bool = false; | |
| 160 | |
| 161 if (message->root->type == Dart_CObject::kString) { | |
|
Mads Ager (google)
2012/02/03 14:09:32
This takes a bool too now. Should be easy to updat
Søren Gjesse
2012/02/15 15:09:39
Done.
| |
| 162 bool created = Directory::Delete(message->root->value.as_string); | |
|
Mads Ager (google)
2012/02/03 14:09:32
deleted
Søren Gjesse
2012/02/15 15:09:39
Done.
| |
| 163 object.value.as_bool = created; | |
| 164 } | |
| 165 | |
| 166 Dart_PostCMessage(reply_port_id, &response); | |
| 167 } | |
| 168 | |
| 169 | |
| 170 static const int kCreateService = 0; | |
| 171 static const int kDeleteService = 1; | |
| 172 | |
| 173 | |
| 174 void FUNCTION_NAME(Directory_NewServicePort)(Dart_NativeArguments args) { | |
| 175 Dart_EnterScope(); | |
| 176 Dart_SetReturnValue(args, Dart_Null()); | |
| 177 Dart_Handle service_id = Dart_GetNativeArgument(args, 0); | |
| 178 if (Dart_IsInteger(service_id)) { | |
| 179 int64_t value; | |
| 180 Dart_Handle result = Dart_IntegerToInt64(service_id, &value); | |
| 181 if (!Dart_IsError(result)) { | |
| 182 Dart_Port service_port = kIllegalPort; | |
| 183 switch (value) { | |
| 184 case kCreateService: | |
| 185 service_port = Dart_NewNativePort("DirectoryCreateService", | |
| 186 DirectoryCreateService, | |
| 187 true); | |
| 188 break; | |
| 189 case kDeleteService: | |
| 190 service_port = Dart_NewNativePort("DirectoryDeleteService", | |
| 191 DirectoryDeleteService, | |
| 192 true); | |
| 193 break; | |
| 194 } | |
| 195 if (service_port != kIllegalPort) { | |
| 196 // Return a send port for the service port. | |
| 197 Dart_Handle send_port = Dart_NewSendPort(service_port); | |
| 198 Dart_SetReturnValue(args, send_port); | |
| 199 } | |
| 200 } | |
| 201 } | |
| 202 Dart_ExitScope(); | |
| 203 } | |
| OLD | NEW |