added fucntion for getting drm fd used by backend 59/109959/3
authorChangyeon Lee <cyeon.lee@samsung.com>
Thu, 12 Jan 2017 09:13:29 +0000 (18:13 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Thu, 12 Jan 2017 10:12:39 +0000 (19:12 +0900)
Change-Id: I8aa01d67ad49597b99552e3cd6acee7675d89f86

src/tbm_drm_helper.h
src/tbm_drm_helper_client.c

index 3584eeb..77f97ce 100644 (file)
@@ -109,4 +109,36 @@ void tbm_drm_helper_unset_tbm_master_fd(void);
  */
 int tbm_drm_helper_get_auth_info(int *auth_fd, char **device, uint32_t *capabilities);
 
+/**
+ * @brief Set the given fd to TBM_DRM_FD enviroment variable.
+ * @details
+ * Some client want to get drm fd used tbm_backend.
+   if tbm_backend allow that client use drm_fd, it SHOULD be set.
+ * @param[in] fd The given fd
+ * @see #tbm_drm_helper_get_fd()
+ */
+void tbm_drm_helper_set_fd(int fd);
+
+/**
+ * @brief Unset the given fd to TBM_DRM_FD enviroment variable.
+ * @details
+ * Some client want to get drm fd used tbm_backend.
+   if tbm_backend allow that client use drm_fd, it SHOULD be set.
+ * @param[in] fd The given fd
+ * @see #tbm_drm_helper_get_fd()
+ */
+void tbm_drm_helper_unset_fd(void);
+
+/**
+ * @brief Get the fd from TBM_DRM_FD enviroment variable.
+ * @details
+ * Some client want to get drm fd used tbm_backend.
+   client can get drm fd from this fucntion.
+   The Caller SHOULD close the fd.
+ * @return fd if success. Otherwise, -1.
+ * @see #tdm_helper_set_tbm_master_fd()
+ * @see #tbm_drm_helper_unset_tbm_master_fd()
+ */
+int tbm_drm_helper_get_fd(void);
+
 #endif                                                 /* _TBM_DRM_HELPER_H_ */
index 3710936..affb2dc 100644 (file)
@@ -186,5 +186,73 @@ tbm_drm_helper_get_auth_info(int *auth_fd, char **device, uint32_t *capabilities
 
        return 1;
 }
-/* LCOV_EXCL_STOP */
 
+
+void
+tbm_drm_helper_set_fd(int fd)
+{
+       char buf[32];
+       int ret;
+
+       snprintf(buf, sizeof(buf), "%d", fd);
+
+       ret = setenv("TBM_DRM_FD", (const char*)buf, 1);
+       if (ret) {
+               TBM_LOG_E("failed to set TBM_DRM_FD to %d\n", fd);
+               return;
+       }
+
+       TBM_LOG_I("TBM_DRM_FD: %d\n", fd);
+}
+
+void
+tbm_drm_helper_unset_fd(void)
+{
+       int ret;
+
+       ret = unsetenv("TBM_DRM_FD");
+       if (ret) {
+               TBM_LOG_E("failed to unset TBM_DRM_FD\n");
+               return;
+       }
+}
+
+int
+tbm_drm_helper_get_fd(void)
+{
+       const char *value;
+       int ret, flags, fd = -1;
+       int new_fd = -1;
+
+       value = (const char*)getenv("TBM_DRM_FD");
+       if (!value)
+               return -1;
+
+       ret = sscanf(value, "%d", &fd);
+       if (ret <= 0)
+               return -1;
+
+       TBM_LOG_I("TBM_DRM_FD: %d\n", fd);
+
+       flags = fcntl(fd, F_GETFD);
+       if (flags == -1) {
+               TBM_LOG_E("fcntl failed: %m\n");
+               return -1;
+       }
+
+       new_fd = dup(fd);
+       if (new_fd < 0) {
+               TBM_LOG_E("dup failed: %m\n");
+               return -1;
+       }
+
+       fcntl(new_fd, F_SETFD, flags|FD_CLOEXEC);
+
+       TBM_LOG_I("Return TBM_FD: %d\n", new_fd);
+
+       return new_fd;
+
+       return fd;
+}
+
+/* LCOV_EXCL_STOP */