Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Jan 29, 2020 4:02 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Running instance
PostPosted: Fri Mar 25, 2011 9:14 am 
Offline
User avatar

Joined: Thu Jan 07, 2010 7:57 am
Posts: 72
Location: Solihull UK
Does anyone know how to get a handle to a running instance of a class
That has been instantiated in RB not the plugin itself

Mark


Top
 Profile  
Reply with quote  
 Post subject: Re: Running instance
PostPosted: Fri Mar 25, 2011 9:35 am 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
1) subscribe to the plugins mailing list http://realsoftware.com/support/listmanager/
you're likely to find more answers there

2) check the archives at http://support.realsoftware.com/listarc ... c-plugins/

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
 Post subject: Re: Running instance
PostPosted: Fri Mar 25, 2011 9:51 am 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
The RB code passes it to the function in a function call as parameter?

If the class is declared in the plugin, you can have a constructor there and get your code to run when the instance is created.

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Running instance
PostPosted: Fri Mar 25, 2011 9:59 am 
Offline
User avatar

Joined: Thu Jan 07, 2010 7:57 am
Posts: 72
Location: Solihull UK
Thanks guys I will have a look at the lists, i and using posix threads and trying to find out
Why in the calling function I can call y event defs, go into the thread and you cannot it dies the debugger (Xcode) reports and exec error (it cannot access the pointer, the event fires ok but when in call the actual call with fptr(instance,12)

I know the instance is ok as I can access r/w in the thread on any prop in the plugin

I had a problem with stack space so I increased this. But when im in my running
Thread I cannot fire events.

A real strange one

I pass the instance in the array params when in start the thread, it works great but no events.

Hence why I wanted to the running instance and call this.

Real strange
Mark


Top
 Profile  
Reply with quote  
 Post subject: Re: Running instance
PostPosted: Fri Mar 25, 2011 11:47 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Are you taking into account the extra parameter RB adds to the event call?


Top
 Profile  
Reply with quote  
 Post subject: Re: Running instance
PostPosted: Fri Mar 25, 2011 12:14 pm 
Offline
User avatar

Joined: Thu Jan 07, 2010 7:57 am
Posts: 72
Location: Solihull UK
Yes the REALobject instance

which I assume is a void pointer to the running instance, of course thinking this though it may be that the pointer is invalid
as the RB subsystem is running in another context.

Its fully preemtive tasking , I fire a thread and send it the REALobject instance in the parameter array.

This works fine as I can use
ClassData( TestClassDefinition, myData->instance, TestClassData, me );

me->MooseName=REALbuildString("John",4);

or

if (strcmp(me->mMooseName->CString(),"<Q>")==0){
}

so I know the instance is valid


If I then try and call the event def then it makes the call but dies as it tries to alert RB

Mark


Top
 Profile  
Reply with quote  
 Post subject: Re: Running instance
PostPosted: Fri Mar 25, 2011 12:17 pm 
Offline
User avatar

Joined: Thu Jan 07, 2010 7:57 am
Posts: 72
Location: Solihull UK
FireSignalStrengthEvent( myData->instance, 200 );

static void FireSignalStrengthEvent( REALobject instance,int i)
{
// You can use this helper function to fire the user's Action event. If the user doesn't implement the event,
// then this function will return nil for you. But if the user does implement the event, the the function will
// return the data the caller returns. Try to load the function pointer for our method from the object instance passed in.

void (*fpAction)(REALobject instance,int i) =
(void (*)(REALobject,int))REALGetEventInstance( (REALcontrolInstance)instance, &TestClassEvents[0]);

if (fpAction) {
// The user has implemented the Action event, so now we can call it and return the data.
fpAction( instance,i ); // ************ DIES HERE
}
}

pthread_t threads[NUM_THREADS];
int rc;
long t;

size_t stacksize;
stacksize=sizeof(double) *2*MEGEXTRA;
pthread_attr_t attr;

pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, stacksize);

//ClassData( TestClassDefinition, instance, TestClassData, me );
//me->mMooseName=REALBuildString("Blake", 5);
// Fire the event here it works ok

for(t=0; t<NUM_THREADS; t++){
printf("In main: creating thread %ld\n", t);
thread_data_array[t].thread_id=t;
thread_data_array[t].instance=instance;

rc = pthread_create(&threads[t],&attr, PrintHello, (void *)&thread_data_array[t]);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}



MArk


Top
 Profile  
Reply with quote  
 Post subject: Re: Running instance
PostPosted: Fri Mar 25, 2011 12:32 pm 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
the runtime is not completely re-entrant so that could contribute what you're seeing

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
 Post subject: Re: Running instance
