home *** CD-ROM | disk | FTP | other *** search
- /*
- o_msgr.c
- */
- /* Copyright (c) 1994 Christian F. Tschudin. All rights reserved.
-
- Distributed under the terms of the GNU General Public License
- version 2 of june 1991 as published by the Free Software
- Foundation, Inc.
-
- This file is part of M0.
-
- M0 is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY. No author or distributor accepts responsibility to anyone for
- the consequences of using it or for whether it serves any particular
- purpose or works at all, unless he says so in writing. Refer to the GNU
- General Public License for full details.
-
- Everyone is granted permission to copy, modify and redistribute M0, but
- only under the conditions described in the GNU General Public License.
- A copy of this license is supposed to have been given to you along with
- M0 so you can know your rights and responsibilities. It should be in a
- file named LICENSE. Among other things, the copyright notice and this
- notice must be preserved on all copies. */
-
- #include "l_proto.h"
- #include "o_proto.h"
-
-
- retcode
- o_currentqueue()
- {
- eindex ei;
-
- if (current->osp >= MAXOSTACK)
- return ERR_OSTACK_OVERFLOW;
- ei = current->qkey ? current->qkey : null_val;
- incref(current, ei);
- current->os[current->osp++] = ei;
-
- return OK;
- }
-
-
- retcode
- o_enter()
- {
- /* possible usages:
- q-key E -
- q-key int E int (no timeout=0, timeout=1)
- q-key time E int
- */
- eindex qk, t=0;
- eptr qp, tp;
- retcode rc;
-
- if (current->osp < 1)
- return ERR_STACK_UNDERFLOW;
- qk = current->os[current->osp-1];
- qp = eaddr(current, qk);
- if (eptype(qp) != T_KEY) {
- if (eptype(qp)!= T_INT && eptype(qp)!=T_TIME)
- return ERR_TYPE_CHECK;
- t = qk;
- tp = qp;
- if (current->osp < 2)
- return ERR_STACK_UNDERFLOW;
- qk = current->os[current->osp-2];
- qp = eaddr(current,qk);
- if (eptype(qp) != T_KEY)
- return ERR_TYPE_CHECK;
- current->osp -= 2;
- } else
- current->osp -= 1;
-
- if (t && eptype(tp) == T_INT) {
- eindex now = time_now(current), then;
- then = time_addint(current, now, tp->V.i);
- decrefp(current, t, tp);
- decref(current, now);
- t = then;
- }
-
- rc = enqueue(current, qk, t);
- if (t)
- decref(current, t);
- decrefp(current, qk, qp);
-
- if (t && rc == OK)
- current->os[current->osp++] = new_element(current, T_INT);
-
- return rc;
- }
-
-
- retcode
- o_leave()
- {
- if (current->qkey)
- dequeue(current);
-
- return OK;
- }
-
-
- retcode
- o_qstate()
- {
- load_2_args(qk, i, qkp, ip);
-
- if (eptype(qkp)!= T_KEY || eptype(ip)!=T_INT)
- return ERR_TYPE_CHECK;
-
- queue_state(qk, ip->V.i);
-
- decrefp(current, qk, qkp);
- decrefp(current, i, ip);
- current->osp -= 2;
-
- return OK;
- }
-
-
- retcode
- o_submit()
- {
- eindex c;
-
- load_2_args(k, m, kp, mp);
-
- if (eptype(mp) != T_STRING)
- return ERR_TYPE_CHECK;
- if (!(epattr(mp) & A_READ))
- return ERR_ACCESS_CHECK;
-
- if (eptype(kp) == T_KEY) {
- c = dict_get(current, channeldict, k);
- if (c) {
- eindex m2 = make_global(current, m);
- eptr cp = eaddr(current, c);
- (cp->V.cha.submit)(current, cp->V.cha.data, m2);
- decref(0, m2);
- }
- } else {
- eindex m2 = make_global(current, m);
- eindex k2 = make_global(current, k);
- c = dict_get(current, channeldict, null_key);
- (eaddr(current, c)->V.cha.submit)(current, &k2, m2);
- decref(0, m2);
- decref(0, k2);
- }
-
-
- decrefp(current, k, kp);
- decrefp(current, m, mp);
- current->osp -= 2;
-
- return OK;
- }
-