UPSCLI_GET(3) | NUT Manual | UPSCLI_GET(3) |
NAME¶
upscli_get - retrieve data from a UPSSYNOPSIS¶
#include <upsclient.h>
int upscli_get(UPSCONN_t *ups, int numq, const char **query, int *numa, char ***answer)
DESCRIPTION¶
The upscli_get() function takes the pointer ups to a UPSCONN_t state structure, and the pointer query to an array of numq query elements. It builds a properly-formatted request from those elements and transmits it to upsd(8).USES¶
This function implements the "GET" command in the protocol. As a result, you can use it to request many different things from the server. Some examples are:•GET NUMLOGINS <ups>
•GET UPSDESC <ups>
•GET VAR <ups> <var>
•GET TYPE <ups> <var>
•GET DESC <ups> <var>
•GET CMDDESC <ups>
<cmd>
QUERY FORMATTING¶
To generate a request for GET NUMLOGINS su700, you would populate query and numq as follows:int numq; const char *query[2];
query[0] = "NUMLOGINS"; query[1] = "su700"; numq = 2;
ANSWER FORMATTING¶
The raw response from upsd to the above query would be NUMLOGINS su700 1. Since this is split up for you, the values work out like this:numa = 3; answer[0] = "NUMLOGINS" answer[1] = "su700" answer[2] = "1"
ERROR CHECKING¶
This function will check your query against the response from upsd(8). For example, if you send "VAR" "su700" "ups.status", it will expect to see those at the beginning of the response.ANSWER ARRAY LIFETIME¶
The pointers contained within the answer array are only valid until the next call to a upsclient function which references them. If you need to use data from multiple calls, you must copy it somewhere else first.RETURN VALUE¶
The upscli_get() function returns 0 on success, or -1 if an error occurs.SEE ALSO¶
upscli_list_start(3), upscli_list_next(3), upscli_strerror(3), upscli_upserror(3)05/22/2012 | Network UPS Tools |