From 02ee2c6832291a768a1bf749baf68ec8756db528 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Thu, 13 Oct 2011 20:25:50 +0200 Subject: [PATCH] cec: use int instead of bool on the public C interface and remove stdbool.h include --- include/cecc.h | 42 +++++++++++++------------- include/cectypes.h | 20 +++++-------- src/lib/LibCECC.cpp | 72 ++++++++++++++++++++++----------------------- 3 files changed, 65 insertions(+), 69 deletions(-) diff --git a/include/cecc.h b/include/cecc.h index 1d4c26c..bfbe0cc 100644 --- a/include/cecc.h +++ b/include/cecc.h @@ -48,9 +48,9 @@ extern "C" { * @return True when initialised, false otherwise. */ #ifdef __cplusplus -extern DECLSPEC bool cec_init(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); +extern DECLSPEC int cec_init(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); #else -extern DECLSPEC bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); +extern DECLSPEC int cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); #endif /*! @@ -64,7 +64,7 @@ extern DECLSPEC void cec_destroy(void); * @param iTimeout Connection timeout in ms. * @return True when connected, false otherwise. */ -extern DECLSPEC bool cec_open(const char *strPort, uint32_t iTimeout); +extern DECLSPEC int cec_open(const char *strPort, uint32_t iTimeout); /*! * @brief Close the connection to the CEC adapter. @@ -87,13 +87,13 @@ extern DECLSPEC int8_t cec_find_adapters(cec_adapter *deviceList, uint8_t iBufSi * @brief Ping the CEC adapter. * @return True when the ping was succesful, false otherwise. */ -extern DECLSPEC bool cec_ping_adapters(void); +extern DECLSPEC int cec_ping_adapters(void); /*! * @brief Start the bootloader of the CEC adapter. * @return True when the command was sent succesfully, false otherwise. */ -extern DECLSPEC bool cec_start_bootloader(void); +extern DECLSPEC int cec_start_bootloader(void); /*! * @return Get the minimal version of libcec that this version of libcec can interface with. @@ -111,9 +111,9 @@ extern DECLSPEC int8_t cec_get_lib_version(void); * @return True when the command was sent succesfully, false otherwise. */ #ifdef __cplusplus -extern DECLSPEC bool cec_power_on_devices(CEC::cec_logical_address address = CEC::CECDEVICE_TV); +extern DECLSPEC int cec_power_on_devices(CEC::cec_logical_address address = CEC::CECDEVICE_TV); #else -extern DECLSPEC bool cec_power_on_devices(cec_logical_address address = CECDEVICE_TV); +extern DECLSPEC int cec_power_on_devices(cec_logical_address address = CECDEVICE_TV); #endif /*! @@ -122,22 +122,22 @@ extern DECLSPEC bool cec_power_on_devices(cec_logical_address address = CECDEVIC * @return True when the command was sent succesfully, false otherwise. */ #ifdef __cplusplus -extern DECLSPEC bool cec_standby_devices(CEC::cec_logical_address address = CEC::CECDEVICE_BROADCAST); +extern DECLSPEC int cec_standby_devices(CEC::cec_logical_address address = CEC::CECDEVICE_BROADCAST); #else -extern DECLSPEC bool cec_standby_devices(cec_logical_address address = CECDEVICE_BROADCAST); +extern DECLSPEC int cec_standby_devices(cec_logical_address address = CECDEVICE_BROADCAST); #endif /*! * @brief Broadcast a message that notifies connected CEC capable devices that this device is the active source. * @return True when the command was sent succesfully, false otherwise. */ -extern DECLSPEC bool cec_set_active_view(void); +extern DECLSPEC int cec_set_active_view(void); /*! * @brief Broadcast a message that notifies connected CEC capable devices that this device is no longer the active source. * @return True when the command was sent succesfully, false otherwise. */ -extern DECLSPEC bool cec_set_inactive_view(void); +extern DECLSPEC int cec_set_inactive_view(void); /*! * @brief Get the next log message in the queue, if there is one. @@ -145,9 +145,9 @@ extern DECLSPEC bool cec_set_inactive_view(void); * @return True if a message was passed, false otherwise. */ #ifdef __cplusplus -extern DECLSPEC bool cec_get_next_log_message(CEC::cec_log_message *message); +extern DECLSPEC int cec_get_next_log_message(CEC::cec_log_message *message); #else -extern DECLSPEC bool cec_get_next_log_message(cec_log_message *message); +extern DECLSPEC int cec_get_next_log_message(cec_log_message *message); #endif /*! @@ -156,9 +156,9 @@ extern DECLSPEC bool cec_get_next_log_message(cec_log_message *message); * @return True if a key was passed, false otherwise. */ #ifdef __cplusplus -extern DECLSPEC bool cec_get_next_keypress(CEC::cec_keypress *key); +extern DECLSPEC int cec_get_next_keypress(CEC::cec_keypress *key); #else -extern DECLSPEC bool cec_get_next_keypress(cec_keypress *key); +extern DECLSPEC int cec_get_next_keypress(cec_keypress *key); #endif /*! @@ -167,9 +167,9 @@ extern DECLSPEC bool cec_get_next_keypress(cec_keypress *key); * @return True when a command was passed, false otherwise. */ #ifdef __cplusplus -extern DECLSPEC bool cec_get_next_command(CEC::cec_command *command); +extern DECLSPEC int cec_get_next_command(CEC::cec_command *command); #else -extern DECLSPEC bool cec_get_next_command(cec_command *command); +extern DECLSPEC int cec_get_next_command(cec_command *command); #endif /*! @@ -179,9 +179,9 @@ extern DECLSPEC bool cec_get_next_command(cec_command *command); * @return True when the data was sent and acked, false otherwise. */ #ifdef __cplusplus -extern DECLSPEC bool cec_transmit(const CEC::cec_command &data, bool bWaitForAck = true); +extern DECLSPEC int cec_transmit(const CEC::cec_command &data, int bWaitForAck = 1); #else -extern DECLSPEC bool cec_transmit(const cec_command &data, bool bWaitForAck = true); +extern DECLSPEC int cec_transmit(const cec_command &data, int bWaitForAck = 1); #endif /*! @@ -190,9 +190,9 @@ extern DECLSPEC bool cec_transmit(const cec_command &data, bool bWaitForAck = tr * @return True when the logical address was set succesfully, false otherwise. */ #ifdef __cplusplus -extern DECLSPEC bool cec_set_logical_address(CEC::cec_logical_address iLogicalAddress); +extern DECLSPEC int cec_set_logical_address(CEC::cec_logical_address iLogicalAddress); #else -extern DECLSPEC bool cec_set_logical_address(cec_logical_address myAddress, cec_logical_address targetAddress); +extern DECLSPEC int cec_set_logical_address(cec_logical_address myAddress, cec_logical_address targetAddress); #endif #ifdef __cplusplus diff --git a/include/cectypes.h b/include/cectypes.h index eee0552..854fdeb 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -37,10 +37,6 @@ #include #include -#if !defined(_WIN32) && !defined(_WIN64) -#include -#endif - #if !defined(DECLSPEC) #if defined(_WIN32) || defined(_WIN64) #include @@ -646,11 +642,11 @@ typedef struct cec_command { cec_logical_address initiator; cec_logical_address destination; - bool ack; - bool eom; + int8_t ack; + int8_t eom; cec_opcode opcode; cec_datapacket parameters; - bool opcode_set; + int8_t opcode_set; #ifdef __cplusplus static void format(cec_command &command, cec_logical_address initiator, cec_logical_address destination, cec_opcode opcode) @@ -659,14 +655,14 @@ typedef struct cec_command command.initiator = initiator; command.destination = destination; command.opcode = opcode; - command.opcode_set = true; + command.opcode_set = 1; } void push_back(uint8_t data) { if (!opcode_set) { - opcode_set = true; + opcode_set = 1; opcode = (cec_opcode) data; } else @@ -677,9 +673,9 @@ typedef struct cec_command { initiator = CECDEVICE_UNKNOWN; destination = CECDEVICE_UNKNOWN; - ack = false; - eom = false; - opcode_set = false; + ack = 0; + eom = 0; + opcode_set = 0; opcode = CEC_OPCODE_FEATURE_ABORT; parameters.clear(); }; diff --git a/src/lib/LibCECC.cpp b/src/lib/LibCECC.cpp index d55681e..1c9ef4d 100644 --- a/src/lib/LibCECC.cpp +++ b/src/lib/LibCECC.cpp @@ -42,10 +42,10 @@ using namespace std; //@{ ICECAdapter *cec_parser; -bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint8_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) +int cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint8_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) { cec_parser = (ICECAdapter *) CECCreate(strDeviceName, iLogicalAddress, iPhysicalAddress); - return (cec_parser != NULL); + return (cec_parser != NULL) ? 1 : 0; } void cec_destroy(void) @@ -55,7 +55,7 @@ void cec_destroy(void) cec_parser = NULL; } -bool cec_open(const char *strPort, uint32_t iTimeout) +int cec_open(const char *strPort, uint32_t iTimeout) { if (cec_parser) return cec_parser->Open(strPort, iTimeout); @@ -75,18 +75,18 @@ int8_t cec_find_adapters(cec_adapter *deviceList, uint8_t iBufSize, const char * return -1; } -bool cec_ping_adapters(void) +int cec_ping_adapters(void) { if (cec_parser) - return cec_parser->PingAdapter(); - return false; + return cec_parser->PingAdapter() ? 1 : 0; + return -1; } -bool cec_start_bootloader(void) +int cec_start_bootloader(void) { if (cec_parser) - return cec_parser->StartBootloader(); - return false; + return cec_parser->StartBootloader() ? 1 : 0; + return -1; } int8_t cec_get_min_version(void) @@ -103,67 +103,67 @@ int8_t cec_get_lib_version(void) return -1; } -bool cec_get_next_log_message(cec_log_message *message) +int cec_get_next_log_message(cec_log_message *message) { if (cec_parser) - return cec_parser->GetNextLogMessage(message); - return false; + return cec_parser->GetNextLogMessage(message) ? 1 : 0; + return -1; } -bool cec_get_next_keypress(cec_keypress *key) +int cec_get_next_keypress(cec_keypress *key) { if (cec_parser) - return cec_parser->GetNextKeypress(key); - return false; + return cec_parser->GetNextKeypress(key) ? 1 : 0; + return -1; } -bool cec_get_next_command(cec_command *command) +int cec_get_next_command(cec_command *command) { if (cec_parser) - return cec_parser->GetNextCommand(command); - return false; + return cec_parser->GetNextCommand(command) ? 1 : 0; + return -1; } -bool cec_transmit(const CEC::cec_command &data, bool bWaitForAck /* = true */) +int cec_transmit(const CEC::cec_command &data, int bWaitForAck /* = true */) { if (cec_parser) - return cec_parser->Transmit(data, bWaitForAck); - return false; + return cec_parser->Transmit(data, bWaitForAck == 1) ? 1 : 0; + return -1; } -bool cec_set_logical_address(cec_logical_address iLogicalAddress) +int cec_set_logical_address(cec_logical_address iLogicalAddress) { if (cec_parser) - return cec_parser->SetLogicalAddress(iLogicalAddress); - return false; + return cec_parser->SetLogicalAddress(iLogicalAddress) ? 1 : 0; + return -1; } -bool cec_power_on_devices(cec_logical_address address /* = CECDEVICE_TV */) +int cec_power_on_devices(cec_logical_address address /* = CECDEVICE_TV */) { if (cec_parser) - return cec_parser->PowerOnDevices(address); - return false; + return cec_parser->PowerOnDevices(address) ? 1 : 0; + return -1; } -bool cec_standby_devices(cec_logical_address address /* = CECDEVICE_BROADCAST */) +int cec_standby_devices(cec_logical_address address /* = CECDEVICE_BROADCAST */) { if (cec_parser) - return cec_parser->StandbyDevices(address); - return false; + return cec_parser->StandbyDevices(address) ? 1 : 0; + return -1; } -bool cec_set_active_view(void) +int cec_set_active_view(void) { if (cec_parser) - return cec_parser->SetActiveView(); - return false; + return cec_parser->SetActiveView() ? 1 : 0; + return -1; } -bool cec_set_inactive_view(void) +int cec_set_inactive_view(void) { if (cec_parser) - return cec_parser->SetInactiveView(); - return false; + return cec_parser->SetInactiveView() ? 1 : 0; + return -1; } //@} -- 2.34.1