Ejemplo n.º 1
0
/* pull apart the name and value from the given message, and set operand value.
 * ignore any other messages.
 * return 0 if found a recognized operand else -1
 */
static int
setOp (XMLEle *root)
{
	char *t = tagXMLEle (root);
        const char *d = findXMLAttValu (root, "device");
        const char *n = findXMLAttValu (root, "name");
	int nset = 0;
	double v;
	char prop[1024];
	XMLEle *ep;

	/* check values */
	if (!strcmp (t,"defNumberVector") || !strcmp (t,"setNumberVector")) {
	    for (ep = nextXMLEle(root,1); ep; ep = nextXMLEle(root,0)) {
		char *et = tagXMLEle(ep);
		if (!strcmp (et,"defNumber") || !strcmp (et,"oneNumber")) {
		    sprintf (prop, "%s.%s.%s", d, n, findXMLAttValu(ep,"name"));
		    v = atof(pcdataXMLEle(ep));
		    if (setOperand (prop, v) == 0) {
			nset++;
			if (oflag)
			    fprintf (stderr, "%s=%g\n", prop, v);
		    }
		}
	    }
	} else if(!strcmp(t,"defSwitchVector") || !strcmp(t,"setSwitchVector")){
	    for (ep = nextXMLEle(root,1); ep; ep = nextXMLEle(root,0)) {
		char *et = tagXMLEle(ep);
		if (!strcmp (et,"defSwitch") || !strcmp (et,"oneSwitch")) {
		    sprintf (prop, "%s.%s.%s", d, n, findXMLAttValu(ep,"name"));
		    v = (double)!strcmp(pcdataXMLEle(ep),"On");
		    if (setOperand (prop, v) == 0) {
			nset++;
			if (oflag)
			    fprintf (stderr, "%s=%g\n", prop, v);
		    }
		}
	    }
	} else if(!strcmp(t,"defLightVector") || !strcmp(t,"setLightVector")){
	    for (ep = nextXMLEle(root,1); ep; ep = nextXMLEle(root,0)) {
		char *et = tagXMLEle(ep);
		if (!strcmp (et,"defLight") || !strcmp (et,"oneLight")) {
		    sprintf (prop, "%s.%s.%s", d, n, findXMLAttValu(ep,"name"));
		    v = (double)pstatestr(pcdataXMLEle(ep));
		    if (setOperand (prop, v) == 0) {
			nset++;
			if (oflag)
			    fprintf (stderr, "%s=%g\n", prop, v);
		    }
		}
	    }
	}

	/* check special elements */
        t = (char *) findXMLAttValu (root, "state");
	if (t[0]) {
	    sprintf (prop, "%s.%s._STATE", d, n);
	    v = (double)pstatestr(t);
	    if (setOperand (prop, v) == 0) {
		nset++;
		if (oflag)
		    fprintf (stderr, "%s=%g\n", prop, v);
	    }
	}
        t = (char *) findXMLAttValu (root, "timestamp");
	if (t[0]) {
	    sprintf (prop, "%s.%s._TS", d, n);
	    v = (double)timestamp(t);
	    if (setOperand (prop, v) == 0) {
		nset++;
		if (oflag)
		    fprintf (stderr, "%s=%g\n", prop, v);
	    }
	}

	/* return whether any were set */
	return (nset > 0 ? 0 : -1);
}
Ejemplo n.º 2
0
/* put Msg mp on queue of each client interested in dev/name, except notme.
 * if BLOB always honor current mode.
 * return -1 if had to shut down any clients, else 0.
 */
