Ejemplo n.º 1
0
	HTTPClientBinding::HTTPClientBinding(Host* host) : 
		host(host),global(host->GetGlobalObject()),
		thread(NULL),response(NULL),async(true),filestream(NULL)
	{
		this->SetMethod("abort",&HTTPClientBinding::Abort);
		this->SetMethod("open",&HTTPClientBinding::Open);
		this->SetMethod("setRequestHeader",&HTTPClientBinding::SetRequestHeader);
		this->SetMethod("send",&HTTPClientBinding::Send);
		this->SetMethod("sendFile",&HTTPClientBinding::SendFile);
		this->SetMethod("sendDir",&HTTPClientBinding::SendDir);
		this->SetMethod("getResponseHeader",&HTTPClientBinding::GetResponseHeader);

		SET_INT_PROP("readyState",0)
		SET_INT_PROP("UNSENT",0)
		SET_INT_PROP("OPENED",1)
		SET_INT_PROP("HEADERS_RECEIVED",2)
		SET_INT_PROP("LOADING",3)
		SET_INT_PROP("DONE",4)
		SET_NULL_PROP("responseText")
		SET_NULL_PROP("responseXML")
		SET_NULL_PROP("status")
		SET_NULL_PROP("statusText")
		SET_BOOL_PROP("connected",false)
		SET_NULL_PROP("onreadystatechange")
		SET_NULL_PROP("ondatastream")

		this->self = Value::NewObject(this);
	}
Ejemplo n.º 2
0
    static
    JSBool
    getEvents(JSContext *cx, JSObject *, uintN, jsval *, jsval *rval)
    {
        JSObject * jsarray;
        if (!(jsarray=JS_NewArrayObject(cx, 0, NULL))) return JS_FALSE;
        *rval=OBJECT_TO_JSVAL(jsarray);
        SDL_Event event;
        unsigned i=0;
        while ( SDL_PollEvent(&event) ) {
            JSObject *jseventobj;
            if (!(jseventobj=JS_NewObject(cx, NULL, NULL, NULL))) return JS_FALSE;
            jsval jsevent=OBJECT_TO_JSVAL(jseventobj);
            if (!JS_SetElement(cx, jsarray, i, &jsevent)) return JS_FALSE;

            SET_NUM_PROP(event,type);

            switch (event.type) {
            case SDL_ACTIVEEVENT:
                SET_BOOL_PROP(event.active,gain);
                SET_NUM_PROP(event.active,state);
                break;
            case SDL_KEYDOWN:
            case SDL_KEYUP:
                SET_NUM_PROP (event.key,which);
                SET_BOOL_PROP(event.key,state);
                // platform dependent
                //	SET_NUM_PROP(event.key.keysym,scancode);
                SET_NUM_PROP (event.key.keysym,sym);
                SET_NUM_PROP (event.key.keysym,mod);
                SET_NUM_PROP (event.key.keysym,unicode);
                break;
            case SDL_MOUSEMOTION:
                SET_NUM_PROP (event.motion,which);
                SET_BOOL_PROP(event.motion,state);
                SET_NUM_PROP (event.motion,x);
                SET_NUM_PROP (event.motion,y);
                SET_NUM_PROP (event.motion,xrel);
                SET_NUM_PROP (event.motion,yrel);
                break;
            case SDL_MOUSEBUTTONDOWN:
            case SDL_MOUSEBUTTONUP:
                SET_NUM_PROP (event.button,which);
                SET_NUM_PROP (event.button,button);
                SET_BOOL_PROP(event.button,state);
                SET_NUM_PROP (event.button,x);
                SET_NUM_PROP (event.button,y);
                break;
            case SDL_JOYAXISMOTION:
                SET_NUM_PROP (event.jaxis,which);
                SET_NUM_PROP (event.jaxis,axis);
                SET_NUM_PROP (event.jaxis,value);
                break;
            case SDL_JOYBALLMOTION:
                SET_NUM_PROP (event.jball,which);
                SET_NUM_PROP (event.jball,ball);
                SET_NUM_PROP (event.jball,xrel);
                SET_NUM_PROP (event.jball,yrel);
                break;
            case SDL_JOYHATMOTION:
                SET_NUM_PROP (event.jhat,which);
                SET_NUM_PROP (event.jhat,hat);
                SET_NUM_PROP (event.jhat,value);
                break;
            case SDL_JOYBUTTONDOWN:
            case SDL_JOYBUTTONUP:
                SET_NUM_PROP (event.jbutton,which);
                SET_NUM_PROP (event.jbutton,button);
                SET_BOOL_PROP(event.jbutton,state);
            case SDL_QUIT:
                break;
            case SDL_VIDEORESIZE:
                SET_NUM_PROP (event.resize,w);
                SET_NUM_PROP (event.resize,h);
            case SDL_VIDEOEXPOSE:
                break;
            default:
                EJS_INFO("Got unknown event => we drop it ("<<unsigned(event.type)<<")");
            }
            ++i;
        }
        return JS_TRUE;
    }