Help with AREXX in a C program
Help with AREXX in a C program
I have a program written in 'C' and I would like to send and Arexx command to a program and get the return value back to my program.
My program doesn't need to support it's own Arexx commands, just send and read return values from another one. Do I need to set up a full Arexx interface in my program but just have an empty command list to do this? I've read through the auto docs but am still a bit unclear on how to do this. Is there any example code that shows how to do this? Any help or pointers would be greatly appreciated.
My program doesn't need to support it's own Arexx commands, just send and read return values from another one. Do I need to set up a full Arexx interface in my program but just have an empty command list to do this? I've read through the auto docs but am still a bit unclear on how to do this. Is there any example code that shows how to do this? Any help or pointers would be greatly appreciated.
Kevin - X1000 first contact / uA1
Re: Help with AREXX in a C program
You need to create an ARexx object using arexx.class, then you can simply call something like the following:
IDoMethod(arexx_obj,AM_EXECUTE,"TOFRONT","NETSURF",NULL,NULL,NULL,NULL);
One of those NULLs is the place to put a char** to capture the result, you'll need to check the Autodoc for AM_EXECUTE for that.
IDoMethod(arexx_obj,AM_EXECUTE,"TOFRONT","NETSURF",NULL,NULL,NULL,NULL);
One of those NULLs is the place to put a char** to capture the result, you'll need to check the Autodoc for AM_EXECUTE for that.
- thomasrapp
- Posts: 310
- Joined: Sat Jun 18, 2011 11:22 pm
Re: Help with AREXX in a C program
Unfortunatly it doesn't appear to be quit that simple. From what I can gather that would work if I were executing a command in my programs own Arexx port. I'm trying retrieve a return value from MPlayer's Arexx port. According the the autodocs I need to set up a hook function to get the values.chris wrote:You need to create an ARexx object using arexx.class, then you can simply call something like the following:
IDoMethod(arexx_obj,AM_EXECUTE,"TOFRONT","NETSURF",NULL,NULL,NULL,NULL);
One of those NULLs is the place to put a char** to capture the result, you'll need to check the Autodoc for AM_EXECUTE for that.
Here is what I have done but it seems my hook function never gets called. The PAUSE command does get sent to MPlayer and the playback pauses so I know my commands are getting to MPlayer. Any ideas on what I might be missing?
Since I don't expect to receive any ARexx commands I haven't set up an Arexx port and I set AREXX_Commands to NULL. Is that Ok?
Code: Select all
#include <classes/arexx.h>
#include <proto/arexx.h>
#include "SDI_hook.h"
/* callback hook function */
STATIC VOID reply_callback(struct Hook *hook, Object *obj , struct RexxMsg *rxm)
{
IDOS->Printf("Args[0]: %s\nResult1: %ld Result2: %ld\n",
rxm->rm_Args[0], rxm->rm_Result1, rxm->rm_Result2);
}
MakeStaticHook(reply_hook, reply_callback); /* setup hook structure. Best to do after function. */
/* I DO THE FOLLWOING IN MAIN() */
Object *arexx_obj;
arexx_obj = IIntuition->NewObject(NULL, "arexx.class",
AREXX_HostName, PROG_NAME,
AREXX_Commands, NULL,
AREXX_ReplyHook, &reply_hook,
TAG_DONE);
/* A BUTTON GADGET EXECUTES THE FOLLOWING WHEN CLICKED */
IIntuition->IDoMethod(objects[OID_AREXX], AM_EXECUTE, "PAUSE", "MPLAYER.1", NULL, NULL, NULL, NULL);
IIntuition->IDoMethod(objects[OID_AREXX], AM_EXECUTE, "GET_PERCENT_POS", "MPLAYER.1", NULL, NULL, NULL, NULL);
Kevin - X1000 first contact / uA1
Re: Help with AREXX in a C program
Thanks for your example Thomas. I've visited your home page in the past and studied several of your examples. They have been very helpful.thomasrapp wrote:http://thomas-rapp.homepage.t-online.de/examples/rexx.c
I downloaded, studied and compiled the example you supplied. It works as described using the example you gave opening the Ram: but I couldn't get it to send commands to MPlayer for some reason.
Kevin - X1000 first contact / uA1
- thomasrapp
- Posts: 310
- Joined: Sat Jun 18, 2011 11:22 pm
Re: Help with AREXX in a C program
I forgot to set rm_Action. Fixed (same link as above).
Re: Help with AREXX in a C program
It's been a while since I worked on this but with the help of ssolie's tutorial on AREXX from last years AmiWest
I was able to track down the problem with my AREXX implamentation. It now works! Thanks Steve!
Also, thanks to other that replies to this thread. I reviewed everyones inputs and learned something from all of them.
I was able to track down the problem with my AREXX implamentation. It now works! Thanks Steve!
Also, thanks to other that replies to this thread. I reviewed everyones inputs and learned something from all of them.
Kevin - X1000 first contact / uA1
Re: Help with AREXX in a C program
Sorry for the thread grave-digging, but I found something yesterday which held me up for days scratching my head.
Certain programs such as Blitz Basic will not pick up an Arexx message if the message node isn't set correctly. It'll just ignore the message completely, and the sending task will hang waiting for a reply.
You need to add this code to Thomas' example, once the rexxmsg has been created:
Once that is done, Blitz behaves properly. Apparently Python has the same fault...
Hopefully my addendum may help any one else searching for a solution to this problem!
Certain programs such as Blitz Basic will not pick up an Arexx message if the message node isn't set correctly. It'll just ignore the message completely, and the sending task will hang waiting for a reply.
You need to add this code to Thomas' example, once the rexxmsg has been created:
Code: Select all
((struct Node*)rexxmsg)->ln_Name = "REXX";
Hopefully my addendum may help any one else searching for a solution to this problem!
Re: Help with AREXX in a C program
The same holds true for Dopus4; it will ignore the message unless you add: ((struct Node*)rexxmsg)->ln_Name = "REXX";Spirantho wrote: Certain programs such as Blitz Basic will not pick up an Arexx message if the message node isn't set correctly. It'll just ignore the message completely, and the sending task will hang waiting for a reply.
When I was looking for similar ARexx examples, I got this bit of code in an example from broadblues:
Code: Select all
if(rm->rm_Result1 == 0)
{
if(rm->rm_Result2)
{
IRexxSys->DeleteArgstring((STRPTR)rm->rm_Result2);
}
}
AmigaOne X1000 with 2GB memory - OS4.1 FE
- tonyw
- AmigaOS Core Developer
- Posts: 1479
- Joined: Wed Mar 09, 2011 1:36 pm
- Location: Sydney, Australia
Re: Help with AREXX in a C program
As long as the string was allocated by AllocVecTags(), it has an associated header describing its size, etc. But you would have to be sure that the sending program used that method of allocation, not just something from a memory Pool, for instance.
cheers
tony
tony