コード例 #1
0
ファイル: os_posix.cpp プロジェクト: cwyiu/fibjs
result_t os_base::networkInfo(v8::Local<v8::Object> &retVal)
{
    struct ::ifaddrs *addrs, *ent;
    struct ::sockaddr_in *in4;
    struct ::sockaddr_in6 *in6;
    char ip[INET6_ADDRSTRLEN];

    if (getifaddrs(&addrs) != 0)
        return LastError();

    retVal = v8::Object::New(isolate);

    for (ent = addrs; ent != NULL; ent = ent->ifa_next)
    {
        v8::Local<v8::Array> ret;
        v8::Local<v8::Object> o;
        v8::Local<v8::String> name, ipaddr, family;

        bzero(&ip, sizeof(ip));
        if (!(ent->ifa_flags & IFF_UP && ent->ifa_flags & IFF_RUNNING))
            continue;

        if (ent->ifa_addr == NULL)
            continue;

        if (ent->ifa_addr->sa_family != AF_INET6
                && ent->ifa_addr->sa_family != AF_INET)
            continue;

        name = v8::String::NewFromUtf8(isolate, ent->ifa_name);
        if (retVal->Has(name))
        {
            ret = v8::Local<v8::Array>::Cast(retVal->Get(name));
        }
        else
        {
            ret = v8::Array::New(isolate);
            retVal->Set(name, ret);
        }

        if (ent->ifa_addr->sa_family == AF_INET6)
        {
            in6 = (struct sockaddr_in6 *) ent->ifa_addr;
            inet_ntop(AF_INET6, &(in6->sin6_addr), ip, INET6_ADDRSTRLEN);
            family = v8::String::NewFromUtf8(isolate, "IPv6");
        }
        else if (ent->ifa_addr->sa_family == AF_INET)
        {
            in4 = (struct sockaddr_in *) ent->ifa_addr;
            inet_ntop(AF_INET, &(in4->sin_addr), ip, INET6_ADDRSTRLEN);
            family = v8::String::NewFromUtf8(isolate, "IPv4");
        }

        o = v8::Object::New(isolate);
        o->Set(v8::String::NewFromUtf8(isolate, "address"), v8::String::NewFromUtf8(isolate, ip));
        o->Set(v8::String::NewFromUtf8(isolate, "family"), family);
        o->Set(v8::String::NewFromUtf8(isolate, "internal"),
               ent->ifa_flags & IFF_LOOPBACK ? v8::True(isolate) : v8::False(isolate));

        ret->Set(ret->Length(), o);
    }

    freeifaddrs(addrs);

    return 0;
}
コード例 #2
0
ファイル: nodeutil.cpp プロジェクト: amrsobhy/qminer
bool TNodeJsUtil::IsObjFld(v8::Local<v8::Object> Obj, const TStr& FldNm) {
	v8::Isolate* Isolate = v8::Isolate::GetCurrent();
	v8::HandleScope HandleScope(Isolate);

	return Obj->Has(v8::String::NewFromUtf8(Isolate, FldNm.CStr()));
}
コード例 #3
0
/// Extracts texture compiler arguments from an object passed from JavaScript.
/// @param obj An object specifying the texture compiler arguments.
/// @param obj.sourcePath A string specifying the path of the source file.
/// @param obj.targetPath A string specifying the path of the target file.
/// @param args Pointer to the texture_compiler_args_t structure to populate.
/// @return undefined if the operation is successful; otherwise a V8 exception.
static v8::Handle<v8::Value> v8_object_to_compiler_args(
    v8::Local<v8::Object>    obj,
    texture_compiler_args_t *args)
{
    v8::HandleScope          scope;
    v8::Handle<v8::String>   type          = v8::String::New("type");
    v8::Handle<v8::String>   flipY         = v8::String::New("flipY");
    v8::Handle<v8::String>   format        = v8::String::New("format");
    v8::Handle<v8::String>   target        = v8::String::New("target");
    v8::Handle<v8::String>   wrapModeS     = v8::String::New("wrapModeS");
    v8::Handle<v8::String>   wrapModeT     = v8::String::New("wrapModeT");
    v8::Handle<v8::String>   borderMode    = v8::String::New("borderMode");
    v8::Handle<v8::String>   sourcePath    = v8::String::New("sourcePath");
    v8::Handle<v8::String>   targetPath    = v8::String::New("targetPath");
    v8::Handle<v8::String>   targetWidth   = v8::String::New("targetWidth");
    v8::Handle<v8::String>   targetHeight  = v8::String::New("targetHeight");
    v8::Handle<v8::String>   minifyFilter  = v8::String::New("minifyFilter");
    v8::Handle<v8::String>   magnifyFilter = v8::String::New("magnifyFilter");
    v8::Handle<v8::String>   premultiplied = v8::String::New("premultipliedAlpha");
    v8::Handle<v8::String>   forcePowerOf2 = v8::String::New("forcePowerOf2");
    v8::Handle<v8::String>   buildMipmaps  = v8::String::New("buildMipmaps");
    v8::Handle<v8::String>   levelCount    = v8::String::New("levelCount");

    // source file path. this field is required.
    init_compiler_args(args);
    if (obj->Has(sourcePath))
        args->source_path = v8_string_to_utf8(obj->Get(sourcePath));
    else
        return scope.Close(ex("Missing required field sourcePath."));

    // target file path. this field is required.
    if (obj->Has(targetPath))
        args->target_path = v8_string_to_utf8(obj->Get(targetPath));
    else
        return scope.Close(ex("Missing required field targetPath."));

    // texture type. this field must be validated later.
    if (obj->Has(type))
        args->texture_type = v8_string_to_utf8(obj->Get(type));

    // texture format. this field must be validated later.
    if (obj->Has(format))
        args->target_format = v8_string_to_utf8(obj->Get(format));

    // texture target. this field must be validated later.
    if (obj->Has(target))
        args->texture_target = v8_string_to_utf8(obj->Get(target));

    // border mode. this field is optional.
    if (obj->Has(borderMode))
        args->border_mode =v8_string_to_utf8(obj->Get(borderMode));

    // flip Y. this field is optional.
    if (obj->Has(flipY))
        args->flip_y = obj->Get(flipY)->IsTrue() ? true : false;
    else
        args->flip_y = true;

    // force power of two? this field is optional.
    if (obj->Has(forcePowerOf2))
        args->force_pow2 = obj->Get(forcePowerOf2)->IsTrue() ? true : false;
    else
        args->force_pow2 = false;

    // build mipmaps? this field is optional.
    if (obj->Has(buildMipmaps))
        args->build_mipmaps = obj->Get(buildMipmaps)->IsTrue() ? true : false;
    else
        args->build_mipmaps = false;

    // premultiply alpha? this field is optional.
    if (obj->Has(premultiplied))
        args->premultiplied = obj->Get(premultiplied)->IsTrue() ? true : false;
    else
        args->premultiplied = false;

    // maximum number of mip-levels? this field is optional.
    if (obj->Has(levelCount))
        args->level_count = obj->Get(levelCount)->Uint32Value();
    else
        args->level_count = args->build_mipmaps ? 0 : 1;

    // specific output width? this field is optional.
    if (obj->Has(targetWidth))
        args->target_width = obj->Get(targetWidth)->Uint32Value();
    else
        args->target_width = 0;

    // specific otput height? this field is optional.
    if (obj->Has(targetHeight))
        args->target_height = obj->Get(targetHeight)->Uint32Value();
    else
        args->target_height = 0;

    // wrap mode S? this field is optional.
    if (obj->Has(wrapModeS))
        args->wrap_mode_s = v8_string_to_utf8(obj->Get(wrapModeS));
    else
        args->wrap_mode_s = strdup("CLAMP_TO_EDGE");

    // wrap mode T? this field is optional.
    if (obj->Has(wrapModeT))
        args->wrap_mode_t = v8_string_to_utf8(obj->Get(wrapModeT));
    else
        args->wrap_mode_t = strdup("CLAMP_TO_EDGE");

    // minify filter? this field is optional.
    if (obj->Has(minifyFilter))
    {
        args->minify_filter = v8_string_to_utf8(obj->Get(minifyFilter));
    }
    else
    {
        if (args->build_mipmaps)
            args->minify_filter = strdup("LINEAR_MIPMAP_LINEAR");
        else
            args->minify_filter = strdup("LINEAR");
    }

    // magnify filter? this field is optional.
    if (obj->Has(magnifyFilter))
        args->magnify_filter = v8_string_to_utf8(obj->Get(magnifyFilter));
    else
        args->magnify_filter = strdup("LINEAR");
    return scope.Close(v8::Undefined());
}