aboutsummaryrefslogtreecommitdiff
path: root/pkg/vocl/builtin_vo.c
blob: 4cb4dd295eaee8fae2ce04e2f00a10c4641694d8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
 */

#define import_spp
#define import_libc
#define import_fset
#define import_error
#define import_ctype
#define import_stdio
#define import_alloc
#define import_ttset
#define import_prstat
#define import_xwhen
#include <iraf.h>

/*
*/
#include "config.h"
#include "clmodes.h"
#include "mem.h"
#include "operand.h"
#include "opcodes.h"
#include "param.h"
#include "task.h"
#include "errs.h"


/*
 * BUILTIN_VO -- This file contains the functions that perform the built-in
 *   VO-related commands of the cl, such as coneCaller(), getRegistry(), etc.
 *
 * SetVOBuiltins() contains a table of functions and their user names; add
 *   to this table when adding new builtin functions.
 *
 * See builtins.c for addition notes and details.
 */

extern	int   cldebug, cltrace;		/* debug/trace flags		     */
extern	int   lastjobno;		/* last background job spawned	     */
extern	int   gologout;			/* flag to execute() to cause logout */
extern  int   logout_status;      	/* optional arg to logout()          */
extern  int   errorline;		/* error recover line		     */
extern  int   currentline;		/* line currently being executed     */
extern	char *findexe();

extern	int do_error;			/* for error recovery/trapping 	     */


extern int	VOClient_initialized;

typedef int (*PFI)();

static PFI	old_onipc;		/* X_IPC handler		     */
int		voc_onipc();


/* CL_VOCINIT --  Initialize the VO Client interface.
 */
void
cl_vocinit (void)
{
    register struct pfile *pfp;
    struct  operand o;
    int     n, status;

    if (VOClient_initialized == 0) {

	c_xwhen (X_IPC, voc_onipc, &old_onipc);

        pfp = newtask->t_pfp;
        if ((n = nargs (pfp)) > 1) {
            cl_error (E_UERR, e_posargs, "vocinit");
	    return;

        } else if (n < 1) {
            status = voc_initVOClient (envget("vo_runid"));

	} else {
            pushbparams (pfp->pf_pp);
            popop();                    /* discard fake name.           */
            opcast (OT_STRING);
            o = popop();                /* get ltask                    */

            status = voc_initVOClient (o.o_val.v_s);
        }

	if (status) {
            cl_error (E_UERR, "Can't init VOClient", "vocinit");
	} else
	    VOClient_initialized = 1;
    }
}


/* CL_VOCSTOP --  Stop the VO Client interface.
 */
void
cl_vocstop (void)
{
    register struct pfile *pfp;
    struct  operand o;
    int     n, status;

    if (VOClient_initialized == 1) {
	c_xwhen (X_IPC, old_onipc, &old_onipc);

        pfp = newtask->t_pfp;
        if ((n = nargs (pfp)) > 1) {
            cl_error (E_UERR, e_posargs, "vocstop");
	    return;

        } else if (n < 1) {
            voc_closeVOClient (1);

	} else {
            pushbparams (pfp->pf_pp);
            popop();                    /* discard fake name.           */
            opcast (OT_INT);
            o = popop();                /* get ltask                    */
            voc_closeVOClient (o.o_val.v_i);
	}
	VOClient_initialized = 0;
    }
}


/* CL_VOCRESET --  Restart the VO Client interface.
 */
void
cl_vocreset ()
{
    int status;

    voc_closeVOClient (1);
    status = voc_initVOClient (envget("vo_runid"));
}


/* ========================================================
 *
 * End of builtin functions.
 * What follows is their support code.
 *
 * ========================================================*/


/* VO_SETBUILTINS -- Add the builtin functions to package at pkp (this should
 * always just be clpackage).  To add more functions, write the support function
 * and enter it into the builtin table, btbl.  Reverse alpha due to lifo nature
 * of list.  Aliases can be made easily with multiple b_names using the same
 * b_f.  Setting LT_INVIS will keep it from being seen in the menu.
 */
void
vo_setbuiltins (
    struct package *pkp
)
{
    static struct builtin {
    	char	*b_name;
    	void	(*b_f)();
    	int	b_flags;
    } btbl[] = {
        { "vocinit",  cl_vocinit,  0}, /* initialize the VO Client	*/
        { "vocstop",  cl_vocstop,  0}, /* stop the VO Client	*/
        { "vocreset", cl_vocreset, 0}, /* reset the VO Client	*/
        NULL
    };

    register struct builtin *bp;

    for (bp = btbl; bp < &btbl[sizeof(btbl)/sizeof(struct builtin)]; bp++)
        newbuiltin (pkp, bp->b_name, bp->b_f, bp->b_flags, "", 0);
}


/* VOC_ONIPC -- Call this when get a signal that indicates a write to an IPC
 * channel with no reader.  We are called after the system X_IPC handler
 * has been called to cleanup the internal process tables and file system,
 * disabling any further output to the process.
 */         
/* ARGSUSED */
int
voc_onipc (
    int   *vex,                   /* virtual exception code       */
    PFI   *next_handler           /* next handler to be called    */
)
{       
    VOClient_initialized = 0;
    cl_vocreset();
    cl_error (E_UERR, "Abnormal termination of %s, resetting\n",
	"VOClientd");

    return (0);
}