aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/libraries/SledjHamr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libraries/SledjHamr.c')
-rw-r--r--src/libraries/SledjHamr.c68
1 files changed, 32 insertions, 36 deletions
diff --git a/src/libraries/SledjHamr.c b/src/libraries/SledjHamr.c
index 10eeca5..2fb9019 100644
--- a/src/libraries/SledjHamr.c
+++ b/src/libraries/SledjHamr.c
@@ -38,7 +38,7 @@ static boolean checkConnection(Connection *conn, char *func, connType wanted, bo
38 if ((conn->type != CT_CLIENT) && (conn->type != CT_SERVER)) 38 if ((conn->type != CT_CLIENT) && (conn->type != CT_SERVER))
39 { 39 {
40 result = FALSE; 40 result = FALSE;
41 printf("CONNECTION OBJECT in %s() is of unknown type %d\n", func, (int) conn->type); 41 PE("CONNECTION OBJECT in %s() is of unknown type %d", func, (int) conn->type);
42 } 42 }
43 else if (conn->type != wanted) 43 else if (conn->type != wanted)
44 { 44 {
@@ -47,43 +47,43 @@ static boolean checkConnection(Connection *conn, char *func, connType wanted, bo
47 { 47 {
48 case CT_CLIENT : 48 case CT_CLIENT :
49 if (conn->type == CT_SERVER) 49 if (conn->type == CT_SERVER)
50 printf("INVALID CONNECTION OBJECT in %s(), it might be a server object!\n", func); 50 PE("INVALID CONNECTION OBJECT in %s(), it might be a server object!", func);
51 else 51 else
52 printf("INVALID CONNECTION OBJECT in %s(), type is %d!\n", func, (int) conn->type); 52 PE("INVALID CONNECTION OBJECT in %s(), type is %d!", func, (int) conn->type);
53 if (conn->conn.client.myServer == NULL) 53 if (conn->conn.client.myServer == NULL)
54 printf("CONNECTION OBJECT in %s() is a local client, but should be a remote client mirror!\n", func); 54 PE("CONNECTION OBJECT in %s() is a local client, but should be a remote client mirror!", func);
55 break; 55 break;
56 56
57 case CT_SERVER : 57 case CT_SERVER :
58 if (conn->type == CT_CLIENT) 58 if (conn->type == CT_CLIENT)
59 printf("INVALID CONNECTION OBJECT in %s(), it might be a client object!\n", func); 59 PE("INVALID CONNECTION OBJECT in %s(), it might be a client object!", func);
60 else 60 else
61 printf("INVALID CONNECTION OBJECT in %s(), type is %d!\n", func, (int) conn->type); 61 PE("INVALID CONNECTION OBJECT in %s(), type is %d!", func, (int) conn->type);
62 if (isLocal) 62 if (isLocal)
63 { 63 {
64 if (conn->conn.server.clients == NULL) 64 if (conn->conn.server.clients == NULL)
65 printf("CONNECTION OBJECT in %s() is a remote server mirror, but should be a local server!\n", func); 65 PE("CONNECTION OBJECT in %s() is a remote server mirror, but should be a local server!", func);
66 } 66 }
67 else 67 else
68 { 68 {
69 if (conn->conn.server.clients != NULL) 69 if (conn->conn.server.clients != NULL)
70 printf("CONNECTION OBJECT in %s() is a local server, but should be a remote server mirror!\n", func); 70 PE("CONNECTION OBJECT in %s() is a local server, but should be a remote server mirror!", func);
71 } 71 }
72 break; 72 break;
73 73
74 default : 74 default :
75 printf("CONNECTION OBJECT in %s(), silly coder asked for an unknown type!""\n", func); 75 PE("CONNECTION OBJECT in %s(), silly coder asked for an unknown type!", func);
76 break; 76 break;
77 } 77 }
78 78
79 if (NULL == conn->name) 79 if (NULL == conn->name)
80 { 80 {
81 result = FALSE; 81 result = FALSE;
82 printf("CONNECTION OBJECT in %s() has no name!\n", func); 82 PE("CONNECTION OBJECT in %s() has no name!", func);
83 } 83 }
84 } 84 }
85 85
86//if (result) printf("%s(\"%s\")\n", func, conn->name); 86//if (result) PD("%s(\"%s\")", func, conn->name);
87 87
88 return result; 88 return result;
89} 89}
@@ -102,11 +102,11 @@ void sendBack(Connection *conn, const char *SID, const char *message, ...)
102 va_end(args); 102 va_end(args);
103 buf[length++] = '\n'; 103 buf[length++] = '\n';
104 buf[length] = '\0'; 104 buf[length] = '\0';
105// printf("sendBack(%s", buf); 105// PD("sendBack(%s", buf);
106// ecore_con_client_send(client, buf, length); 106// ecore_con_client_send(client, buf, length);
107// ecore_con_client_flush(client); 107// ecore_con_client_flush(client);
108//Connection *conn = ecore_con_client_data_get(client); 108//Connection *conn = ecore_con_client_data_get(client);
109if (conn) send2(conn, SID, buf); else printf("sendBack() can't find Connection!\n"); 109if (conn) send2(conn, SID, buf); else PE("sendBack() can't find Connection!");
110} 110}
111 111
112void sendForth(Connection *conn, const char *SID, const char *message, ...) 112void sendForth(Connection *conn, const char *SID, const char *message, ...)
@@ -123,11 +123,11 @@ void sendForth(Connection *conn, const char *SID, const char *message, ...)
123 va_end(args); 123 va_end(args);
124 buf[length++] = '\n'; 124 buf[length++] = '\n';
125 buf[length] = '\0'; 125 buf[length] = '\0';
126// printf("sendForth(%s", buf); 126// PD("sendForth(%s", buf);
127// ecore_con_server_send(server, buf, length); 127// ecore_con_server_send(server, buf, length);
128// ecore_con_server_flush(server); 128// ecore_con_server_flush(server);
129//Connection *conn = ecore_con_server_data_get(server); 129//Connection *conn = ecore_con_server_data_get(server);
130if (conn) send2(conn, SID, buf); else printf("sendForth() can't find Connection!\n"); 130if (conn) send2(conn, SID, buf); else PE("sendForth() can't find Connection!");
131} 131}
132 132
133void send2(Connection *conn, const char *SID, const char *message, ...) 133void send2(Connection *conn, const char *SID, const char *message, ...)
@@ -153,24 +153,24 @@ length = strlen(buf);
153 switch (conn->type) 153 switch (conn->type)
154 { 154 {
155 case CT_CLIENT : 155 case CT_CLIENT :
156// printf("vvv send2(%*s", length, buf); 156// PD("vvv send2(%*s", length, buf);
157 ecore_con_client_send(conn->conn.client.client, strndup(buf, length), length); 157 ecore_con_client_send(conn->conn.client.client, strndup(buf, length), length);
158 ecore_con_client_flush(conn->conn.client.client); 158 ecore_con_client_flush(conn->conn.client.client);
159 break; 159 break;
160 160
161 case CT_SERVER : 161 case CT_SERVER :
162// printf("^^^ send2(%*s", length, buf); 162// PD("^^^ send2(%*s", length, buf);
163 ecore_con_server_send(conn->conn.server.server, strndup(buf, length), length); 163 ecore_con_server_send(conn->conn.server.server, strndup(buf, length), length);
164 ecore_con_server_flush(conn->conn.server.server); 164 ecore_con_server_flush(conn->conn.server.server);
165 break; 165 break;
166 166
167 default : 167 default :
168 printf("send2() unable to send to partially bogus Connection object!\n"); 168 PE("send2() unable to send to partially bogus Connection object!");
169 break; 169 break;
170 } 170 }
171 } 171 }
172 else 172 else
173 printf("send2() unable to send to bogus Connection object!\n"); 173 PE("send2() unable to send to bogus Connection object!");
174} 174}
175 175
176static Eina_Bool parseStream(void *data, int type, void *evData, int evSize, void *ev) 176static Eina_Bool parseStream(void *data, int type, void *evData, int evSize, void *ev)
@@ -180,7 +180,6 @@ static Eina_Bool parseStream(void *data, int type, void *evData, int evSize, voi
180 const char *command; 180 const char *command;
181 char *ext; 181 char *ext;
182 182
183//printf("parseStream(%s, \"%*s\")\n", conn->name, evSize, (char *) evData);
184 if (NULL == conn->stream) 183 if (NULL == conn->stream)
185 conn->stream = eina_strbuf_new(); 184 conn->stream = eina_strbuf_new();
186 185
@@ -202,7 +201,6 @@ static Eina_Bool parseStream(void *data, int type, void *evData, int evSize, voi
202 if (ext) 201 if (ext)
203 { 202 {
204 streamParser func = eina_hash_find(conn->commands, command); 203 streamParser func = eina_hash_find(conn->commands, command);
205//printf("parseStream(%s>> %s\"\n", conn->name, command);
206 204
207// ext[0] = '\0'; 205// ext[0] = '\0';
208 // Need a callback if we can't find the command. 206 // Need a callback if we can't find the command.
@@ -211,7 +209,7 @@ static Eina_Bool parseStream(void *data, int type, void *evData, int evSize, voi
211 if (func) 209 if (func)
212 func(conn->pointer, conn, SID, (char *) command, ext + 1); 210 func(conn->pointer, conn, SID, (char *) command, ext + 1);
213 else 211 else
214 printf("parseStream() No function found for command %s!\n", command); 212 PE("parseStream() No function found for command %s!", command);
215 } 213 }
216 } 214 }
217 215
@@ -297,9 +295,9 @@ static Eina_Bool clientDel(void *data, int type, Ecore_Con_Event_Client_Del *ev)
297 // The "- 1" is coz this server is still counted. 295 // The "- 1" is coz this server is still counted.
298 clients = ecore_con_server_clients_get(conn->conn.server.server) - 1; 296 clients = ecore_con_server_clients_get(conn->conn.server.server) - 1;
299 if (0 == eina_list_count(clients)) 297 if (0 == eina_list_count(clients))
300 printf("No more clients for %s, exiting.\n", conn->name); 298 PI("No more clients for %s, exiting.", conn->name);
301 else 299 else
302 printf("Some (%d) more clients for %s, exiting anyway.\n", eina_list_count(clients), conn->name); 300 PW("Some (%d) more clients for %s, exiting anyway.", eina_list_count(clients), conn->name);
303 301
304 // TODO - the Connection free function should take care of all of this, and we should call it here. ish. 302 // TODO - the Connection free function should take care of all of this, and we should call it here. ish.
305 eina_clist_remove(conn->conn.client.server); 303 eina_clist_remove(conn->conn.client.server);
@@ -345,7 +343,7 @@ Connection *openArms(char *name, const char *address, int port, void *data, Ecor
345 ecore_con_server_client_limit_set(server, -1, 0); 343 ecore_con_server_client_limit_set(server, -1, 0);
346// ecore_con_server_timeout_set(server, 10); 344// ecore_con_server_timeout_set(server, 10);
347// ecore_con_server_client_limit_set(server, 3, 0); 345// ecore_con_server_client_limit_set(server, 3, 0);
348 printf("ACTUALLY created the %s server %s:%d.\n", name, address, port); 346 PI("ACTUALLY created the %s server %s:%d.", name, address, port);
349 } 347 }
350 else 348 else
351 { 349 {
@@ -368,9 +366,9 @@ static Eina_Bool serverAdd(void *data, int type, Ecore_Con_Event_Server_Add *ev)
368 conn->stage++; 366 conn->stage++;
369 367
370 if (conn->name) 368 if (conn->name)
371 printf("serverAdd()^^^^^^^^^^^^^^^^^^^^^^^Connected to %s server.\n", conn->name); 369 PI("serverAdd()^^^^^^^^^^^^^^^^^^^^^^^Connected to %s server.", conn->name);
372 else 370 else
373 printf("serverAdd()^^^^^^^^^^^^^^^^^^^^^^^Connected to UNKNOWN server.\n"); 371 PW("serverAdd()^^^^^^^^^^^^^^^^^^^^^^^Connected to UNKNOWN server.");
374 372
375 // In case the server crashed, clear out any waiting data. 373 // In case the server crashed, clear out any waiting data.
376 if (conn->stream) 374 if (conn->stream)
@@ -421,18 +419,16 @@ static Eina_Bool _reachOutTimer(void *data)
421 { 419 {
422 // TODO - Seems Ecore_con now has trouble with my try first, then start method, so start first, then try. Fix this, or do something else. 420 // TODO - Seems Ecore_con now has trouble with my try first, then start method, so start first, then try. Fix this, or do something else.
423 case -3 : 421 case -3 :
424 printf("Failed to connect to a %s server, starting our own.\n", conn->name); 422 PW("Failed to connect to a %s server, starting our own.", conn->name);
425 conn->conn.server.serverHandle = ecore_exe_pipe_run(conn->conn.server.serverCommand, ECORE_EXE_NONE /*| ECORE_EXE_TERM_WITH_PARENT*/, conn); 423 conn->conn.server.serverHandle = ecore_exe_pipe_run(conn->conn.server.serverCommand, ECORE_EXE_NONE /*| ECORE_EXE_TERM_WITH_PARENT*/, conn);
426 if (conn->conn.server.serverHandle) 424 if (conn->conn.server.serverHandle)
427 { 425 {
428 conn->conn.server.pid = ecore_exe_pid_get(conn->conn.server.serverHandle); 426 conn->conn.server.pid = ecore_exe_pid_get(conn->conn.server.serverHandle);
429 if (conn->conn.server.pid == -1) 427 if (conn->conn.server.pid == -1)
430 fprintf(stderr, "Could not retrive the PID!\n"); 428 PE("Could not retrive the PID!");
431 else
432 fprintf(stdout, "The child process has PID:%u\n", (unsigned int)conn->conn.server.pid);
433 } 429 }
434 else 430 else
435 fprintf(stderr, "Could not create server process %s!\n", conn->conn.server.serverCommand); 431 PE("Could not create server process %s!", conn->conn.server.serverCommand);
436 432
437 // TODO - There's also the question of what to do if the connection failed. 433 // TODO - There's also the question of what to do if the connection failed.
438 // Did the server crash, or was it just the connection? 434 // Did the server crash, or was it just the connection?
@@ -448,20 +444,20 @@ static Eina_Bool _reachOutTimer(void *data)
448 case -1 : // Give the server some time to start up. 444 case -1 : // Give the server some time to start up.
449 // Check if the server is still running here, if not, reset stage to previous -3 (taking into account the increment at the end). 445 // Check if the server is still running here, if not, reset stage to previous -3 (taking into account the increment at the end).
450 if (conn->conn.server.pid) 446 if (conn->conn.server.pid)
451 printf("Waiting for %s server to start from command \"%s\"\n", conn->name, conn->conn.server.serverCommand); 447 PI("Waiting for %s server to start from command \"%s\"", conn->name, conn->conn.server.serverCommand);
452 else 448 else
453 conn->stage = -4; 449 conn->stage = -4;
454 break; 450 break;
455 451
456 case 0 : 452 case 0 :
457 printf("Attempting to connect to the %s server %s:%d.\n", conn->name, conn->address, conn->port); 453 PI("Attempting to connect to the %s server %s:%d.", conn->name, conn->address, conn->port);
458 // This should only return NULL if something goes wrong with the setup, 454 // This should only return NULL if something goes wrong with the setup,
459 // you wont know if the connection worked until you get the add callback, 455 // you wont know if the connection worked until you get the add callback,
460 // or you get the del calback if it failed. 456 // or you get the del calback if it failed.
461 if ((server = ecore_con_server_connect(ECORE_CON_REMOTE_TCP, conn->address, conn->port, conn))) 457 if ((server = ecore_con_server_connect(ECORE_CON_REMOTE_TCP, conn->address, conn->port, conn)))
462 printf("MAYBE connecting to the %s server %s:%d.\n", conn->name, conn->address, conn->port); 458 PD("MAYBE connecting to the %s server %s:%d.", conn->name, conn->address, conn->port);
463 else 459 else
464 printf("FAILED to create the connection to the %s server %s:%d!\n", conn->name, conn->address, conn->port); 460 PE("FAILED to create the connection to the %s server %s:%d!", conn->name, conn->address, conn->port);
465 conn->conn.server.server = server; 461 conn->conn.server.server = server;
466 break; 462 break;
467 463