device: Merge public api on Tizen 2.3 into tizen branch
[platform/core/api/device.git] / src / common.h
similarity index 51%
rename from include/device_log.h
rename to src/common.h
index 8752926..dd01165 100644 (file)
  * limitations under the License.
  */
 
-#ifndef __DEVICE_LOG_H__
-#define __DEVICE_LOG_H__
+#ifndef __COMMON_H__
+#define __COMMON_H__
 
 #ifdef FEATURE_DEVICE_DLOG
     #define LOG_TAG "SYSTEM_DEVICE"
     #include <dlog.h>
-    #define DEVICE_LOG(fmt, args...)       SLOGD(fmt, ##args)
-    #define DEVICE_ERROR(fmt, args...)     SLOGE(fmt, ##args)
+    #define _D(fmt, args...)   SLOGD(fmt, ##args)
+    #define _I(fmt, args...)   SLOGI(fmt, ##args)
+    #define _E(fmt, args...)   SLOGE(fmt, ##args)
 #else
-    #define DEVICE_LOG(x, ...)
-    #define DEVICE_ERROR(x, ...)
+    #define _D(x, ...)
+    #define _I(x, ...)
+    #define _E(x, ...)
 #endif
 
-#endif /* __DEVICE_LOG_H__ */
+#ifndef __CONSTRUCTOR__
+#define __CONSTRUCTOR__ __attribute__ ((constructor))
+#endif
+
+#include "device-error.h"
+
+static inline int errno_to_device_error(int err)
+{
+       if (err == -ECOMM)
+               return DEVICE_ERROR_PERMISSION_DENIED;
+       else if (err == -ENODEV || err == -ENOENT)
+               return DEVICE_ERROR_NOT_SUPPORTED;
+       else if (err < 0)
+               return DEVICE_ERROR_OPERATION_FAILED;
+
+       return DEVICE_ERROR_NONE;
+}
+
+#endif /* __COMMON_H__ */