External connection device type macros have a strong correlation.
And they can be grouped and there is no reason to exist
as an individual macro definition in terms of code maintenance.
Thus, hal_device_external_connection_device_type_e enum type is added.
To utilize above enum type properly,
converting functions are necessary.
With converting functions, enum can replace the use of existing macro string.
This functions is added.
- int hal_device_external_connection_get_device_name(hal_device_external_connection_device_type_e deivce_type, const char **device_name);
-> If hal_device_external_connection_device_type is not proper value, then this returns -EINVAL,
and device_name is filled with NULL.
If not, it will be return 0 and device_name is filled with proper device type name.
Also, converting const char* <-> hal_device_battery_power_source_type_e type
test case is added.
Change-Id: I3ababb0915c5340a3b6ca3c4751716077200282e
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
}
ASSERT_EQ(ret_val, 0) << strerr("Failed to get current state", ret_val);
}
+
+TEST_F(EXTCON, GetExternalConnectionDeviceNameP)
+{
+ const char *temp_external_connection_name = NULL;
+
+ if (!EXTCON::supported) {
+ SKIP_MESSAGE("External connection not supported");
+ return;
+ }
+
+ hal_device_external_connection_get_device_name(HAL_DEVICE_EXTERNAL_CONNECTION_USB, &temp_external_connection_name);
+ EXPECT_STREQ(temp_external_connection_name, "USB");
+
+ hal_device_external_connection_get_device_name(HAL_DEVICE_EXTERNAL_CONNECTION_USB_HOST, &temp_external_connection_name);
+ EXPECT_STREQ(temp_external_connection_name, "USB-HOST");
+
+ hal_device_external_connection_get_device_name(HAL_DEVICE_EXTERNAL_CONNECTION_TA, &temp_external_connection_name);
+ EXPECT_STREQ(temp_external_connection_name, "TA");
+
+ hal_device_external_connection_get_device_name(HAL_DEVICE_EXTERNAL_CONNECTION_HDMI, &temp_external_connection_name);
+ EXPECT_STREQ(temp_external_connection_name, "HDMI");
+
+ hal_device_external_connection_get_device_name(HAL_DEVICE_EXTERNAL_CONNECTION_DOCK, &temp_external_connection_name);
+ EXPECT_STREQ(temp_external_connection_name, "Dock");
+
+ hal_device_external_connection_get_device_name(HAL_DEVICE_EXTERNAL_CONNECTION_MIC, &temp_external_connection_name);
+ EXPECT_STREQ(temp_external_connection_name, "Microphone");
+
+ hal_device_external_connection_get_device_name(HAL_DEVICE_EXTERNAL_CONNECTION_HEADPHONE, &temp_external_connection_name);
+ EXPECT_STREQ(temp_external_connection_name, "Headphone");
+}
\ No newline at end of file
extern "C" {
#endif
-/* FIXME: These macros will be replaced by enum */
-#define EXTERNAL_CONNECTION_USB "USB"
-#define EXTERNAL_CONNECTION_USB_HOST "USB-HOST"
-#define EXTERNAL_CONNECTION_TA "TA"
-#define EXTERNAL_CONNECTION_HDMI "HDMI"
-#define EXTERNAL_CONNECTION_DOCK "Dock"
-#define EXTERNAL_CONNECTION_MIC "Microphone"
-#define EXTERNAL_CONNECTION_HEADPHONE "Headphone"
+/**
+ * @brief Enumeration for external connection device type.
+ * @since HAL_MODULE_DEVICE_EXTERNAL_CONNECTION 1.0
+ */
+typedef enum {
+ HAL_DEVICE_EXTERNAL_CONNECTION_USB = 0,
+ HAL_DEVICE_EXTERNAL_CONNECTION_USB_HOST,
+ HAL_DEVICE_EXTERNAL_CONNECTION_TA,
+ HAL_DEVICE_EXTERNAL_CONNECTION_HDMI,
+ HAL_DEVICE_EXTERNAL_CONNECTION_DOCK,
+ HAL_DEVICE_EXTERNAL_CONNECTION_MIC,
+ HAL_DEVICE_EXTERNAL_CONNECTION_HEADPHONE,
+} hal_device_external_connection_device_type_e;
/**
* @brief Structure for external connection information data.
* @since HAL_MODULE_DEVICE_EXTERNAL_CONNECTION 1.0
*/
typedef struct {
- char *name; /**< This indicates switch device type (Since HAL_MODULE_DEVICE_EXTERNAL_CONNECTION 1.0) */
+ hal_device_external_connection_device_type_e name; /**< This indicates switch device type (Since HAL_MODULE_DEVICE_EXTERNAL_CONNECTION 1.0) */
char *state; /**< This indicates current state of the switch device,
e.g) "on" of "off" (Since HAL_MODULE_DEVICE_EXTERNAL_CONNECTION 1.0) */
int flags;
int hal_device_external_connection_register_changed_event(hal_device_external_connection_updated_cb updated_cb, void *data);
int hal_device_external_connection_unregister_changed_event(hal_device_external_connection_updated_cb updated_cb);
int hal_device_external_connection_get_current_state(hal_device_external_connection_updated_cb updated_cb, void *data);
+int hal_device_external_connection_get_device_name(hal_device_external_connection_device_type_e deivce_type, const char **device_name);
#ifdef __cplusplus
}
return hal_device_external_connection_funcs->get_current_state(updated_cb, data);
}
+int hal_device_external_connection_get_device_name(hal_device_external_connection_device_type_e deivce_type, const char **device_name)
+{
+ if (!device_name)
+ return -EINVAL;
+
+ switch (deivce_type) {
+ case HAL_DEVICE_EXTERNAL_CONNECTION_USB:
+ *device_name = "USB";
+ break;
+ case HAL_DEVICE_EXTERNAL_CONNECTION_USB_HOST:
+ *device_name = "USB-HOST";
+ break;
+ case HAL_DEVICE_EXTERNAL_CONNECTION_TA:
+ *device_name = "TA";
+ break;
+ case HAL_DEVICE_EXTERNAL_CONNECTION_HDMI:
+ *device_name = "HDMI";
+ break;
+ case HAL_DEVICE_EXTERNAL_CONNECTION_DOCK:
+ *device_name = "Dock";
+ break;
+ case HAL_DEVICE_EXTERNAL_CONNECTION_MIC:
+ *device_name = "Microphone";
+ break;
+ case HAL_DEVICE_EXTERNAL_CONNECTION_HEADPHONE:
+ *device_name = "Headphone";
+ break;
+ default:
+ *device_name = NULL;
+ return -EINVAL;
+ }
+
+ return 0;
+}
+