2 Copyright © 1995-2002, The AROS Development Team. All rights reserved.
5 Desc: Rexx function to create a MsgPort
9 #include <proto/exec.h>
10 #include <proto/rexxsyslib.h>
11 #include <proto/alib.h>
13 #include <exec/types.h>
14 #include <exec/memory.h>
15 #include <rexx/storage.h>
16 #include <rexx/errors.h>
17 #include <aros/debug.h>
21 #include "rexxsupport_intern.h"
24 LONG
rxsupp_openport(struct Library
*RexxSupportBase
, struct RexxMsg
*msg
, UBYTE
**argstring
)
26 struct PortNode
*node
;
27 struct PortNodeData
*data
;
30 data
= (struct PortNodeData
*)FindName(&RSBI(RexxSupportBase
)->openports
, ARG1(msg
));
33 struct MsgPort
*replyport
, *rexxport
, *port
;
34 struct RexxMsg
*msg2
, *msg3
;
35 if (FindPort(ARG1(msg
)) != NULL
)
37 *argstring
= CreateArgstring("0", 1);
40 rexxport
= FindPort("REXX");
46 port
= CreateMsgPort();
49 node
= (struct PortNode
*)AllocMem(sizeof(struct PortNode
), MEMF_PUBLIC
);
50 name
= AllocMem(LengthArgstring(ARG1(msg
))+1, MEMF_PUBLIC
);
51 strcpy(name
, ARG1(msg
));
52 node
->rsrc
.rr_Node
.ln_Name
= name
;
53 node
->rsrc
.rr_Base
= RexxSupportBase
;
54 node
->rsrc
.rr_Func
= -36;
55 node
->data
.node
.ln_Name
= name
;
56 node
->data
.self
= (struct RexxRsrc
*)node
;
57 node
->data
.port
= port
;
58 NewList(&node
->data
.msgs
);
59 /* Lock lib in memory because it can be called by rexx */
60 if (IsListEmpty(&RSBI(RexxSupportBase
)->openports
))
61 RexxSupportBase
->lib_OpenCnt
++;
63 AddTail(&RSBI(RexxSupportBase
)->openports
, &node
->data
.node
);
64 port
->mp_Node
.ln_Name
= name
;
65 port
->mp_Node
.ln_Pri
= 0;
68 replyport
= CreateMsgPort();
69 if (replyport
!= NULL
)
71 replyport
->mp_Node
.ln_Name
= NULL
;
72 replyport
->mp_Node
.ln_Pri
= 0;
73 msg2
= CreateRexxMsg(replyport
, NULL
, NULL
);
75 if (replyport
== NULL
|| msg2
== NULL
)
80 msg2
->rm_Private1
= msg
->rm_Private1
;
81 msg2
->rm_Private2
= msg
->rm_Private2
;
82 msg2
->rm_Action
= RXADDRSRC
;
83 msg2
->rm_Args
[0] = (IPTR
)node
;
84 PutMsg(rexxport
, (struct Message
*)msg2
);
87 msg3
= (struct RexxMsg
*)GetMsg(replyport
);
88 } while (msg3
!= msg2
);
89 if (msg2
->rm_Result1
!= RC_OK
)
90 kprintf("ClosePort ADDRSRC Result1 != RC_OK\n");
92 DeleteMsgPort(replyport
);
94 *argstring
= CreateArgstring("1", 1);
99 *argstring
= CreateArgstring("0", 1);
105 *argstring
= CreateArgstring("0", 1);