示例#1
0
quintptr Container::getIdElementByIndex(uint index) const
{
    const PElement e = getElementByIndex(index);
    if (!e)
        return 0;

    return e->getId();
}
示例#2
0
/**
 * Parses a line of data given to a control channel.
 * @param pClient the client of the channel
 * @param argIx array with start index of each argument
 * @param argCount number of arguments
 * @return 0 on success, a negative value otherwise
 */
static int ctrlParse(ClientElem_t *pClient, int *argIx, int argCount, int cmdlen) {
	int res = -1;
	char *pCmd = pClient->cmdbuf;

	switch (pCmd[0]) {
		 /* Identify this control channel */
		case 'I': {
			SEND("%i", getIndexByElement(pClient))
			res = 0;
			break;
		}
		/* Attach this channel to given control channel and make it a data channel */
		case 'A': {
			int ix = atoi(&pCmd[argIx[1]]);
			ClientElem_t *pOtherClient = getElementByIndex(ix);
			if (pOtherClient == NULL) {
				SEND("ERROR no such channel")
			} else if (pClient == pOtherClient) {
				SEND("ERROR cannot attach to self")
			} else if (pOtherClient->portNumerator == -1) {
				SEND("ERROR channel not connected to device")
			} else {
				pClient->serialHdl = pOtherClient->serialHdl;
				pClient->portNumerator = pOtherClient->portNumerator;
				pClient->type = TYPE_DATA;
				res = 0;
			}
			break;
		}
		/* List devices */
		case 'L': {
			res = listDevices(pClient);
			break;
		}
		/* Open device */
		case 'O': {
			if (openDevice(pClient, argIx, argCount, cmdlen) >= 0) {
				res = 0;
			}
			break;
		}
		/* Configure UART */
		case 'U': {
			res = setUART(pClient, argIx, argCount);
			break;
		}
		/* Kill client, close device */
		case 'C': {
			DBG_PRINT("Killing client");
			pClient->running = 0;
			res = 0;
			break;
		}
		/* Kill server */
		case 'X': {
			DBG_PRINT("Killing server");
			g_serverRunning = 0;
			res = 0;
			break;
		}
		default: {
			SEND("ERROR unkown command: %s", pCmd)
		}
	}
	if (res == 0) {
		SEND("OK")
	}
	return res;
}