int
q2Clients (ClInfo *notme, int isblob, const char *dev, const char *name, Msg *mp, XMLEle *root)
{
	int shutany = 0;
	ClInfo *cp;
    int ql,i=0;

	/* queue message to each interested client */
	for (cp = clinfo; cp < &clinfo[nclinfo]; cp++) {
	    /* cp in use? notme? want this dev/name? blob? */
	    if (!cp->active || cp == notme)
		continue;
            if (findClDevice (cp, dev, name) < 0)
		continue;

            //if ((isblob && cp->blob==B_NEVER) || (!isblob && cp->blob==B_ONLY))
            if (!isblob && cp->blob==B_ONLY)
                continue;

            if (isblob)
            {
                if (cp->nprops > 0)
                {
                Property *pp = NULL;
                int blob_found=0;
                for (i = 0; i < cp->nprops; i++)
                {
                    pp = &cp->props[i];
                    if (!strcmp (pp->dev, dev) && (!strcmp(pp->name, name)))
                    {
                        blob_found = 1;
                        break;
                    }
                }

                if ( (blob_found && pp->blob == B_NEVER) || (blob_found==0 && cp->blob == B_NEVER) )
                    continue;
               }
               else if (cp->blob == B_NEVER)
                   continue;
           }

	    /* shut down this client if its q is already too large */
	    ql = msgQSize(cp->msgq);
	    if (ql > maxqsiz) {
		if (verbose)
		    fprintf (stderr, "%s: Client %d: %d bytes behind, shutting down\n",
						    indi_tstamp(NULL), cp->s, ql);
		shutdownClient (cp);
		shutany++;
		continue;
	    }

	    /* ok: queue message to this client */
	    mp->count++;
	    pushFQ (cp->msgq, mp);
	    if (verbose > 1)
		fprintf (stderr, "%s: Client %d: queuing <%s device='%s' name='%s'>\n",
				    indi_tstamp(NULL), cp->s, tagXMLEle(root),
				    findXMLAttValu (root, "device"),
				    findXMLAttValu (root, "name"));
	}

	return (shutany ? -1 : 0);
}
Ejemplo n.º 3
0
bool Controller::ISSnoopDevice(XMLEle * root)
{
    XMLEle * ep=NULL;
    double mag=0, angle=0;

    // If joystick is disabled, do not process anything.
    if (UseJoystickSP.sp[0].s == ISS_OFF)
        return false;

    const char * propName = findXMLAttValu(root, "name");

    // Check axis
    if (!strcmp("JOYSTICK_AXIS", propName))
    {
        for (ep = nextXMLEle(root, 1) ; ep != NULL ; ep = nextXMLEle(root, 0))
        {
            const char * elemName = findXMLAttValu(ep, "name");
            const char * setting = getControllerSetting(elemName);
            if (setting == NULL)
                return false;

            mag = atof(pcdataXMLEle(ep));

            axisCallbackFunc(setting, mag, device);
        }
    }
    // Check buttons
    else if (!strcmp("JOYSTICK_BUTTONS", propName))
    {
        for (ep = nextXMLEle(root, 1) ; ep != NULL ; ep = nextXMLEle(root, 0))
        {
            const char * elemName = findXMLAttValu(ep, "name");
            const char * setting = getControllerSetting(elemName);

            if (setting == NULL)
                continue;

            buttonCallbackFunc(setting, strcmp(pcdataXMLEle(ep), "Off") ? ISS_ON : ISS_OFF, device);

        }
    }
    // Check joysticks
    else if (strstr(propName, "JOYSTICK_"))
    {
        const char * setting  = getControllerSetting(propName);

        // We don't have this here, so let's not process it
        if (setting == NULL)
            return false;

        for (ep = nextXMLEle(root, 1) ; ep != NULL ; ep = nextXMLEle(root, 0))
        {
            if (!strcmp("JOYSTICK_MAGNITUDE", findXMLAttValu(ep, "name")))
                mag = atof(pcdataXMLEle(ep));
            else if (!strcmp("JOYSTICK_ANGLE", findXMLAttValu(ep, "name")))
                angle = atof(pcdataXMLEle(ep));
        }

        joystickCallbackFunc(setting, mag, angle, device);
    }

    return false;
}