Revision 51 logic/trunk/src/hci_comm/hci_comm_listener.c

View differences:

hci_comm_listener.c
14 14
#include <stdlib.h>
15 15
#include <string.h>
16 16
#include <unistd.h>
17
#include "../mxml/mxml.h"
17 18

  
18 19
int listenTo(unsigned short int portNum) {
19 20

  
21
    // Holders
22
    char *attrVal = malloc(32*sizeof(char));
23
    char *name = malloc(32*sizeof(char));
24

  
20 25
	// Buffer
21 26
	char *requestBuffer = malloc(HCI_COMM_REQUEST_BUFFER_SIZE * sizeof(char));
22 27
	if(requestBuffer == NULL) {
......
73 78
			return HCI_COMM_ERR_READ_FAIL;
74 79
		}
75 80

  
81
        // Parse request
82
        mxml_node_t *tree;
83
        tree = mxmlLoadString(NULL, requestBuffer, MXML_TEXT_CALLBACK);
84

  
76 85
		// Create a response
77
		char *hciResponse = "Works!"; // TODO
78
		int responseLength = 6; // TODO
86
		char *hciResponse = "";
87
		int responseLength = 0;
88
		mxml_node_t *node;
89
        node = (tree, tree, "hci-request", "type", NULL, MXML_DESCEND);
90
        strcpy(attrVal,node->value.element.attrs->value);
91
        if(strcmp(attrVal,"checkConnection") == 0) {
92
            strcat(hciResponse,"<logic-response type=\"checkConnection\"><data>");
93
            strcat(hciResponse,node->child->value.text.string);
94
            strcat(hciResponse,"</data></logic-response>");
95
            responseLength = strlen(hciResponse);
96
        } else if(strcmp(attrVal,"getConfig") == 0) {
97
            // TODO
98
        } else if(strcmp(attrVal,"setConfig") == 0) {
99
            // TODO
100
        } else if(strcmp(attrVal,"getScenarios") == 0) {
101
            // TODO
102
        } else if(strcmp(attrVal,"setScenarios") == 0) {
103
            // TODO
104
        } else if(strcmp(attrVal,"executeAction") == 0) {
105
            // TODO
106
        } else {
107
            strcpy(hciResponse,"<logic-response type=\"error\">Invalid request!</logic-response>");
108
            responseLength = 62;
109
        }
79 110

  
80 111
		// Check if logic wants to terminate the infinite loop
81 112
		if(responseLength == HCI_COMM_TERMINATE) {

Also available in: Unified diff