platform/packages/wings/lib/src/angel_wings.cc

55 lines
1.8 KiB
C++
Raw Normal View History

2019-09-29 05:26:27 +00:00
#include "angel_wings.h"
#include <cstdlib>
2019-09-29 05:26:27 +00:00
#include <dart_api.h>
#include <iostream>
#include <string.h>
// The name of the initialization function is the extension name followed
// by _Init.
2019-09-29 05:26:27 +00:00
DART_EXPORT Dart_Handle angel_wings_Init(Dart_Handle parent_library) {
2019-04-27 19:12:09 +00:00
if (Dart_IsError(parent_library))
return parent_library;
Dart_Handle result_code =
Dart_SetNativeResolver(parent_library, ResolveName, NULL);
2019-04-27 19:12:09 +00:00
if (Dart_IsError(result_code))
return result_code;
return Dart_Null();
}
2019-09-29 05:26:27 +00:00
Dart_Handle HandleError(Dart_Handle handle) {
2019-04-27 19:12:09 +00:00
if (Dart_IsError(handle))
Dart_PropagateError(handle);
return handle;
}
2019-09-29 05:26:27 +00:00
Dart_NativeFunction ResolveName(Dart_Handle name, int argc,
bool *auto_setup_scope) {
// If we fail, we return NULL, and Dart throws an exception.
2019-04-27 19:12:09 +00:00
if (!Dart_IsString(name))
return NULL;
Dart_NativeFunction result = NULL;
2019-04-27 19:12:09 +00:00
const char *cname;
HandleError(Dart_StringToCString(name, &cname));
2019-04-27 19:12:09 +00:00
if (strcmp("Dart_WingsSocket_bindIPv4", cname) == 0)
result = Dart_WingsSocket_bindIPv4;
if (strcmp("Dart_WingsSocket_bindIPv6", cname) == 0)
result = Dart_WingsSocket_bindIPv6;
2019-05-01 01:33:46 +00:00
if (strcmp("Dart_WingsSocket_getAddress", cname) == 0)
result = Dart_WingsSocket_getAddress;
2019-04-27 19:12:09 +00:00
if (strcmp("Dart_WingsSocket_getPort", cname) == 0)
result = Dart_WingsSocket_getPort;
if (strcmp("Dart_WingsSocket_write", cname) == 0)
result = Dart_WingsSocket_write;
if (strcmp("Dart_WingsSocket_closeDescriptor", cname) == 0)
result = Dart_WingsSocket_closeDescriptor;
if (strcmp("Dart_WingsSocket_close", cname) == 0)
result = Dart_WingsSocket_close;
2019-04-29 05:55:02 +00:00
if (strcmp("Dart_WingsSocket_listen", cname) == 0)
result = Dart_WingsSocket_listen;
2019-04-29 08:22:36 +00:00
if (strcmp("Dart_WingsSocket_parseHttp", cname) == 0)
result = Dart_WingsSocket_parseHttp;
return result;
}