Accessing fields of a dynamic object ?

classic Classic list List threaded Threaded
24 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Accessing fields of a dynamic object ?

Stéphane M.
This post has NOT been accepted by the mailing list yet.
Still playing with ThreadRemotingServer / AsyncProxy (J'ai plus beaucoup de cheveux ^^')... objects are stored in Context when :

contextInstance.addObject(objectName, object);

we can retrieve them back by the dynamic SocketConnexion object.

newObject = socketConnexionInstance.object;

no problem on that.
my question is how to dynamically retrieve a certain object.

Reflect.hasField(socketConnexionInstance, objectName) => false.
Reflect.field(socketConnexionInstance, objectName) => null.

is there a way to get it like in old flash way if Reflect methods do not work ?

new Object = socketConnexion[objectName];

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Stéphane M.
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Stéphane M.
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Stéphane M.
This post has NOT been accepted by the mailing list yet.
untyped (socketConnectionInstance[objectName]) launch an error.

so is there truly no solution to check if an object has been added to a SocketConnection Context ???


Could you give me a hint to add a method to SocketConnection class to check that ?

Checking the __data.protocol.context.objects Hash can't help because the keys have changed. (in Flash-side to Neko-side I guess.)

Help needed. ^^'

Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Stéphane M.
This post has NOT been accepted by the mailing list yet.
This post was updated on .
Maybe if I explain the goal of that, help will come. :)
(sorry for my poor english)

I'm trying to increase the magic of the ThreadRemotingServer/AsyncProxy to let the Server assign dynamically an interface to a connected Client.
So, in Flash client, I could load a default client, or an administrator one, or any kind of Client to a XMLSocket, and assign an adequate interface by the ThreadRemotingServer.
Have a look.


in a ClientsManager singleton class.

...
/**/
public function initializeClientConnection(_c:Client):SocketConnection {
        var n:NetworkLocation = _c.getNetworkLocation();
        trace("ClientsManager.initializeClientConnection() >>> trying to connect to " + n.host + " at port " + n.port);
        var socket:Socket = new Socket();
        socket.addEventListener(Event.CONNECT, _c.onConnect);
        socket.addEventListener(IOErrorEvent.IO_ERROR, _c.onIOError);
        socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, _c.onSecurityError);
        socket.connect(n.host, n.port);
        var context:Context = new Context();
        context.addObject(Std.string(_c.getClientType(), _c);
        return SocketConnection.create(socket, context);
}
...

Client is an interface common to the different Client type.

typedef NetworkLocation = {
        host:String;
        port:Int;
}

enum ClientType {
        DEFAULT; // for the moment.
}

The addContext() method dynamically give the ClientType.
Now we only need to retrieve it serverside.

It should occur with the standard initClientApi() assignation to the ThreadRemotingServer :

/**/
public function initClientApi(_s:SocketConnection, _c:Context):Void {
        var a:Array<String> = Type.getEnumConstructs(ClientType);
        for (i in 0...a.length) {
                var s:String = a[i];

                the problem is here !
                untyped (_s[s]); // crash.
                _s.getProtocol().context.objects.exists(s); // return false.
                _s.getProtocol().context.objects.get(s)); // return null.
                _s.getProtocol().context.objects.getKeys(); // return "h" ??? in place of "DEFAULT" of ClientType.
                Reflect.field(_s, s); // impossible because of the dynamic SocketConnection.
                Reflect.hadField(_s, s); // return false.

        }
}

Like _s.DEFAULT is working, there should be a way to retrieve it dynamically, no ?

Please, help me Obiwan, you're my only hope.
I do not understand well the core of Haxe.

Thanks.
Stéphane.
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Stéphane M.
This post has NOT been accepted by the mailing list yet.
This post was updated on .
There must be a way to check for a particular object in context even if it is obscured with dynamic path in the SocketConnection object :

When I attempt to access any OBJECT_NAME.methods - who has not been Context.addContext() - within dynamic  SocketConnection, I have well :

No such object OBJECT_NAME
called from ...haxe/Unserializer.hx line 227
called from ...haxe/remoting/SocketProtocol.hx line 193
called from ...haxe/remoting/SocketConnection.hx line 107

A simple check method if an Object exists in Context could extend ThreadRemoting/Server possibilities...

Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Stéphane M.
This post has NOT been accepted by the mailing list yet.
I really need help.
Looking in the haxe core is not my cup of tea... I'm plunging into SocketConnection/SocketProtocol/Context classes with no success for now.

