summaryrefslogtreecommitdiff
path: root/src/lib/evas/cserve2/evas_cs2_client.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-07-29 13:08:36 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2013-10-28 15:47:13 +0900
commit47be3a2b819ed6319a65018195b31b622b547aab (patch)
treeda38402d574af89bfe4ce36667598cb8a260d108 /src/lib/evas/cserve2/evas_cs2_client.c
parentc0bb73c775787ae1221efacc8d5d7a01a28320af (diff)
evas/cserve2: Prepare shared indexes in clients
- Move required struct definitions to common evas_cs2.h - Open/close shm and map arrays to memory Pretty stupid for now as it will close & reopen the shm files even when unchanged. - Check shm size and array header consistency - Implement message send - Send messages from server when calling repack()
Diffstat (limited to '')
-rw-r--r--src/lib/evas/cserve2/evas_cs2_client.c137
1 files changed, 137 insertions, 0 deletions
diff --git a/src/lib/evas/cserve2/evas_cs2_client.c b/src/lib/evas/cserve2/evas_cs2_client.c
index 9fde9412d8..a52d547386 100644
--- a/src/lib/evas/cserve2/evas_cs2_client.c
+++ b/src/lib/evas/cserve2/evas_cs2_client.c
@@ -42,6 +42,10 @@ static unsigned int _data_id = 0;
42 42
43static Eina_List *_requests = NULL; 43static Eina_List *_requests = NULL;
44 44
45// Shared index table
46static Index_Table _index;
47static int _server_index_list_set(Msg_Base *data, int size);
48
45#ifndef UNIX_PATH_MAX 49#ifndef UNIX_PATH_MAX
46#define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path) 50#define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
47#endif 51#endif
@@ -279,6 +283,8 @@ evas_cserve2_init(void)
279 if (cserve2_init++) 283 if (cserve2_init++)
280 return cserve2_init; 284 return cserve2_init;
281 285
286 memset(&_index, 0, sizeof(_index));
287
282 DBG("Connecting to cserve2."); 288 DBG("Connecting to cserve2.");
283 if (!_server_connect()) 289 if (!_server_connect())
284 { 290 {
@@ -292,10 +298,13 @@ evas_cserve2_init(void)
292int 298int
293evas_cserve2_shutdown(void) 299evas_cserve2_shutdown(void)
294{ 300{
301 const char zeros[sizeof(Msg_Index_List)] = {0};
302
295 if ((--cserve2_init) > 0) 303 if ((--cserve2_init) > 0)
296 return cserve2_init; 304 return cserve2_init;
297 305
298 DBG("Disconnecting from cserve2."); 306 DBG("Disconnecting from cserve2.");
307 _server_index_list_set((Msg_Base *) zeros, sizeof(Msg_Index_List));
299 _server_disconnect(); 308 _server_disconnect();
300 309
301 return cserve2_init; 310 return cserve2_init;
@@ -316,6 +325,123 @@ _next_rid(void)
316 return _rid_count++; 325 return _rid_count++;
317} 326}
318 327
328// Returns the number of correctly opened index arrays
329static int
330_server_index_list_set(Msg_Base *data, int size)
331{
332 Msg_Index_List *msg = (Msg_Index_List *) data;
333 unsigned sz;
334 int ret = 0;
335
336 if (size != sizeof(*msg) || msg->base.type != CSERVE2_INDEX_LIST)
337 {
338 CRIT("Invalid message! type: %d, size: %d (expected %d)",
339 msg->base.type, size, (int) sizeof(*msg));
340 return -1;
341 }
342
343 // Reset index table
344 if (_index.files.f)
345 {
346 if (_index.files.header)
347 eina_file_map_free(_index.files.f, (void *) _index.files.header);
348 eina_file_close(_index.files.f);
349 }
350 if (_index.images.f)
351 {
352 if (_index.images.header)
353 eina_file_map_free(_index.images.f, (void *) _index.images.header);
354 eina_file_close(_index.images.f);
355 }
356 if (_index.fonts.f)
357 {
358 if (_index.fonts.header)
359 eina_file_map_free(_index.fonts.f, (void *) _index.fonts.header);
360 eina_file_close(_index.fonts.f);
361 }
362 memset(&_index, 0, sizeof(_index));
363
364 // Open new indexes
365 eina_strlcpy(_index.files.path, msg->files_index_path, 64);
366 eina_strlcpy(_index.images.path, msg->images_index_path, 64);
367 eina_strlcpy(_index.fonts.path, msg->fonts_index_path, 64);
368
369 if (_index.files.path[0])
370 {
371 _index.files.f = eina_file_open(_index.files.path, EINA_TRUE);
372 sz = eina_file_size_get(_index.files.f);
373 if (sz < sizeof(Shared_Array_Header))
374 {
375 ERR("Shared index for files is too small: %u", sz);
376 eina_file_close(_index.files.f);
377 _index.files.f = NULL;
378 }
379 else
380 {
381 _index.files.header = eina_file_map_all(_index.files.f,
382 EINA_FILE_WILLNEED);
383 if (sz < (_index.files.header->count * sizeof(File_Data)
384 + sizeof(Shared_Array_Header)))
385 {
386 ERR("Shared index size does not match array size: %u / %u",
387 sz, _index.files.header->count);
388 eina_file_map_free(_index.files.f,
389 (void *) _index.files.header);
390 eina_file_close(_index.files.f);
391 _index.files.f = NULL;
392 }
393 else
394 {
395 _index.files.entries = (File_Data *) &(_index.files.header[1]);
396 DBG("Mapped files shared index '%s' at %p: %u entries max",
397 _index.files.path, _index.files.header,
398 _index.files.header->count);
399 ret++;
400 }
401 }
402 }
403
404 if (_index.images.path[0])
405 {
406 _index.images.f = eina_file_open(_index.images.path, EINA_TRUE);
407 sz = eina_file_size_get(_index.images.f);
408 if (sz < sizeof(Shared_Array_Header))
409 {
410 ERR("Shared index for images is too small: %u", sz);
411 eina_file_close(_index.images.f);
412 _index.images.f = NULL;
413 }
414 else
415 {
416 _index.images.header = eina_file_map_all(_index.images.f,
417 EINA_FILE_WILLNEED);
418 if (sz < (_index.images.header->count * sizeof(Image_Data)
419 + sizeof(Shared_Array_Header)))
420 {
421 ERR("Shared index size does not match array size: %u / %u",
422 sz, _index.images.header->count);
423 eina_file_map_free(_index.images.f,
424 (void *) _index.images.header);
425 eina_file_close(_index.images.f);
426 _index.images.f = NULL;
427 }
428 else
429 {
430 _index.images.entries = (Image_Data *) &(_index.images.header[1]);
431 DBG("Mapped images shared index '%s' at %p: %u entries max",
432 _index.images.path, _index.images.header,
433 _index.images.header->count);
434 ret++;
435 }
436 }
437 }
438
439 if (_index.fonts.path[0])
440 ERR("Not implemented yet: fonts shared index");
441
442 return ret;
443}
444
319static unsigned int 445static unsigned int
320_server_dispatch(Eina_Bool *failed) 446_server_dispatch(Eina_Bool *failed)
321{ 447{
@@ -333,6 +459,17 @@ _server_dispatch(Eina_Bool *failed)
333 } 459 }
334 *failed = EINA_FALSE; 460 *failed = EINA_FALSE;
335 461
462 // Special messages (no request)
463 switch (msg->type)
464 {
465 case CSERVE2_INDEX_LIST:
466 _server_index_list_set(msg, size);
467 free(msg);
468 return 0;
469 default: break;
470 }
471
472 // Normal client to server requests
336 EINA_LIST_FOREACH_SAFE(_requests, l, l_next, cr) 473 EINA_LIST_FOREACH_SAFE(_requests, l, l_next, cr)
337 { 474 {
338 if (cr->rid != msg->rid) // dispatch this answer 475 if (cr->rid != msg->rid) // dispatch this answer