コード例 #1
0
ファイル: ddpserver.cpp プロジェクト: bowlofstew/ddpserver
void DdpServer::process(const std::string &input)
{
    jvar::Variant inputData;
    if (!inputData.parseJson(input.c_str()))
        throw;

    jvar::Variant responseArray;
    responseArray.createArray();
    for(int i = 0; i < inputData.length();i++)
    {
        jvar::Variant packet;
        packet.parseJson(inputData[i].toString().c_str());

        jvar::Variant response;
        response = processPing(packet);
        response = response.isEmpty() ? processConnect(packet) : response;
        response = response.isEmpty() ? processSub(packet) : response;
        response = response.isEmpty() ? processUnsub(packet) : response;
        response = response.isEmpty() ? processMethod(packet) : response;

        if (response.isEmpty())
        {
            // unknown
        }
        else if (response.isArray())
        {
            for (int j = 0; j < response.length(); j++)
                responseArray.push(response[j].toString());
        }
        else
        {
            responseArray.push(response.toString());
        }

    }

    if (responseArray.length() == 0)
        return;

    onEmitCallback(context, "a" + responseArray.toJsonString());
}
コード例 #2
0
ファイル: main.cpp プロジェクト: MrEricSir/Modipulate
/**
 * Receive loop
 * Returns false when it's time to quit.
 */
bool doReceive(void)
{
    oscpkt::PacketReader pr((char*)socketReceive.packetData() + skip_bytes,
        socketReceive.packetSize() - skip_bytes);
    oscpkt::Message *msg;

    while (pr.isOk() && (msg = pr.popMessage()) != 0)
    {
        err = MODIPULATE_ERROR_NONE;

        // Print whole received message
        std::cout << PFX_OSCIN << *msg << "\n";

        // Check each command.
        if (processPing(msg)) goto runtimeErrorCheck;
        if (processQuit(msg)) return false;
        if (processSetVolume(msg)) goto runtimeErrorCheck;
        if (processSongLoad(msg)) goto runtimeErrorCheck;
        if (processSongUnload(msg)) goto runtimeErrorCheck;
        if (processSongGetInfo(msg)) goto runtimeErrorCheck;
        if (processSongPlay(msg)) goto runtimeErrorCheck;
        if (processSongPause(msg)) goto runtimeErrorCheck;
        if (processSongSetVolume(msg)) goto runtimeErrorCheck;
        if (processSongPlaySample(msg)) goto runtimeErrorCheck;
        //if (processSongSetTempo(msg)) goto runtimeErrorCheck; // For the future...
        if (processSongChannelEnable(msg)) goto runtimeErrorCheck;
        if (processSongChannelDisable(msg)) goto runtimeErrorCheck;
        if (processSongChannelFade(msg)) goto runtimeErrorCheck;
        if (processSongChannelEffectCommand(msg)) goto runtimeErrorCheck;
        if (processSongChannelVolumeCommand(msg)) goto runtimeErrorCheck;
        //if (processSongChannelSetVolume(msg)) goto runtimeErrorCheck; // For the future...


runtimeErrorCheck:
        if (!MODIPULATE_OK(err))
            std::cout << PFX_ERR << "Modipulate: " << modipulate_global_get_last_error_string() << "\n";
    }

    return true;
}
コード例 #3
0
/*
 * Main routine of our mini time server
 */
int
main(int argc, char* argv[])
{
	establishRedirection("mtimesrv.log", REDIR_OUT_APPEND, STDOUT_FILENO | STDERR_FILENO);

	printf("\nMicro Time Server\nVersion: %s\n\n", MTIMESRV_VERSION);

	init();
	daemonize();

	/* main server loop */
	while(1)
	{
		ipc_packet_data.sem_id  = status.sem_id;
		ipc_packet_data.reqresp = &request;
		
		if(receiveRequest(&ipc_packet_data) < 0)
		{
			ipcerror("mtimesrv::main():receiveRequest() - failed");
			exit(1);
		}
		
		/* Dispatch requests */
		switch(request.command)
		{
			case IDLE:
				printf("Idle\n");
				fflush(stdout);
				break;

			case TIME:
				sendTime();
				break;

			case OPEN:
				registerClient();
				break;

			case VERSION:
				sendVersion();
				break;

			case TERMINATE:
				terminate();
				break;

			case PING:
				processPing();
				break;

			default:
				printf("Unsupported command (%d) from a client (PID=%d)... Ignored.\n", request.command, request.client_pid);
				fflush(stdout);
				break;
		}

		/* Reset the request buffer */
		memset(&request, 0, sizeof(request_t));
	}

	return 0;
}