It is really amazing.

In one side (flash), Context.addContext("AsyncProxyName", AsyncProxyObject)
In the other side (neko), Context.objects.getKeys() do not even return "AsyncProxyName" while the addContext() method

SocketConnectionInstance.AsyncProxyName do not raise an exception while SocketConnectionInstance.ANotAddedContextName raise a fatal one.

I really think it is a great opportunity to allow Context check for an object, but where to find it ?
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Stéphane M.
This post has NOT been accepted by the mailing list yet.
Without help, I have to use a way not really elegant.

Do you think there is a security problem using such a solution ? (I wonder what would happen if two clients are initialized by initClientAPI at the same moment)


Clientside

• in the ClientsManager singleton class.

public function initializeClientConnection(_c:Client):SocketConnection {
        ......
        context.addObject("CLIENT_PROXY", _c); // ObjectName is hard-defined.
        return SocketConnection.create(socket, context);
}

• in an AbstractClient class.

public function getClientProxyType():ClientProxyType {
        return ClientProxyType.DEFAULT_CLIENT_PROXY; // for example.
}
public var serverProxy(default, null):ServerProxy;

public function new() {
        var connection:SocketConnection = ClientsManager.getOccurence().initializeClientConnection(this);
        switch getClientProxyType() {
                case ClientProxyType.DEFAULT_CLIENT_PROXY: serverProxy = new DefaultServerProxy(connection.DEFAULT_SERVER_PROXY); // or whatever you want.
        }
}


Serverside :

in a Server class :

public function initClientApi(_s:SocketConnection, _c:Context):Void {
        connection = _s;
        context = _c;
        client = new DefaultClientProxy(_s.CLIENT_PROXY); // Retrieve the hard-defined. :(
        client.getClientProxyType(onClientProxyType);
}

public var client:DefaultClientProxy;
public var connection:SocketConnection;
public var context:Context;

public function onClientProxyType(_c:ClientProxyType):Void {
        switch (_c) {
                case ClientProxyType.DEFAULT_CLIENT_PROXY:
                        var serverProxy:AbstractServerProxy = new AbstractServerProxy(connection);
                        context.addObject(Std.string(ServerProxyType.DEFAULT_SERVER_PROXY), serverProxy);
                        serverProxy.clientProxy = new DefaultClientProxy(connection.CLIENT_PROXY);
                }
        }
}


Is this callback onClientProxyType() function secured enough to not assign a serverProxy to the wrong connection/context (in case of multiple connections at the same time) ?

Thanks for your advices.

Stéphane.
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Stéphane M.
This post has NOT been accepted by the mailing list yet.
but the same problem is now to check Context objects within the clientDisconnected() method...

:'(
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Stéphane M.
Now that subscription succeeded, I retry...
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

singmajesty
You should be able to use Reflect.fields or Type.getInstanceFields to  
enumerate properties. I forget if one works for generic, dynamic objects  
and the other doesn't, but feel free to give both a try!




On Wed, 07 Sep 2011 10:25:05 -0700, Stéphane M. <[hidden email]>  
wrote:

> Now that subscription succeeded, I retry...
>
> --
> View this message in context:  
> http://haxe.1354130.n2.nabble.com/Accessing-fields-of-a-dynamic-object-tp6746051p6768734.html
> Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Stéphane M.
The Reflect.fields(), field(), hasField() methods do not work with runtime dynamic properties. Pretty sure of that after having test them in that optic.

About the Type.getInstanceFields(c:Class<Dynamic>) I don't know how to check a socketconnection instance or a context instance...

public function initClientApi(_s:SocketConnection, _c:Context):Void {
    trace(Type.getInstanceFields(_s)); // throws a compilation error "haxe.remoting.SocketConnection should be Class<Dynamic>"
}

If I try strange syntax like, casted or untyped... whatever on _s, or _c, errors at runtime.

Thanks for your time at least...
I was feeling myself so lonely ^^
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Jan_Flanders


On Wed, Sep 7, 2011 at 8:16 PM, Stéphane M. <[hidden email]> wrote:
public function initClientApi(_s:SocketConnection, _c:Context):Void {
   trace(Type.getInstanceFields(_s)); // throws a compilation error "haxe.remoting.SocketConnection should be Class<Dynamic>"
}

The function expects a class as argument, not an instance.

