#include "debug.h"
#include "util.h"
#include "fb.h"
-#include "critical_log.h"
int errno;
return 0;
}
+static inline void update_fb_size(struct fb_info *info)
+{
+ info->bufsz = info->w * info->h * s_info.depth;
+}
+
static inline int sync_for_file(struct fb_info *info)
{
int fd;
buffer = info->buffer;
- if (!buffer) /* Ignore this sync request */
+ if (!buffer) { /* Ignore this sync request */
return LB_STATUS_SUCCESS;
+ }
if (buffer->state != CREATED) {
ErrPrint("Invalid state of a FB\n");
if (read(fd, buffer->data, info->bufsz) != info->bufsz) {
ErrPrint("read: %s\n", strerror(errno));
- close(fd);
+ if (close(fd) < 0) {
+ ErrPrint("close: %s\n", strerror(errno));
+ }
/*!
* \note
return LB_STATUS_SUCCESS;
}
- close(fd);
+ if (close(fd) < 0) {
+ ErrPrint("close: %s\n", strerror(errno));
+ }
return LB_STATUS_SUCCESS;
}
XImage *xim;
buffer = info->buffer;
- if (!buffer) /*!< Ignore this sync request */
+ if (!buffer) { /*!< Ignore this sync request */
return LB_STATUS_SUCCESS;
+ }
if (buffer->state != CREATED) {
ErrPrint("Invalid state of a FB\n");
}
if (info->bufsz == 0) {
+ /*!
+ * If the client does not acquire the buffer,
+ * This function will do nothing.
+ * It will work only if the buffer is acquired.
+ * To sync its contents.
+ */
DbgPrint("Nothing can be sync\n");
return LB_STATUS_SUCCESS;
}
si.readOnly = False;
si.shmaddr = shmat(si.shmid, NULL, 0);
if (si.shmaddr == (void *)-1) {
-
- if (shmctl(si.shmid, IPC_RMID, 0) < 0)
+ if (shmctl(si.shmid, IPC_RMID, 0) < 0) {
ErrPrint("shmctl: %s\n", strerror(errno));
+ }
return LB_STATUS_ERROR_FAULT;
}
&si,
info->w, info->h);
if (xim == NULL) {
- if (shmdt(si.shmaddr) < 0)
+ if (shmdt(si.shmaddr) < 0) {
ErrPrint("shmdt: %s\n", strerror(errno));
+ }
- if (shmctl(si.shmid, IPC_RMID, 0) < 0)
+ if (shmctl(si.shmid, IPC_RMID, 0) < 0) {
ErrPrint("shmctl: %s\n", strerror(errno));
+ }
return LB_STATUS_ERROR_FAULT;
}
XShmDetach(s_info.disp, &si);
XDestroyImage(xim);
- if (shmdt(si.shmaddr) < 0)
+ if (shmdt(si.shmaddr) < 0) {
ErrPrint("shmdt: %s\n", strerror(errno));
+ }
- if (shmctl(si.shmid, IPC_RMID, 0) < 0)
+ if (shmctl(si.shmid, IPC_RMID, 0) < 0) {
ErrPrint("shmctl: %s\n", strerror(errno));
+ }
return LB_STATUS_SUCCESS;
}
info = calloc(1, sizeof(*info));
if (!info) {
- CRITICAL_LOG("Heap: %s\n", strerror(errno));
+ ErrPrint("Heap: %s\n", strerror(errno));
return NULL;
}
info->id = strdup(id);
if (!info->id) {
- CRITICAL_LOG("Heap: %s\n", strerror(errno));
+ ErrPrint("Heap: %s\n", strerror(errno));
free(info);
return NULL;
}
if (!info->buffer) {
if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
- info->bufsz = info->w * info->h * s_info.depth;
+ update_fb_size(info);
+
buffer = calloc(1, sizeof(*buffer) + info->bufsz);
if (!buffer) {
- CRITICAL_LOG("Heap: %s\n", strerror(errno));
+ ErrPrint("Heap: %s\n", strerror(errno));
info->bufsz = 0;
return NULL;
}
*/
sync_for_pixmap(info);
} else if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) {
- info->bufsz = info->w * info->h * s_info.depth;
+ update_fb_size(info);
+
buffer = calloc(1, sizeof(*buffer) + info->bufsz);
if (!buffer) {
- CRITICAL_LOG("Heap: %s\n", strerror(errno));
+ ErrPrint("Heap: %s\n", strerror(errno));
info->bufsz = 0;
return NULL;
}
if (!data) {
ErrPrint("buffer data == NIL\n");
- return 0;
+ return LB_STATUS_ERROR_INVALID;
}
buffer = container_of(data, struct buffer, data);
switch (buffer->type) {
case BUFFER_TYPE_SHM:
- if (shmdt(buffer) < 0)
+ if (shmdt(buffer) < 0) {
ErrPrint("shmdt: %s\n", strerror(errno));
+ }
break;
case BUFFER_TYPE_PIXMAP:
buffer->refcnt--;
buffer->state = DESTROYED;
free(buffer);
- if (info && info->buffer == buffer)
+ if (info && info->buffer == buffer) {
info->buffer = NULL;
+ }
}
break;
case BUFFER_TYPE_FILE:
buffer->state = DESTROYED;
free(buffer);
- if (info && info->buffer == buffer)
+ if (info && info->buffer == buffer) {
info->buffer = NULL;
+ }
}
break;
default:
break;
}
- return 0;
+ return LB_STATUS_SUCCESS;
}
int fb_refcnt(void *data)
struct shmid_ds buf;
int ret;
- if (!data)
+ if (!data) {
return LB_STATUS_ERROR_INVALID;
+ }
buffer = container_of(data, struct buffer, data);
int fb_size(struct fb_info *info)
{
- if (!info)
+ if (!info) {
return 0;
+ }
+
+ update_fb_size(info);
- info->bufsz = info->w * info->h * s_info.depth;
return info->bufsz;
}
+int fb_type(struct fb_info *info)
+{
+ struct buffer *buffer;
+
+ if (!info) {
+ return BUFFER_TYPE_ERROR;
+ }
+
+ buffer = info->buffer;
+ if (!buffer) {
+ int type = BUFFER_TYPE_ERROR;
+ /*!
+ * \note
+ * Try to get this from SCHEMA
+ */
+ if (info->id) {
+ if (!strncasecmp(info->id, SCHEMA_FILE, strlen(SCHEMA_FILE))) {
+ type = BUFFER_TYPE_FILE;
+ } else if (!strncasecmp(info->id, SCHEMA_PIXMAP, strlen(SCHEMA_PIXMAP))) {
+ type = BUFFER_TYPE_PIXMAP;
+ } else if (!strncasecmp(info->id, SCHEMA_SHM, strlen(SCHEMA_SHM))) {
+ type = BUFFER_TYPE_SHM;
+ }
+ }
+
+ return type;
+ }
+
+ return buffer->type;
+}
/* End of a file */