Skip to content

Commit

Permalink
Merge pull request #12 from allanliu/client_interface
Browse files Browse the repository at this point in the history
libsmartctl:  libsmartctl client interface
  • Loading branch information
allanliu authored May 17, 2018
2 parents 4ec6121 + 8de0847 commit 6afcf54
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
61 changes: 56 additions & 5 deletions libsmartctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct CantIdDevResp {
CantIdDevResp() : err(NOERR) {}
};

class Client {
class ClientInterface {
public:
/**
* @brief Checks if device name of the param type can be identified.
Expand All @@ -81,7 +81,7 @@ class Client {
* device can't be IDed, meaning if it can't -> return true.
*/
virtual CantIdDevResp cantIdDev(std::string const &devname,
std::string const &type);
std::string const &type) = 0;

/**
*@brief Retrieves drive information.
Expand All @@ -94,7 +94,7 @@ class Client {
* @return Map of information type and value, both strings.
*/
virtual DevInfoResp getDevInfo(std::string const &devname,
std::string const &type = "");
std::string const &type = "") = 0;

/**
*@brief Retrieves drive vendor attributes
Expand All @@ -107,8 +107,59 @@ class Client {
* @return a vector maps containing string key and values of vendor attribute
*type name and attribute type values
*/
virtual DevVendorAttrsResp getDevVendorAttrs(std::string const &devname,
std::string const &type = "");
virtual DevVendorAttrsResp
getDevVendorAttrs(std::string const &devname,
std::string const &type = "") = 0;

public:
virtual ~ClientInterface() {}
};

class Client : public ClientInterface {
public:
/**
* @brief Checks if device name of the param type can be identified.
* Gaurantees if true, the device is not identifiable, but if true, it still
* necessarily mean device is identifiable.
*
* @param String of full path device name.
*
* @param String of device type, if left blank, auto device type detection
* will be used.
*
* @return struct containing an err type and a boolean indicating if the the
* device can't be IDed, meaning if it can't -> return true.
*/
virtual CantIdDevResp cantIdDev(std::string const &devname,
std::string const &type) override;

/**
*@brief Retrieves drive information.
*
* @param String of full path device name.
*
* @param String of device type, if left blank, auto device type detection
* will be used.
*
* @return Map of information type and value, both strings.
*/
virtual DevInfoResp getDevInfo(std::string const &devname,
std::string const &type = "") override;

/**
*@brief Retrieves drive vendor attributes
*
* @param string of full path device name
*
* @param String of device type, if left blank, auto device type detection
* will be used.
*
* @return a vector maps containing string key and values of vendor attribute
*type name and attribute type values
*/
virtual DevVendorAttrsResp
getDevVendorAttrs(std::string const &devname,
std::string const &type = "") override;

public:
Client();
Expand Down
2 changes: 1 addition & 1 deletion libsmartctl_ata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static void get_drive_info(std::map<std::string, std::string> &results,
uint64_t unique_id = 0;
int naa = ata_get_wwn(drive, oui, unique_id);
if (naa >= 0) {
results["LU_WWN_device_id"] =
results["lu_wwn_device_id"] =
strprintf("%x %06x %09" PRIx64, naa, oui, unique_id);
}
}
Expand Down

0 comments on commit 6afcf54

Please sign in to comment.