Esempio n. 1
0
/* start the given remote INDI driver connection.
 * exit if trouble.
 */
void
startRemoteDvr (DvrInfo *dp)
{
	Msg *mp;
	char dev[1024];
	char host[1024];
	char buf[1024];
	int indi_port, sockfd;

	/* extract host and port */
	indi_port = INDIPORT;
	if (sscanf (dp->name, "%[^@]@%[^:]:%d", dev, host, &indi_port) < 2) {
	    fprintf (stderr, "Bad remote device syntax: %s\n", dp->name);
	    Bye();
	}

	/* connect */
	sockfd = openINDIServer (host, indi_port);

	/* record flag pid, io channels, init lp and snoop list */
	dp->pid = REMOTEDVR;
	dp->rfd = sockfd;
	dp->wfd = sockfd;
	dp->lp = newLilXML();
	dp->msgq = newFQ(1);
    dp->sprops = (Property*) malloc (1);	/* seed for realloc */
	dp->nsprops = 0;
	dp->nsent = 0;
    dp->active = 1;
    dp->ndev = 1;
    dp->dev = (char **) malloc(sizeof(char *));

	/* N.B. storing name now is key to limiting outbound traffic to this
	 * dev.
	 */
    dp->dev[0] = (char *) malloc(MAXINDIDEVICE * sizeof(char));
    strncpy (dp->dev[0], dev, MAXINDIDEVICE-1);
    dp->dev[0][MAXINDIDEVICE-1] = '\0';

	/* Sending getProperties with device lets remote server limit its
	 * outbound (and our inbound) traffic on this socket to this device.
	 */
	mp = newMsg();
	pushFQ (dp->msgq, mp);
	sprintf (buf, "<getProperties device='%s' version='%g'/>\n",
             dp->dev[0], INDIV);
	setMsgStr (mp, buf);
	mp->count++;

	if (verbose > 0)
	    fprintf (stderr, "%s: Driver %s: socket=%d\n", indi_tstamp(NULL),
							    dp->name, sockfd);
}
Esempio n. 2
0
int
main (int ac, char *av[])
{
	FILE *fp;

	/* save our name for usage() */
	me = av[0];

	/* crack args */
	while (--ac && **++av == '-') {
	    char *s = *av;
	    while (*++s) {
		switch (*s) {
		case 'b':	/* beep when true */
		    bflag++;
		    break;
		case 'd':
		    if (ac < 2) {
			fprintf (stderr, "-d requires open fileno\n");
			usage();
		    }
		    directfd = atoi(*++av);
		    ac--;
		    break;
		case 'e':	/* print each updated expression value */
		    eflag++;
		    break;
		case 'f':	/* print final expression value */
		    fflag++;
		    break;
		case 'h':
		    if (directfd >= 0) {
			fprintf (stderr, "Can not combine -d and -h\n");
			usage();
		    }
		    if (ac < 2) {
			fprintf (stderr, "-h requires host name\n");
			usage();
		    }
		    host = *++av;
		    ac--;
		    break;
		case 'i':	/* read expression from stdin */
		    iflag++;
		    break;
		case 'o':	/* print operands as they change */
		    oflag++;
		    break;
		case 'p':
		    if (directfd >= 0) {
			fprintf (stderr, "Can not combine -d and -p\n");
			usage();
		    }
		    if (ac < 2) {
			fprintf (stderr, "-p requires tcp port number\n");
			usage();
		    }
		    port = atoi(*++av);
		    ac--;
		    break;
		case 't':
		    if (ac < 2) {
			fprintf (stderr, "-t requires timeout\n");
			usage();
		    }
		    timeout = atoi(*++av);
		    ac--;
		    break;
		case 'v':	/* verbose */
		    verbose++;
		    break;
		case 'w':	/* wait for expression to be true */
		    wflag++;
		    break;
		default:
		    fprintf (stderr, "Unknown flag: %c\n", *s);
		    usage();
		}
	    }
	}

	/* now there are ac args starting with av[0] */

	/* compile expression from av[0] or stdin */
	if (ac == 0)
	    compile (NULL);
	else if (ac == 1)
	    compile (av[0]);
	else
	    usage();

        /* open connection */
	if (directfd >= 0) {
	    fp = fdopen (directfd, "r+");
	    setbuf (fp, NULL);		/* don't absorb next guy's stuff */
	    if (!fp) {
		fprintf (stderr, "Direct fd %d: %s\n",directfd,strerror(errno));
		exit(1);
	    }
	    if (verbose)
		fprintf (stderr, "Using direct fd %d\n", directfd);
	} else {
	    fp = openINDIServer();
	    if (verbose)
		fprintf (stderr, "Connected to %s on port %d\n", host, port);
	}

	/* build a parser context for cracking XML responses */
	lillp = newLilXML();

	/* set up to catch an io timeout function */
	signal (SIGALRM, onAlarm);

	/* send getProperties */
	getProps(fp);

	/* initialize all properties */
	initProps(fp);

	/* evaluate expression, return depending on flags */
	return (runEval(fp));
}