PostPosted: Fri Mar 25, 2011 1:38 pm 
Offline
User avatar

Joined: Thu Jan 07, 2010 7:57 am
Posts: 72
Location: Solihull UK
I thought as much I did think at one stage the pointers were messed up
But I do have another solution which is not ideal but would work I guess
Have a timer the instance variables and fire up the events with this I also had the idea of calling a shared method but your right the runtime is gone so it's gonna be hat much harder to solve.

I guess I need to dream up a callback in c++ and then maybe I could do it that wafireing the event in the callback

Mark


Top
 Profile  
Reply with quote  
 Post subject: Re: Running instance
PostPosted: Fri Mar 25, 2011 5:24 pm 
Offline
User avatar

Joined: Thu Jan 07, 2010 7:57 am
Posts: 72
Location: Solihull UK
Sorted it I now have events firing from all my threads.

How it did it was put a REALclassref in the plugin entry and then in the actual thread
The first thing I do is instantiate a new object using the dynamic access calls
I do not need to do anything with the class just create and instantiate it.
The instance comes alive and points to the rb runtime as the object in the thread is there.

I got the idea from reading about the mechanics if a call back and assigning the pointers.

Hang on if I can do a call back why not instantiate and object as the compiler will not strip our the dead code due to the REALclassref in the plug in entry ..

Bingo it works, the events fire and I can pass parameters and return thew as well

I did have to add a global object of the type I was instantiating and in the app.open instantiate it, but the class does nothing anyway and I use a tcp class which I can use for other things anyway which is way cool.

So I guess all I am using the object in the actual thread code as a helper to get back to the instance of the real class I want whoopee........

I will make the grade as a plugin programmer yet lol

Thanks for all you help guys and I will post some code later as an example
I am so pleased I have events in my plugin now it makes my life so much easier.

Mark


Top
 Profile  
Reply with quote  
 Post subject: Re: Running instance
PostPosted: Fri Mar 25, 2011 5:26 pm 
Offline
User avatar

Joined: Thu Jan 07, 2010 7:57 am
Posts: 72
Location: Solihull UK
I did something as well set the setter of a property to fire the event as well and that works too
Mark


Top
 Profile  
Reply with quote  
 Post subject: Re: Running instance
PostPosted: Fri Mar 25, 2011 6:10 pm 
Offline
User avatar

Joined: Thu Jan 07, 2010 7:57 am
Posts: 72
Location: Solihull UK
I have just had a better idea which is much more controllable. Build a small helper plugin that I can use via dynamic access for all my alerts and method calls back into the main application this ips. Much cleaner I can make it easy to maintain,

Trying to call the main class is a little problematic, so I opted for the second solution which works just as well if not better.

Mark


Top
 Profile  
Reply with quote  
 Post subject: Re: Running instance
PostPosted: Sun Mar 27, 2011 8:25 am 
Offline
User avatar

Joined: Thu Jan 07, 2010 7:57 am
Posts: 72
Location: Solihull UK
Well after further testing the concept sort of worked, adding the stack pragma to rb helped
But I did experience some crashes and at points when it was not expected mainly whe the call returned, do it inside a tight loop and your asking for trouble.

The thread is. Not blocked and you can get into all sorts of issues.

There had to be another way, the is using the ipc socket
In the rb application define an ipc socket and set it listening then in the actual thread create a new ipc socket have a property to hold the path, that the rb side is bound to
Bingo you can connect to the remote rb app and write or read data from the rb app.

Problem solved the thread code can now send alerts back to the rb application using the data available event in the ipc socket.
You can also set the ipc sock to asynchronous and sync operation and actually control the threads operation by using the data available event in the plugin.

It's multi platform as well which is good. This is what the ipc socket was built for a great way to control posix threads.

All manner of complex situations can be accommodated including killin a thread instance in a certain condition.

And it's thread safe as well as in the thread code I use the mutex on local props.

And threads can talk to each other as well using this method.


Be sure to get your class ref in the plugin entry so that the compiler does not strip out the any calls as the api states.

Bingo I only need t write to the rb end so my solution was easy.

Mark

Ps I will drop up a sample app for people to play with when I have the time to build it.
Use ipc sockets and all your reentrant issues are gone.


Top
 Profile  
Reply with quote  
 Post subject: Re: Running instance
PostPosted: Wed Mar 30, 2011 12:51 am 
Offline

Joined: Sat Nov 26, 2005 4:51 am
Posts: 346
Interesting. Can you post a link to a sample project?

Regards,
- Oskar


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group