forked from enlightenment/efl
evas/cserve2: Add basic error handling on thread
slave. It will now receive errors from the thread callback and call the error request function, with the respective error type in the message. SVN revision: 71606
This commit is contained in:
parent
91a1ac65c7
commit
de3a6a067b
|
@ -166,7 +166,7 @@ typedef void (*Timeout_Cb)(void); /* void* for compat? */
|
|||
typedef void (*Main_Loop_Child_Dead_Cb)(int pid, int status); /* void* for compat? */
|
||||
typedef void (*Slave_Dead_Cb)(Slave *slave, void *data);
|
||||
typedef void (*Slave_Read_Cb)(Slave *slave, Slave_Command cmd, void *msg, void *data);
|
||||
typedef void *(*Slave_Thread_Cb)(Slave_Thread_Data *sd, Slave_Command cmd, const void *cmddata, void *userdata);
|
||||
typedef void *(*Slave_Thread_Cb)(Slave_Thread_Data *sd, Slave_Command *cmd, const void *cmddata, void *userdata);
|
||||
typedef void (*File_Change_Cb)(const char *path, Eina_Bool deleted, void *data);
|
||||
|
||||
void cserve2_client_accept(int fd);
|
||||
|
@ -239,6 +239,6 @@ void cserve2_cache_requests_response(Slave_Command type, void *msg, void *data);
|
|||
|
||||
void cserve2_font_init(void);
|
||||
void cserve2_font_shutdown(void);
|
||||
void *cserve2_font_slave_cb(Slave_Thread_Data *sd, Slave_Command cmd, const void *cmddata, void *data);
|
||||
void *cserve2_font_slave_cb(Slave_Thread_Data *sd, Slave_Command *cmd, const void *cmddata, void *data);
|
||||
|
||||
#endif /* _EVAS_CSERVE2_H */
|
||||
|
|
|
@ -31,6 +31,15 @@ struct _Font_Source_Info
|
|||
typedef struct _Font_Info Font_Info;
|
||||
typedef struct _Font_Source_Info Font_Source_Info;
|
||||
|
||||
static void *
|
||||
_font_slave_error_send(Error_Type error)
|
||||
{
|
||||
Error_Type *e = calloc(1, sizeof(*e));
|
||||
*e = error;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
static Font_Source_Info *
|
||||
_font_slave_source_load(const char *file)
|
||||
{
|
||||
|
@ -105,7 +114,12 @@ _font_slave_int_load(const Slave_Msg_Font_Load *msg, Font_Source_Info *fsi)
|
|||
error = FT_Set_Pixel_Sizes(fsi->face, chosen_width, fi->real_size);
|
||||
|
||||
if (error)
|
||||
ERR("Could not choose the font size.");
|
||||
{
|
||||
ERR("Could not choose the font size for font: '%s'.", msg->name);
|
||||
FT_Done_Size(fi->size);
|
||||
free(fi);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
fi->max_h = 0;
|
||||
|
@ -153,9 +167,18 @@ _font_slave_load(const void *cmddata, void *data __UNUSED__)
|
|||
|
||||
// FIXME: Return correct error message
|
||||
if (!fsi)
|
||||
return NULL;
|
||||
{
|
||||
ERR("Could not load font source: '%s'", msg->file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fi = _font_slave_int_load(msg, fsi);
|
||||
if (!fi)
|
||||
{
|
||||
FT_Done_Face(fsi->face);
|
||||
free(fsi);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
response = calloc(1, sizeof(*response));
|
||||
response->ftdata1 = fsi;
|
||||
|
@ -165,20 +188,28 @@ _font_slave_load(const void *cmddata, void *data __UNUSED__)
|
|||
}
|
||||
|
||||
void *
|
||||
cserve2_font_slave_cb(Slave_Thread_Data *sd __UNUSED__, Slave_Command cmd, const void *cmddata, void *data)
|
||||
cserve2_font_slave_cb(Slave_Thread_Data *sd __UNUSED__, Slave_Command *cmd, const void *cmddata, void *data)
|
||||
{
|
||||
void *response = NULL;
|
||||
|
||||
switch (cmd)
|
||||
switch (*cmd)
|
||||
{
|
||||
case FONT_LOAD:
|
||||
_font_slave_load(cmddata, data);
|
||||
response = _font_slave_load(cmddata, data);
|
||||
break;
|
||||
case FONT_GLYPHS_LOAD:
|
||||
// command for FONT_GLYPHS_LOAD
|
||||
break;
|
||||
default:
|
||||
ERR("Invalid command for font slave: %d", cmd);
|
||||
ERR("Invalid command for font slave: %d", *cmd);
|
||||
*cmd = ERROR;
|
||||
return _font_slave_error_send(CSERVE2_INVALID_COMMAND);
|
||||
}
|
||||
|
||||
if (!response)
|
||||
{
|
||||
*cmd = ERROR;
|
||||
return _font_slave_error_send(CSERVE2_GENERIC);
|
||||
}
|
||||
|
||||
return response;
|
||||
|
|
|
@ -205,7 +205,7 @@ _cserve2_request_failed(Font_Request *req, Error_Type type)
|
|||
}
|
||||
|
||||
static void
|
||||
_slave_read_cb(Slave *s __UNUSED__, Slave_Command cmd __UNUSED__, void *msg, void *data)
|
||||
_slave_read_cb(Slave *s __UNUSED__, Slave_Command cmd, void *msg, void *data)
|
||||
{
|
||||
Slave_Worker *sw = data;
|
||||
Font_Request *req = sw->data;
|
||||
|
@ -214,7 +214,13 @@ _slave_read_cb(Slave *s __UNUSED__, Slave_Command cmd __UNUSED__, void *msg, voi
|
|||
|
||||
EINA_LIST_FREE(req->waiters, w)
|
||||
{
|
||||
req->funcs->response(w->client, req->data, msg, w->rid);
|
||||
if (cmd == ERROR)
|
||||
{
|
||||
Error_Type *err = msg;
|
||||
req->funcs->error(w->client, req->data, *err, w->rid);
|
||||
}
|
||||
else
|
||||
req->funcs->response(w->client, req->data, msg, w->rid);
|
||||
free(w);
|
||||
}
|
||||
|
||||
|
|
|
@ -474,7 +474,7 @@ _slave_thread_cb(void *data)
|
|||
n);
|
||||
continue;
|
||||
}
|
||||
sd->cmdanswer = sd->cb(sd, cmd, sd->cmddata, sd->cb_data);
|
||||
sd->cmdanswer = sd->cb(sd, &cmd, sd->cmddata, sd->cb_data);
|
||||
write(sd->write_fd, &cmd, sizeof(cmd));
|
||||
|
||||
n = read(sd->read_fd, &cmd, sizeof(cmd));
|
||||
|
|
Loading…
Reference in New Issue