1212
1313int stlxdm_server_init (stlxdm_server_t * server , stlxgfx_context_t * gfx_ctx , stlxgfx_pixel_format_t format ) {
1414 if (!server || !gfx_ctx ) {
15- printf ( "[STLXDM_SERVER] ERROR: Invalid parameters for server init\n " );
15+ STLXDM_SERVER_TRACE ( " ERROR: Invalid parameters for server init" );
1616 return -1 ;
1717 }
1818
@@ -84,7 +84,7 @@ int stlxdm_server_accept_new_connections(stlxdm_server_t* server) {
8484 // Allocate receive buffer for this client
8585 server -> clients [slot ].receive_buffer = malloc (STLXGFX_MAX_PAYLOAD_SIZE );
8686 if (!server -> clients [slot ].receive_buffer ) {
87- printf ( "[STLXDM_SERVER] ERROR: Failed to allocate receive buffer for client %u\n " , server -> clients [slot ].client_id );
87+ STLXDM_SERVER_TRACE ( " ERROR: Failed to allocate receive buffer for client %u" , server -> clients [slot ].client_id );
8888 // Clean up the connection
8989 close (new_client_fd );
9090 server -> clients [slot ].socket_fd = -1 ;
@@ -97,13 +97,13 @@ int stlxdm_server_accept_new_connections(stlxdm_server_t* server) {
9797 new_connections ++ ;
9898 } else {
9999 // No slots available, close the connection
100- printf ( "[STLXDM_SERVER] WARNING: No client slots available, closing connection\n " );
100+ STLXDM_SERVER_TRACE ( " WARNING: No client slots available, closing connection" );
101101 close (new_client_fd );
102102 break ;
103103 }
104104 } else if (new_client_fd == -2 ) {
105105 // Error accepting connection
106- printf ( "[STLXDM_SERVER] ERROR: Failed to accept client connection\n " );
106+ STLXDM_SERVER_TRACE ( " ERROR: Failed to accept client connection" );
107107 return -1 ;
108108 } else {
109109 // No more pending connections (new_client_fd == -1)
@@ -137,7 +137,7 @@ static int stlxdm_server_dispatch_message(stlxdm_server_t* server,
137137 return stlxdm_server_handle_destroy_window_request (server , client , header , payload );
138138 }
139139 default : {
140- printf ( "[STLXDM_SERVER] Unknown message type %u from client %u\n " ,
140+ STLXDM_SERVER_TRACE ( " Unknown message type %u from client %u" ,
141141 header -> message_type , client -> client_id );
142142 return -1 ;
143143 }
@@ -152,7 +152,7 @@ static int stlxdm_server_handle_create_window_request(stlxdm_server_t* server,
152152
153153 // Validate window dimensions
154154 if (req -> width == 0 || req -> height == 0 || req -> width > 4096 || req -> height > 4096 ) {
155- printf ( "[STLXDM_SERVER] Invalid window dimensions: %ux%u\n " , req -> width , req -> height );
155+ STLXDM_SERVER_TRACE ( " Invalid window dimensions: %ux%u" , req -> width , req -> height );
156156 // TODO: Send error response
157157 return -1 ;
158158 }
@@ -165,14 +165,14 @@ static int stlxdm_server_handle_create_window_request(stlxdm_server_t* server,
165165
166166 // Validate title length
167167 if (req -> title_length > 255 ) {
168- printf ( "[STLXDM_SERVER] Title too long: %u characters\n " , req -> title_length );
168+ STLXDM_SERVER_TRACE ( " Title too long: %u characters" , req -> title_length );
169169 // TODO: Send error response
170170 return -1 ;
171171 }
172172
173173 // Check if client already has a window
174174 if (client -> window != NULL ) {
175- printf ( "[STLXDM_SERVER] Client %u already has a window\n " , client -> client_id );
175+ STLXDM_SERVER_TRACE ( " Client %u already has a window" , client -> client_id );
176176 // TODO: Send error response
177177 return -1 ;
178178 }
@@ -181,7 +181,7 @@ static int stlxdm_server_handle_create_window_request(stlxdm_server_t* server,
181181 stlxgfx_context_t * gfx_ctx = server -> gfx_ctx ;
182182
183183 if (!gfx_ctx ) {
184- printf ( "[STLXDM_SERVER] ERROR: No graphics context available\n " );
184+ STLXDM_SERVER_TRACE ( " ERROR: No graphics context available" );
185185 return -1 ;
186186 }
187187
@@ -190,7 +190,7 @@ static int stlxdm_server_handle_create_window_request(stlxdm_server_t* server,
190190 stlxgfx_window_sync_t * sync_data ;
191191
192192 if (stlxgfx_dm_create_window_sync_shm (gfx_ctx , & sync_shm_handle , & sync_data ) != 0 ) {
193- printf ( "[STLXDM_SERVER] Failed to create window sync SHM\n " );
193+ STLXDM_SERVER_TRACE ( " Failed to create window sync SHM" );
194194 return -1 ;
195195 }
196196
@@ -203,7 +203,7 @@ static int stlxdm_server_handle_create_window_request(stlxdm_server_t* server,
203203
204204 if (stlxgfx_dm_create_shared_surface_set (gfx_ctx , req -> width , req -> height , surface_format ,
205205 & surface_shm_handle , & surface0 , & surface1 , & surface2 ) != 0 ) {
206- printf ( "[STLXDM_SERVER] Failed to create surface set SHM\n " );
206+ STLXDM_SERVER_TRACE ( " Failed to create surface set SHM" );
207207 // Clean up sync SHM
208208 stlxgfx_dm_destroy_window_sync_shm (gfx_ctx , sync_shm_handle , sync_data );
209209 return -1 ;
@@ -214,7 +214,7 @@ static int stlxdm_server_handle_create_window_request(stlxdm_server_t* server,
214214 stlxgfx_event_ring_t * event_ring ;
215215
216216 if (stlxgfx_dm_create_event_ring_shm (gfx_ctx , & event_shm_handle , & event_ring ) != 0 ) {
217- printf ( "[STLXDM_SERVER] Failed to create event ring SHM\n " );
217+ STLXDM_SERVER_TRACE ( " Failed to create event ring SHM" );
218218 // Clean up surface set SHM
219219 stlxgfx_dm_destroy_shared_surface_set (gfx_ctx , surface_shm_handle , surface0 , surface1 , surface2 );
220220 // Clean up sync SHM
@@ -225,7 +225,7 @@ static int stlxdm_server_handle_create_window_request(stlxdm_server_t* server,
225225 // Create and populate window structure
226226 stlxgfx_window_t * window = malloc (sizeof (stlxgfx_window_t ));
227227 if (!window ) {
228- printf ( "[STLXDM_SERVER] Failed to allocate window structure\n " );
228+ STLXDM_SERVER_TRACE ( " Failed to allocate window structure" );
229229 // Clean up all shared memory
230230 stlxgfx_dm_destroy_event_ring_shm (gfx_ctx , event_shm_handle , event_ring );
231231 stlxgfx_dm_destroy_shared_surface_set (gfx_ctx , surface_shm_handle , surface0 , surface1 , surface2 );
@@ -278,11 +278,11 @@ static int stlxdm_server_handle_create_window_request(stlxdm_server_t* server,
278278 };
279279
280280 if (stlxgfx_send_message (client -> socket_fd , & response_header , & response ) == 0 ) {
281- printf ( "[STLXDM_SERVER] Created window ID=%u with sync_shm=%lu, surface_shm=%lu, event_shm=%lu for client %u\n " ,
281+ STLXDM_SERVER_TRACE ( " Created window ID=%u with sync_shm=%lu, surface_shm=%lu, event_shm=%lu for client %u" ,
282282 window -> window_id , sync_shm_handle , surface_shm_handle , event_shm_handle , client -> client_id );
283283 return 0 ;
284284 } else {
285- printf ( "[STLXDM_SERVER] Failed to send response to client %u\n " , client -> client_id );
285+ STLXDM_SERVER_TRACE ( " Failed to send response to client %u" , client -> client_id );
286286 // Clean up everything on send failure
287287 client -> window = NULL ;
288288 free (window );
@@ -301,7 +301,7 @@ static int stlxdm_server_handle_destroy_window_request(stlxdm_server_t* server,
301301
302302 // Check if client has a window
303303 if (client -> window == NULL ) {
304- printf ( "[STLXDM_SERVER] Client %u has no window to destroy\n " , client -> client_id );
304+ STLXDM_SERVER_TRACE ( " Client %u has no window to destroy" , client -> client_id );
305305 // Send error response
306306 stlxgfx_message_header_t error_header = {
307307 .protocol_version = STLXGFX_PROTOCOL_VERSION ,
@@ -323,7 +323,7 @@ static int stlxdm_server_handle_destroy_window_request(stlxdm_server_t* server,
323323
324324 // Validate that the window ID matches
325325 if (client -> window -> window_id != req -> window_id ) {
326- printf ( "[STLXDM_SERVER] Window ID mismatch: client has %u, request for %u\n " ,
326+ STLXDM_SERVER_TRACE ( " Window ID mismatch: client has %u, request for %u" ,
327327 client -> window -> window_id , req -> window_id );
328328 // Send error response
329329 stlxgfx_message_header_t error_header = {
@@ -348,13 +348,13 @@ static int stlxdm_server_handle_destroy_window_request(stlxdm_server_t* server,
348348 stlxgfx_context_t * gfx_ctx = server -> gfx_ctx ;
349349
350350 if (!gfx_ctx ) {
351- printf ( "[STLXDM_SERVER] ERROR: No graphics context available\n " );
351+ STLXDM_SERVER_TRACE ( " ERROR: No graphics context available" );
352352 return -1 ;
353353 }
354354
355355 // Clean up window resources
356356 stlxgfx_window_t * window = client -> window ;
357- printf ( "[STLXDM_SERVER] Destroying window ID=%u for client %u\n " ,
357+ STLXDM_SERVER_TRACE ( " Destroying window ID=%u for client %u" ,
358358 window -> window_id , client -> client_id );
359359
360360 // Clean up shared memory resources
@@ -402,11 +402,11 @@ static int stlxdm_server_handle_destroy_window_request(stlxdm_server_t* server,
402402 };
403403
404404 if (stlxgfx_send_message (client -> socket_fd , & response_header , & response ) == 0 ) {
405- printf ( "[STLXDM_SERVER] Successfully destroyed window ID=%u for client %u\n " ,
405+ STLXDM_SERVER_TRACE ( " Successfully destroyed window ID=%u for client %u" ,
406406 req -> window_id , client -> client_id );
407407 return 0 ;
408408 } else {
409- printf ( "[STLXDM_SERVER] Failed to send destroy response to client %u\n " , client -> client_id );
409+ STLXDM_SERVER_TRACE ( " Failed to send destroy response to client %u" , client -> client_id );
410410 return -1 ;
411411 }
412412}
@@ -431,16 +431,16 @@ int stlxdm_server_handle_client_requests(stlxdm_server_t* server) {
431431
432432 if (result == 0 ) {
433433 // Message received, dispatch to appropriate handler
434- printf ( "[STLXDM_SERVER] Received %s (%u) from client %u (slot %d)\n " ,
434+ STLXDM_SERVER_TRACE ( " Received %s (%u) from client %u (slot %d)" ,
435435 stlxdm_server_get_message_type_name (header .message_type ),
436436 header .message_type , client -> client_id , i );
437437
438438 if (stlxdm_server_dispatch_message (server , client , & header , client -> receive_buffer ) < 0 ) {
439- printf ( "[STLXDM_SERVER] Failed to handle message from client %u\n " , client -> client_id );
439+ STLXDM_SERVER_TRACE ( " Failed to handle message from client %u" , client -> client_id );
440440 }
441441 } else if (result == -2 ) {
442442 // Client disconnected or error
443- printf ( "[STLXDM_SERVER] Client %u (slot %d) disconnected\n " , client -> client_id , i );
443+ STLXDM_SERVER_TRACE ( " Client %u (slot %d) disconnected" , client -> client_id , i );
444444 stlxdm_server_disconnect_client (server , i );
445445 }
446446 // result == -1 means no data available, which is normal
@@ -464,7 +464,7 @@ int stlxdm_server_disconnect_client(stlxdm_server_t* server, int client_index) {
464464 return 0 ; // Already disconnected
465465 }
466466
467- printf ( "[STLXDM_SERVER] Disconnecting client %u (slot %d, fd %d)\n " ,
467+ STLXDM_SERVER_TRACE ( " Disconnecting client %u (slot %d, fd %d)" ,
468468 client -> client_id , client_index , client -> socket_fd );
469469
470470 // Close socket
@@ -475,7 +475,7 @@ int stlxdm_server_disconnect_client(stlxdm_server_t* server, int client_index) {
475475 // Clean up window if it exists
476476 if (client -> window ) {
477477 stlxgfx_window_t * window = client -> window ;
478- printf ( "[STLXDM_SERVER] Cleaning up window ID=%u for client %u\n " ,
478+ STLXDM_SERVER_TRACE ( " Cleaning up window ID=%u for client %u" ,
479479 window -> window_id , client -> client_id );
480480
481481 // Properly destroy window with shared memory cleanup
0 commit comments