//static function getClassFields( c : Class<Dynamic> ) : Array<String>
//static function getInstanceFields( c : Class<Dynamic> ) : Array<String>

Type.getInstanceFields(SocketConnection)


If needed you can get the class from an instance with:
//static function getClass<T>( o : T ) : Class<T>

Type.getInstanceFields(Type.getClass(_s));

http://haxe.org/api/type

Cheers,

Jan

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Stéphane M.
Of course, I only can agree...
But this cannot help to retrieve dynamically a field of a dynamic object, because it is well the Class who is checked, not the instance ...

For information about the problem, more can be read on the nabble forum-like post...

We do have a method to add an object to a context object, but no method to check if an object has been added to a SocketConnection context...

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Stéphane M.
Really no clue about where to check if Context (SocketConnection) has seen an object added with Context.addObject() method ?...

*angelface*
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Stéphane M.
*prettier angelface*
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Heinz Hölzer-2
In reply to this post by Stéphane M.
Hi Stephane,

this is not possible in this context. You should add a function on the
server side, which returns the available Objects.

class ServerContext {

     public function availableObjects ():Array<String>
     {
         // at this point you can also return which functions are
available on these objects.
         return ["a", "b", "c"];
     }
}

and then you can call this function and use the objects afterwards.

serverProxy.availableObject( function (names) {
     // store names on client side

     for (n in names) {
         // assuming that all of this objects have a function foo.
         myConnection.resolve(n).foo();
     }

});

is this helpful for you??


Am 08.09.2011 18:24, schrieb Stéphane M.:
> Really no clue about where to check if Context (SocketConnection) has seen an
> object added with Context.addObject() method ?...
>
> *angelface*
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Accessing-fields-of-a-dynamic-object-tp6746051p6772534.html
> Sent from the Haxe mailing list archive at Nabble.com.
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Stéphane M.
This post was updated on .
If I understand well...

with :

var myContext:Context = new Context();
myContext.addObject("MY_OBJECT_NAME", myObject);
SocketConnection.create(mySocket, myContext);

it creates a SocketConnection with an access to myObject with :

mySocketConnection.MY_OBJECT_NAME

and in fact,

mySocketConnection.resolve("MY_OBJECT_NAME");

return that same "access" to myObject (in a AsyncConnexion form) !!!


I will have a look right now on your solution, thanks !
Thanks a lot !!!
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

Heinz Hölzer-2
yes, the client doesn't know at all which objects are available it just
sends the objectName, the function and the arguments to the server and then
it's resolved on the server side.

Please correct me someone if i'm wrong ;)


Am 09.09.2011 11:19, schrieb Stéphane M.:

> If I understand well...
>
> with :
>
> var myContext:Context = new Context();
> myContext.addObject("MY_OBJECT_NAME", myObject);
> SocketConnection.create(mySocket, myContext);
>
> it creates a SocketConnection with an access to myObject with :
>
> mySocketConnection.MY_OBJECT_NAME
>
> and in fact,
>
> mySocketConnection.resolve("MY_OBJECT_NAME");
>
> return that same "access" to myObject (in a SocketConnexion form) !!!
>
>
> I will have a look right now on your solution, thanks !
> Thanks a lot !!!
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Accessing-fields-of-a-dynamic-object-tp6746051p6775377.html
> Sent from the Haxe mailing list archive at Nabble.com.
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Accessing fields of a dynamic object ?

bubblebenj
Not sure it's what you're looking for but using remoting proxy could help you with typing

Ben

2011/9/9 Heinz Hölzer <[hidden email]>
yes, the client doesn't know at all which objects are available it just sends the objectName, the function and the arguments to the server and then
it's resolved on the server side.

Please correct me someone if i'm wrong ;)


Am 09.09.2011 11:19, schrieb Stéphane M.:

If I understand well...

with :

var myContext:Context = new Context();
myContext.addObject("MY_OBJECT_NAME", myObject);
SocketConnection.create(mySocket, myContext);

it creates a SocketConnection with an access to myObject with :

mySocketConnection.MY_OBJECT_NAME

and in fact,

mySocketConnection.resolve("MY_OBJECT_NAME");

return that same "access" to myObject (in a SocketConnexion form) !!!


I will have a look right now on your solution, thanks !
Thanks a lot !!!

--
View this message in context: http://haxe.1354130.n2.nabble.com/Accessing-fields-of-a-dynamic-object-tp6746051p6775377.html
Sent from the Haxe mailing list archive at Nabble.com.



--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
12