Page 1 of 2
Help with AREXX in a C program
Posted: Sun Apr 01, 2012 1:40 am
by ktadd
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.
Re: Help with AREXX in a C program
Posted: Sun Apr 01, 2012 11:53 am
by chris
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.
Re: Help with AREXX in a C program
Posted: Sun Apr 01, 2012 1:49 pm
by thomasrapp
Re: Help with AREXX in a C program
Posted: Mon Apr 02, 2012 3:22 am
by ktadd
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.
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.
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);
Re: Help with AREXX in a C program
Posted: Mon Apr 02, 2012 3:36 am
by ktadd
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.
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.
Re: Help with AREXX in a C program
Posted: Mon Apr 02, 2012 9:20 am
by thomasrapp
I forgot to set rm_Action. Fixed (same link as above).
Re: Help with AREXX in a C program
Posted: Mon Jan 21, 2013 1:09 am
by ktadd
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.
Re: Help with AREXX in a C program
Posted: Thu Dec 18, 2014 10:51 am
by Spirantho
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:
Code: Select all
((struct Node*)rexxmsg)->ln_Name = "REXX";
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!
Re: Help with AREXX in a C program
Posted: Thu Dec 18, 2014 4:33 pm
by xenic
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.
The same holds true for Dopus4; it will ignore the message unless you add: ((struct Node*)rexxmsg)->ln_Name = "REXX";
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);
}
}
I could not find anything about dealing with results from ARexx or an ARexx host in any ARexx documentation but it makes sense that if you receive a result string in a message reply you would be responsible for disposing of the string. The host that sent it to you has no way of knowing when you are finished with it. On the other hand, I don't see how DeleteArgstring() would know where the memory was allocated and how to free it.
Re: Help with AREXX in a C program
Posted: Thu Dec 18, 2014 9:50 pm
by tonyw
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.