Merge "Fix indentation and style issues in fmAPI"
This commit is contained in:
commit
7ff98a067f
@ -32,107 +32,116 @@
|
|||||||
#define MAX_PENDING_REQUEST 1000
|
#define MAX_PENDING_REQUEST 1000
|
||||||
|
|
||||||
#define HANDLE_SERVER_RC(hdr) \
|
#define HANDLE_SERVER_RC(hdr) \
|
||||||
if ((hdr)->msg_rc!=FM_ERR_OK) return (EFmErrorT) (hdr)->msg_rc
|
if ((hdr)->msg_rc!=FM_ERR_OK) return (EFmErrorT) (hdr)->msg_rc
|
||||||
|
|
||||||
#define CHECK_RESPONSE(hdr,neededstruct) \
|
#define CHECK_RESPONSE(hdr,neededstruct) \
|
||||||
if (!fm_valid_srv_msg(hdr,sizeof(neededstruct))) \
|
if (!fm_valid_srv_msg(hdr,sizeof(neededstruct))) \
|
||||||
return FM_ERR_COMMUNICATIONS
|
return FM_ERR_COMMUNICATIONS
|
||||||
|
|
||||||
#define CHECK_LIST_FULL(l) \
|
#define CHECK_LIST_FULL(l) \
|
||||||
if (l.size() == MAX_PENDING_REQUEST) \
|
if (l.size() == MAX_PENDING_REQUEST) \
|
||||||
return FM_ERR_NOT_ENOUGH_SPACE
|
return FM_ERR_NOT_ENOUGH_SPACE
|
||||||
|
|
||||||
#define CHECK_LIST_NOT_EMPTY(l) \
|
#define CHECK_LIST_NOT_EMPTY(l) \
|
||||||
if (l.size() != 0) \
|
if (l.size() != 0) \
|
||||||
return FM_ERR_REQUEST_PENDING
|
return FM_ERR_REQUEST_PENDING
|
||||||
|
|
||||||
static CFmSocket m_client;
|
static CFmSocket m_client;
|
||||||
static bool m_connected = false;
|
static bool m_connected = false;
|
||||||
static bool m_thread = false;
|
static bool m_thread = false;
|
||||||
|
|
||||||
typedef std::list<fm_buff_t> FmRequestListT;
|
typedef std::list<fm_buff_t> FmRequestListT;
|
||||||
static FmRequestListT & GetListOfFmRequests(){
|
|
||||||
static FmRequestListT reqs;
|
|
||||||
return reqs;
|
static FmRequestListT & GetListOfFmRequests() {
|
||||||
|
static FmRequestListT reqs;
|
||||||
|
return reqs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CFmMutex & getListMutex(){
|
|
||||||
static CFmMutex *m = new CFmMutex;
|
static CFmMutex & getListMutex() {
|
||||||
return *m;
|
static CFmMutex *m = new CFmMutex;
|
||||||
|
return *m;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CFmMutex & getThreadMutex(){
|
|
||||||
static CFmMutex *m = new CFmMutex;
|
static CFmMutex & getThreadMutex() {
|
||||||
return *m;
|
static CFmMutex *m = new CFmMutex;
|
||||||
|
return *m;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFmMutex & getAPIMutex(){
|
|
||||||
static pthread_mutex_t ml = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
CFmMutex & getAPIMutex() {
|
||||||
static CFmMutex *m = NULL;
|
static pthread_mutex_t ml = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
||||||
if (m == NULL){
|
static CFmMutex *m = NULL;
|
||||||
pthread_mutex_lock(&ml);
|
if (m == NULL) {
|
||||||
m = new CFmMutex;
|
pthread_mutex_lock(&ml);
|
||||||
pthread_mutex_unlock(&ml);
|
m = new CFmMutex;
|
||||||
}
|
pthread_mutex_unlock(&ml);
|
||||||
return *m;
|
}
|
||||||
|
return *m;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void enqueue(fm_buff_t &req){
|
|
||||||
CFmMutexGuard m(getListMutex());
|
static void enqueue(fm_buff_t &req) {
|
||||||
GetListOfFmRequests().push_back(req);
|
CFmMutexGuard m(getListMutex());
|
||||||
|
GetListOfFmRequests().push_back(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool dequeue(fm_buff_t &req){
|
|
||||||
CFmMutexGuard m(getListMutex());
|
static bool dequeue(fm_buff_t &req) {
|
||||||
if (GetListOfFmRequests().size() == 0){
|
CFmMutexGuard m(getListMutex());
|
||||||
return false;
|
if (GetListOfFmRequests().size() == 0) {
|
||||||
}
|
return false;
|
||||||
FmRequestListT::iterator it = GetListOfFmRequests().begin();
|
}
|
||||||
req.clear();
|
|
||||||
req = (*it);
|
FmRequestListT::iterator it = GetListOfFmRequests().begin();
|
||||||
GetListOfFmRequests().pop_front();
|
req.clear();
|
||||||
return true;
|
req = (*it);
|
||||||
|
GetListOfFmRequests().pop_front();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool fm_lib_reconnect() {
|
static bool fm_lib_reconnect() {
|
||||||
char addr[INET6_ADDRSTRLEN];
|
char addr[INET6_ADDRSTRLEN];
|
||||||
|
|
||||||
while (!m_connected) {
|
while (!m_connected) {
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
struct addrinfo *result=NULL, *rp;
|
struct addrinfo *result = NULL, *rp;
|
||||||
memset(&hints,0,sizeof(hints));
|
memset(&hints,0,sizeof(hints));
|
||||||
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
|
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
|
||||||
hints.ai_socktype = SOCK_STREAM; /* Datagram socket */
|
hints.ai_socktype = SOCK_STREAM; /* Datagram socket */
|
||||||
hints.ai_flags = 0; /* For wildcard IP address */
|
hints.ai_flags = 0; /* For wildcard IP address */
|
||||||
hints.ai_protocol = 0; /* Any protocol */
|
hints.ai_protocol = 0; /* Any protocol */
|
||||||
hints.ai_canonname = NULL;
|
hints.ai_canonname = NULL;
|
||||||
hints.ai_addr = NULL;
|
hints.ai_addr = NULL;
|
||||||
hints.ai_next = NULL;
|
hints.ai_next = NULL;
|
||||||
|
|
||||||
int rc = getaddrinfo(FM_MGR_HOST_NAME,NULL,
|
int rc = getaddrinfo(FM_MGR_HOST_NAME, NULL,
|
||||||
&hints,
|
&hints,
|
||||||
&result);
|
&result);
|
||||||
if (rc!=0) {
|
if (rc != 0) {
|
||||||
FM_ERROR_LOG("controller lookup failed... errno:%d",errno);
|
FM_ERROR_LOG("controller lookup failed... errno:%d", errno);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
||||||
if (rp->ai_family==AF_INET||rp->ai_family==AF_INET6) {
|
if (rp->ai_family == AF_INET || rp->ai_family==AF_INET6) {
|
||||||
if(rp->ai_family==AF_INET) {
|
if(rp->ai_family == AF_INET) {
|
||||||
inet_ntop(AF_INET, &(((sockaddr_in*)rp->ai_addr)->sin_addr), addr, sizeof(addr));
|
inet_ntop(AF_INET, &(((sockaddr_in*)rp->ai_addr)->sin_addr), addr, sizeof(addr));
|
||||||
} else if (rp->ai_family==AF_INET6) {
|
} else if (rp->ai_family == AF_INET6) {
|
||||||
inet_ntop(AF_INET6, &(((sockaddr_in6*)rp->ai_addr)->sin6_addr), addr, sizeof(addr));
|
inet_ntop(AF_INET6, &(((sockaddr_in6*)rp->ai_addr)->sin6_addr), addr, sizeof(addr));
|
||||||
}
|
}
|
||||||
m_connected=m_client.connect(addr,8001,rp->ai_family);
|
m_connected = m_client.connect(addr, 8001, rp->ai_family);
|
||||||
if (m_connected==true) {
|
if (m_connected == true) {
|
||||||
FM_INFO_LOG("Connected to FM Manager.");
|
FM_INFO_LOG("Connected to FM Manager.");
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
FM_WARNING_LOG("Failed to connect to FM Manager.");
|
FM_WARNING_LOG("Failed to connect to FM Manager.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -140,375 +149,387 @@ static bool fm_lib_reconnect() {
|
|||||||
return (m_connected);
|
return (m_connected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EFmErrorT fm_msg_utils_prep_requet_msg(fm_buff_t &buff,
|
EFmErrorT fm_msg_utils_prep_requet_msg(fm_buff_t &buff,
|
||||||
EFmMsgActionsT act,
|
EFmMsgActionsT act,
|
||||||
const void * data,
|
const void * data,
|
||||||
uint32_t len) {
|
uint32_t len) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
buff.resize(sizeof(SFmMsgHdrT) + len);
|
buff.resize(sizeof(SFmMsgHdrT) + len);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
FM_ERROR_LOG("Buff resize failed: errno:%d",errno);
|
FM_ERROR_LOG("Buff resize failed: errno:%d",errno);
|
||||||
return FM_ERR_NOMEM;
|
return FM_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
SFmMsgHdrT *hdr = ptr_to_hdr(buff);
|
SFmMsgHdrT *hdr = ptr_to_hdr(buff);
|
||||||
hdr->action = act;
|
hdr->action = act;
|
||||||
hdr->msg_size = len;
|
hdr->msg_size = len;
|
||||||
hdr->version = EFmMsgV1;
|
hdr->version = EFmMsgV1;
|
||||||
hdr->msg_rc = 0;
|
hdr->msg_rc = 0;
|
||||||
memcpy(ptr_to_data(buff),data,len);
|
memcpy(ptr_to_data(buff), data, len);
|
||||||
return FM_ERR_OK;
|
return FM_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fmApiJobHandlerThread(void *context){
|
|
||||||
|
|
||||||
while (true){
|
static void fmApiJobHandlerThread(void *context) {
|
||||||
fm_buff_t buff;
|
|
||||||
buff.clear();
|
while (true) {
|
||||||
while (dequeue(buff)){
|
fm_buff_t buff;
|
||||||
while (true) {
|
buff.clear();
|
||||||
while (!fm_lib_reconnect()){
|
while (dequeue(buff)) {
|
||||||
fmThreadSleep(200);
|
while (true) {
|
||||||
}
|
while (!fm_lib_reconnect()) {
|
||||||
fm_log_request(buff);
|
fmThreadSleep(200);
|
||||||
// protect from other sync APIs to access the same socket
|
}
|
||||||
CFmMutexGuard m(getAPIMutex());
|
fm_log_request(buff);
|
||||||
if(m_client.write_packet(buff)) {
|
// protect from other sync APIs to access the same socket
|
||||||
fm_buff_t in_buff;
|
CFmMutexGuard m(getAPIMutex());
|
||||||
in_buff.clear();
|
if(m_client.write_packet(buff)) {
|
||||||
if(!m_client.read_packet(in_buff)) {
|
fm_buff_t in_buff;
|
||||||
// retry after read failure
|
in_buff.clear();
|
||||||
fm_log_response(buff, in_buff, true);
|
if(!m_client.read_packet(in_buff)) {
|
||||||
m_connected = false;
|
// retry after read failure
|
||||||
continue;
|
fm_log_response(buff, in_buff, true);
|
||||||
}
|
m_connected = false;
|
||||||
else {
|
continue;
|
||||||
fm_log_response(buff, in_buff);
|
} else {
|
||||||
break;
|
fm_log_response(buff, in_buff);
|
||||||
}
|
break;
|
||||||
}else{
|
}
|
||||||
//retry after write failure
|
} else {
|
||||||
fm_log_request(buff, true);
|
// retry after write failure
|
||||||
m_connected = false;
|
fm_log_request(buff, true);
|
||||||
continue;
|
m_connected = false;
|
||||||
}
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmThreadSleep(50);
|
}
|
||||||
}
|
fmThreadSleep(50);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool fm_lib_thread(){
|
|
||||||
CFmMutexGuard m(getThreadMutex());
|
static bool fm_lib_thread() {
|
||||||
if (!m_thread){
|
CFmMutexGuard m(getThreadMutex());
|
||||||
FM_INFO_LOG("Creating thread");
|
if (!m_thread) {
|
||||||
if (!fmCreateThread(fmApiJobHandlerThread,NULL)) {
|
FM_INFO_LOG("Creating thread");
|
||||||
FM_ERROR_LOG("Fail to create API job thread");
|
if (!fmCreateThread(fmApiJobHandlerThread, NULL)) {
|
||||||
}
|
FM_ERROR_LOG("Fail to create API job thread");
|
||||||
else {
|
} else {
|
||||||
m_thread = true;
|
m_thread = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m_thread;
|
return m_thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
static EFmErrorT fm_check_thread_pending_request(){
|
|
||||||
CFmMutexGuard m(getThreadMutex());
|
static EFmErrorT fm_check_thread_pending_request() {
|
||||||
if (m_thread){
|
CFmMutexGuard m(getThreadMutex());
|
||||||
CHECK_LIST_NOT_EMPTY(GetListOfFmRequests());
|
if (m_thread) {
|
||||||
}
|
CHECK_LIST_NOT_EMPTY(GetListOfFmRequests());
|
||||||
return FM_ERR_OK;
|
}
|
||||||
|
return FM_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
EFmErrorT fm_init_lib() {
|
EFmErrorT fm_init_lib() {
|
||||||
signal(SIGINT,SIG_IGN);
|
signal(SIGINT,SIG_IGN);
|
||||||
|
|
||||||
CFmMutexGuard m(getAPIMutex());
|
CFmMutexGuard m(getAPIMutex());
|
||||||
if (!fm_lib_reconnect()) {
|
if (!fm_lib_reconnect()) {
|
||||||
FM_ERROR_LOG("Socket connection failed\n");
|
FM_ERROR_LOG("Socket connection failed\n");
|
||||||
return FM_ERR_NOCONNECT;
|
return FM_ERR_NOCONNECT;
|
||||||
}
|
}
|
||||||
return FM_ERR_OK;
|
return FM_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EFmErrorT fm_set_fault(const SFmAlarmDataT *alarm,
|
EFmErrorT fm_set_fault(const SFmAlarmDataT *alarm,
|
||||||
fm_uuid_t *uuid){
|
fm_uuid_t *uuid) {
|
||||||
|
|
||||||
CFmMutexGuard m(getAPIMutex());
|
CFmMutexGuard m(getAPIMutex());
|
||||||
if (!fm_lib_reconnect()) return FM_ERR_NOCONNECT;
|
if (!fm_lib_reconnect()) return FM_ERR_NOCONNECT;
|
||||||
|
|
||||||
fm_buff_t buff;
|
fm_buff_t buff;
|
||||||
buff.clear();
|
buff.clear();
|
||||||
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff,EFmCreateFault,
|
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff, EFmCreateFault,
|
||||||
alarm,sizeof(*alarm));
|
alarm,sizeof(*alarm));
|
||||||
if (erc!=FM_ERR_OK) return erc;
|
if (erc!=FM_ERR_OK) return erc;
|
||||||
|
|
||||||
if(m_client.write_packet(buff)) {
|
if (m_client.write_packet(buff)) {
|
||||||
if(!m_client.read_packet(buff)) {
|
if (!m_client.read_packet(buff)) {
|
||||||
m_connected = false;
|
m_connected = false;
|
||||||
return FM_ERR_NOCONNECT;
|
return FM_ERR_NOCONNECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE_SERVER_RC(ptr_to_hdr(buff));
|
HANDLE_SERVER_RC(ptr_to_hdr(buff));
|
||||||
CHECK_RESPONSE(ptr_to_hdr(buff),fm_uuid_t);
|
CHECK_RESPONSE(ptr_to_hdr(buff),fm_uuid_t);
|
||||||
if (uuid != NULL)
|
if (uuid != NULL)
|
||||||
memcpy(*uuid,ptr_to_data(buff),sizeof(*uuid)-1);
|
memcpy(*uuid,ptr_to_data(buff),sizeof(*uuid)-1);
|
||||||
} else {
|
} else {
|
||||||
m_connected = false;
|
m_connected = false;
|
||||||
return FM_ERR_NOCONNECT;
|
return FM_ERR_NOCONNECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FM_ERR_OK;
|
return FM_ERR_OK;
|
||||||
}
|
|
||||||
|
|
||||||
EFmErrorT fm_clear_fault(AlarmFilter *filter){
|
|
||||||
|
|
||||||
CFmMutexGuard m(getAPIMutex());
|
|
||||||
if (!fm_lib_reconnect()) return FM_ERR_NOCONNECT;
|
|
||||||
|
|
||||||
fm_buff_t buff;
|
|
||||||
buff.clear();
|
|
||||||
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff,EFmDeleteFault,
|
|
||||||
filter,sizeof(*filter));
|
|
||||||
if (erc!=FM_ERR_OK) return erc;
|
|
||||||
|
|
||||||
if(m_client.write_packet(buff)) {
|
|
||||||
if(!m_client.read_packet(buff)) {
|
|
||||||
m_connected = false;
|
|
||||||
return FM_ERR_NOCONNECT;
|
|
||||||
}
|
|
||||||
HANDLE_SERVER_RC(ptr_to_hdr(buff));
|
|
||||||
} else {
|
|
||||||
m_connected = false;
|
|
||||||
return FM_ERR_NOCONNECT;
|
|
||||||
}
|
|
||||||
return FM_ERR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
EFmErrorT fm_clear_all(fm_ent_inst_t *inst_id){
|
|
||||||
|
|
||||||
CFmMutexGuard m(getAPIMutex());
|
|
||||||
if (!fm_lib_reconnect()) return FM_ERR_NOCONNECT;
|
|
||||||
|
|
||||||
fm_buff_t buff;
|
|
||||||
buff.clear();
|
|
||||||
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff,EFmDeleteFaults,
|
|
||||||
(*inst_id), sizeof(*inst_id));
|
|
||||||
if (erc!=FM_ERR_OK) return erc;
|
|
||||||
|
|
||||||
if(m_client.write_packet(buff)) {
|
|
||||||
if(!m_client.read_packet(buff)) {
|
|
||||||
m_connected = false;
|
|
||||||
FM_ERROR_LOG("Read ERR: return FM_ERR_NOCONNECT");
|
|
||||||
return FM_ERR_NOCONNECT;
|
|
||||||
}
|
|
||||||
HANDLE_SERVER_RC(ptr_to_hdr(buff));
|
|
||||||
} else {
|
|
||||||
m_connected = false;
|
|
||||||
FM_ERROR_LOG("Write ERR: return FM_ERR_NOCONNECT");
|
|
||||||
return FM_ERR_NOCONNECT;
|
|
||||||
}
|
|
||||||
return FM_ERR_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EFmErrorT fm_get_fault(AlarmFilter *filter, SFmAlarmDataT *alarm ){
|
EFmErrorT fm_clear_fault(AlarmFilter *filter) {
|
||||||
|
|
||||||
CFmMutexGuard m(getAPIMutex());
|
CFmMutexGuard m(getAPIMutex());
|
||||||
if (!fm_lib_reconnect()) return FM_ERR_NOCONNECT;
|
if (!fm_lib_reconnect()) return FM_ERR_NOCONNECT;
|
||||||
fm_check_thread_pending_request();
|
|
||||||
|
|
||||||
fm_buff_t buff;
|
fm_buff_t buff;
|
||||||
buff.clear();
|
buff.clear();
|
||||||
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff,EFmGetFault,
|
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff, EFmDeleteFault,
|
||||||
filter,sizeof(*filter));
|
filter, sizeof(*filter));
|
||||||
if (erc!=FM_ERR_OK) return erc;
|
if (erc!=FM_ERR_OK) return erc;
|
||||||
|
|
||||||
if(m_client.write_packet(buff)) {
|
if (m_client.write_packet(buff)) {
|
||||||
if(!m_client.read_packet(buff)) {
|
if (!m_client.read_packet(buff)) {
|
||||||
m_connected = false;
|
m_connected = false;
|
||||||
return FM_ERR_NOCONNECT;
|
return FM_ERR_NOCONNECT;
|
||||||
}
|
}
|
||||||
HANDLE_SERVER_RC(ptr_to_hdr(buff));
|
HANDLE_SERVER_RC(ptr_to_hdr(buff));
|
||||||
CHECK_RESPONSE(ptr_to_hdr(buff),SFmAlarmDataT);
|
} else {
|
||||||
SFmAlarmDataT * data = (SFmAlarmDataT * ) ptr_to_data(buff);
|
m_connected = false;
|
||||||
*alarm = *data;
|
return FM_ERR_NOCONNECT;
|
||||||
} else {
|
}
|
||||||
m_connected = false;
|
return FM_ERR_OK;
|
||||||
return FM_ERR_NOCONNECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FM_ERR_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
EFmErrorT fm_clear_all(fm_ent_inst_t *inst_id) {
|
||||||
|
|
||||||
|
CFmMutexGuard m(getAPIMutex());
|
||||||
|
if (!fm_lib_reconnect()) return FM_ERR_NOCONNECT;
|
||||||
|
|
||||||
|
fm_buff_t buff;
|
||||||
|
buff.clear();
|
||||||
|
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff, EFmDeleteFaults,
|
||||||
|
(*inst_id), sizeof(*inst_id));
|
||||||
|
if (erc!=FM_ERR_OK) return erc;
|
||||||
|
|
||||||
|
if (m_client.write_packet(buff)) {
|
||||||
|
if (!m_client.read_packet(buff)) {
|
||||||
|
m_connected = false;
|
||||||
|
FM_ERROR_LOG("Read ERR: return FM_ERR_NOCONNECT");
|
||||||
|
return FM_ERR_NOCONNECT;
|
||||||
|
}
|
||||||
|
HANDLE_SERVER_RC(ptr_to_hdr(buff));
|
||||||
|
} else {
|
||||||
|
m_connected = false;
|
||||||
|
FM_ERROR_LOG("Write ERR: return FM_ERR_NOCONNECT");
|
||||||
|
return FM_ERR_NOCONNECT;
|
||||||
|
}
|
||||||
|
return FM_ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
EFmErrorT fm_get_fault(AlarmFilter *filter, SFmAlarmDataT *alarm ) {
|
||||||
|
|
||||||
|
CFmMutexGuard m(getAPIMutex());
|
||||||
|
if (!fm_lib_reconnect()) return FM_ERR_NOCONNECT;
|
||||||
|
fm_check_thread_pending_request();
|
||||||
|
|
||||||
|
fm_buff_t buff;
|
||||||
|
buff.clear();
|
||||||
|
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff, EFmGetFault,
|
||||||
|
filter,sizeof(*filter));
|
||||||
|
if (erc!=FM_ERR_OK) return erc;
|
||||||
|
|
||||||
|
if (m_client.write_packet(buff)) {
|
||||||
|
if (!m_client.read_packet(buff)) {
|
||||||
|
m_connected = false;
|
||||||
|
return FM_ERR_NOCONNECT;
|
||||||
|
}
|
||||||
|
HANDLE_SERVER_RC(ptr_to_hdr(buff));
|
||||||
|
CHECK_RESPONSE(ptr_to_hdr(buff),SFmAlarmDataT);
|
||||||
|
SFmAlarmDataT * data = (SFmAlarmDataT * ) ptr_to_data(buff);
|
||||||
|
*alarm = *data;
|
||||||
|
} else {
|
||||||
|
m_connected = false;
|
||||||
|
return FM_ERR_NOCONNECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FM_ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
EFmErrorT fm_get_faults(fm_ent_inst_t *inst_id,
|
EFmErrorT fm_get_faults(fm_ent_inst_t *inst_id,
|
||||||
SFmAlarmDataT *alarm, unsigned int *max_alarms_to_get) {
|
SFmAlarmDataT *alarm,
|
||||||
|
unsigned int *max_alarms_to_get) {
|
||||||
|
|
||||||
CFmMutexGuard m(getAPIMutex());
|
CFmMutexGuard m(getAPIMutex());
|
||||||
if (!fm_lib_reconnect()) return FM_ERR_NOCONNECT;
|
if (!fm_lib_reconnect()) return FM_ERR_NOCONNECT;
|
||||||
fm_check_thread_pending_request();
|
fm_check_thread_pending_request();
|
||||||
|
|
||||||
fm_buff_t buff;
|
fm_buff_t buff;
|
||||||
buff.clear();
|
buff.clear();
|
||||||
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff,EFmGetFaults,
|
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff, EFmGetFaults,
|
||||||
(*inst_id),sizeof(*inst_id));
|
(*inst_id),sizeof(*inst_id));
|
||||||
if (erc!=FM_ERR_OK) return erc;
|
if (erc!=FM_ERR_OK) return erc;
|
||||||
|
|
||||||
if(m_client.write_packet(buff)) {
|
if (m_client.write_packet(buff)) {
|
||||||
if(!m_client.read_packet(buff)) {
|
if(!m_client.read_packet(buff)) {
|
||||||
m_connected = false;
|
m_connected = false;
|
||||||
return FM_ERR_NOCONNECT;
|
return FM_ERR_NOCONNECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ptr_to_hdr(buff)->msg_rc != FM_ERR_OK){
|
if (ptr_to_hdr(buff)->msg_rc != FM_ERR_OK) {
|
||||||
*max_alarms_to_get = 0;
|
*max_alarms_to_get = 0;
|
||||||
EFmErrorT rc = (EFmErrorT)ptr_to_hdr(buff)->msg_rc;
|
EFmErrorT rc = (EFmErrorT)ptr_to_hdr(buff)->msg_rc;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t pkt_size = ptr_to_hdr(buff)->msg_size;
|
|
||||||
if (pkt_size < sizeof(uint32_t)) {
|
|
||||||
FM_ERROR_LOG("Received invalid pkt size: %u\n",pkt_size );
|
|
||||||
m_connected = false;
|
|
||||||
return FM_ERR_COMMUNICATIONS;
|
|
||||||
}
|
|
||||||
pkt_size-=sizeof(uint32_t);
|
|
||||||
|
|
||||||
char *dptr = (char*)ptr_to_data(buff);
|
uint32_t pkt_size = ptr_to_hdr(buff)->msg_size;
|
||||||
|
if (pkt_size < sizeof(uint32_t)) {
|
||||||
|
FM_ERROR_LOG("Received invalid pkt size: %u\n",pkt_size );
|
||||||
|
m_connected = false;
|
||||||
|
return FM_ERR_COMMUNICATIONS;
|
||||||
|
}
|
||||||
|
pkt_size-=sizeof(uint32_t);
|
||||||
|
|
||||||
uint32_t *len = (uint32_t*)dptr;
|
char *dptr = (char*)ptr_to_data(buff);
|
||||||
dptr+=sizeof(uint32_t);
|
|
||||||
if (*max_alarms_to_get < *len) {
|
|
||||||
return FM_ERR_NOT_ENOUGH_SPACE;
|
|
||||||
}
|
|
||||||
if (pkt_size < (*len*sizeof(SFmAlarmDataT)) ) {
|
|
||||||
return FM_ERR_COMMUNICATIONS;
|
|
||||||
}
|
|
||||||
*max_alarms_to_get = *len;
|
|
||||||
memcpy(alarm,dptr,pkt_size);
|
|
||||||
} else {
|
|
||||||
m_connected = false;
|
|
||||||
return FM_ERR_NOCONNECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FM_ERR_OK;
|
uint32_t *len = (uint32_t*)dptr;
|
||||||
|
dptr+=sizeof(uint32_t);
|
||||||
|
if (*max_alarms_to_get < *len) {
|
||||||
|
return FM_ERR_NOT_ENOUGH_SPACE;
|
||||||
|
}
|
||||||
|
if (pkt_size < (*len*sizeof(SFmAlarmDataT))) {
|
||||||
|
return FM_ERR_COMMUNICATIONS;
|
||||||
|
}
|
||||||
|
*max_alarms_to_get = *len;
|
||||||
|
memcpy(alarm,dptr,pkt_size);
|
||||||
|
} else {
|
||||||
|
m_connected = false;
|
||||||
|
return FM_ERR_NOCONNECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FM_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
EFmErrorT fm_get_faults_by_id(fm_alarm_id *alarm_id, SFmAlarmDataT *alarm,
|
|
||||||
unsigned int *max_alarms_to_get){
|
|
||||||
|
|
||||||
CFmMutexGuard m(getAPIMutex());
|
EFmErrorT fm_get_faults_by_id(fm_alarm_id *alarm_id,
|
||||||
if (!fm_lib_reconnect()) return FM_ERR_NOCONNECT;
|
SFmAlarmDataT *alarm,
|
||||||
fm_check_thread_pending_request();
|
unsigned int *max_alarms_to_get) {
|
||||||
|
|
||||||
fm_buff_t buff;
|
CFmMutexGuard m(getAPIMutex());
|
||||||
buff.clear();
|
if (!fm_lib_reconnect()) return FM_ERR_NOCONNECT;
|
||||||
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff,EFmGetFaultsById,
|
fm_check_thread_pending_request();
|
||||||
(*alarm_id),sizeof(*alarm_id));
|
|
||||||
if (erc!=FM_ERR_OK) return erc;
|
|
||||||
|
|
||||||
if(m_client.write_packet(buff)) {
|
fm_buff_t buff;
|
||||||
if(!m_client.read_packet(buff)) {
|
buff.clear();
|
||||||
m_connected = false;
|
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff, EFmGetFaultsById,
|
||||||
return FM_ERR_NOCONNECT;
|
(*alarm_id), sizeof(*alarm_id));
|
||||||
}
|
if (erc!=FM_ERR_OK) return erc;
|
||||||
|
|
||||||
if (ptr_to_hdr(buff)->msg_rc != FM_ERR_OK){
|
if (m_client.write_packet(buff)) {
|
||||||
*max_alarms_to_get = 0;
|
if (!m_client.read_packet(buff)) {
|
||||||
EFmErrorT rc = (EFmErrorT)ptr_to_hdr(buff)->msg_rc;
|
m_connected = false;
|
||||||
return rc;
|
return FM_ERR_NOCONNECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t pkt_size = ptr_to_hdr(buff)->msg_size;
|
if (ptr_to_hdr(buff)->msg_rc != FM_ERR_OK){
|
||||||
if (pkt_size < sizeof(uint32_t)) {
|
*max_alarms_to_get = 0;
|
||||||
FM_ERROR_LOG("Received invalid pkt size: %u\n",pkt_size );
|
EFmErrorT rc = (EFmErrorT)ptr_to_hdr(buff)->msg_rc;
|
||||||
m_connected = false;
|
return rc;
|
||||||
return FM_ERR_COMMUNICATIONS;
|
}
|
||||||
}
|
|
||||||
pkt_size-=sizeof(uint32_t);
|
|
||||||
|
|
||||||
char *dptr = (char*)ptr_to_data(buff);
|
uint32_t pkt_size = ptr_to_hdr(buff)->msg_size;
|
||||||
|
if (pkt_size < sizeof(uint32_t)) {
|
||||||
|
FM_ERROR_LOG("Received invalid pkt size: %u\n",pkt_size );
|
||||||
|
m_connected = false;
|
||||||
|
return FM_ERR_COMMUNICATIONS;
|
||||||
|
}
|
||||||
|
pkt_size-=sizeof(uint32_t);
|
||||||
|
|
||||||
uint32_t *len = (uint32_t*)dptr;
|
char *dptr = (char*)ptr_to_data(buff);
|
||||||
dptr+=sizeof(uint32_t);
|
|
||||||
if (*max_alarms_to_get < *len) {
|
|
||||||
return FM_ERR_NOT_ENOUGH_SPACE;
|
|
||||||
}
|
|
||||||
if (pkt_size < (*len*sizeof(SFmAlarmDataT)) ) {
|
|
||||||
return FM_ERR_COMMUNICATIONS;
|
|
||||||
}
|
|
||||||
*max_alarms_to_get = *len;
|
|
||||||
memcpy(alarm,dptr,pkt_size);
|
|
||||||
} else {
|
|
||||||
m_connected = false;
|
|
||||||
return FM_ERR_NOCONNECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FM_ERR_OK;
|
uint32_t *len = (uint32_t*)dptr;
|
||||||
|
dptr+=sizeof(uint32_t);
|
||||||
|
if (*max_alarms_to_get < *len) {
|
||||||
|
return FM_ERR_NOT_ENOUGH_SPACE;
|
||||||
|
}
|
||||||
|
if (pkt_size < (*len*sizeof(SFmAlarmDataT)) ) {
|
||||||
|
return FM_ERR_COMMUNICATIONS;
|
||||||
|
}
|
||||||
|
*max_alarms_to_get = *len;
|
||||||
|
memcpy(alarm,dptr,pkt_size);
|
||||||
|
} else {
|
||||||
|
m_connected = false;
|
||||||
|
return FM_ERR_NOCONNECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FM_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* APIs that enqueue the request and return ok for acknowledgment.
|
* APIs that enqueue the request and return ok for acknowledgment.
|
||||||
* A backgroup thread will pick up the request and send it to the FM Manager
|
* A backgroup thread will pick up the request and send it to the FM Manager
|
||||||
*/
|
*/
|
||||||
EFmErrorT fm_set_fault_async(const SFmAlarmDataT *alarm, fm_uuid_t *uuid){
|
EFmErrorT fm_set_fault_async(const SFmAlarmDataT *alarm, fm_uuid_t *uuid) {
|
||||||
|
|
||||||
if ( !fm_lib_thread()) return FM_ERR_RESOURCE_UNAVAILABLE;
|
if ( !fm_lib_thread()) return FM_ERR_RESOURCE_UNAVAILABLE;
|
||||||
CHECK_LIST_FULL(GetListOfFmRequests());
|
CHECK_LIST_FULL(GetListOfFmRequests());
|
||||||
|
|
||||||
fm_uuid_t id;
|
fm_uuid_t id;
|
||||||
fm_buff_t buff;
|
fm_buff_t buff;
|
||||||
buff.clear();
|
buff.clear();
|
||||||
fm_uuid_create(id);
|
fm_uuid_create(id);
|
||||||
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff,EFmCreateFault,
|
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff, EFmCreateFault,
|
||||||
alarm,sizeof(*alarm));
|
alarm, sizeof(*alarm));
|
||||||
if (erc!=FM_ERR_OK) return erc;
|
if (erc != FM_ERR_OK) return erc;
|
||||||
memcpy(ptr_to_data(buff), id, sizeof(fm_uuid_t)-1);
|
memcpy(ptr_to_data(buff), id, sizeof(fm_uuid_t)-1);
|
||||||
|
|
||||||
FM_INFO_LOG("Enqueue raise alarm request: UUID (%s) alarm id (%s) instant id (%s)",
|
FM_INFO_LOG("Enqueue raise alarm request: UUID (%s) alarm id (%s) instant id (%s)",
|
||||||
id, alarm->alarm_id, alarm->entity_instance_id);
|
id, alarm->alarm_id, alarm->entity_instance_id);
|
||||||
enqueue(buff);
|
enqueue(buff);
|
||||||
|
|
||||||
if (uuid != NULL){
|
if (uuid != NULL) {
|
||||||
memcpy(*uuid,id,sizeof(*uuid)-1);
|
memcpy(*uuid,id,sizeof(*uuid)-1);
|
||||||
}
|
}
|
||||||
return FM_ERR_OK;
|
return FM_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
EFmErrorT fm_clear_fault_async(AlarmFilter *filter){
|
|
||||||
|
|
||||||
if ( !fm_lib_thread()) return FM_ERR_RESOURCE_UNAVAILABLE;
|
EFmErrorT fm_clear_fault_async(AlarmFilter *filter) {
|
||||||
CHECK_LIST_FULL(GetListOfFmRequests());
|
|
||||||
|
|
||||||
fm_buff_t buff;
|
if ( !fm_lib_thread()) return FM_ERR_RESOURCE_UNAVAILABLE;
|
||||||
buff.clear();
|
CHECK_LIST_FULL(GetListOfFmRequests());
|
||||||
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff,EFmDeleteFault,
|
|
||||||
filter,sizeof(*filter));
|
|
||||||
if (erc!=FM_ERR_OK) return erc;
|
|
||||||
|
|
||||||
FM_INFO_LOG("Enqueue clear alarm request: alarm id (%s), instant id (%s)",
|
fm_buff_t buff;
|
||||||
filter->alarm_id, filter->entity_instance_id);
|
buff.clear();
|
||||||
enqueue(buff);
|
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff, EFmDeleteFault,
|
||||||
|
filter, sizeof(*filter));
|
||||||
|
if (erc!=FM_ERR_OK) return erc;
|
||||||
|
|
||||||
return FM_ERR_OK;
|
FM_INFO_LOG("Enqueue clear alarm request: alarm id (%s), instant id (%s)",
|
||||||
|
filter->alarm_id, filter->entity_instance_id);
|
||||||
|
enqueue(buff);
|
||||||
|
|
||||||
|
return FM_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
EFmErrorT fm_clear_all_async(fm_ent_inst_t *inst_id){
|
|
||||||
|
|
||||||
if ( !fm_lib_thread()) return FM_ERR_RESOURCE_UNAVAILABLE;
|
EFmErrorT fm_clear_all_async(fm_ent_inst_t *inst_id) {
|
||||||
CHECK_LIST_FULL(GetListOfFmRequests());
|
|
||||||
|
|
||||||
fm_buff_t buff;
|
if ( !fm_lib_thread()) return FM_ERR_RESOURCE_UNAVAILABLE;
|
||||||
buff.clear();
|
CHECK_LIST_FULL(GetListOfFmRequests());
|
||||||
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff,EFmDeleteFaults,
|
|
||||||
(*inst_id), sizeof(*inst_id));
|
|
||||||
if (erc!=FM_ERR_OK) return erc;
|
|
||||||
|
|
||||||
FM_INFO_LOG("Enqueue clear all alarm request: instant id (%s)", *inst_id);
|
fm_buff_t buff;
|
||||||
enqueue(buff);
|
buff.clear();
|
||||||
return FM_ERR_OK;
|
EFmErrorT erc = fm_msg_utils_prep_requet_msg(buff, EFmDeleteFaults,
|
||||||
|
(*inst_id), sizeof(*inst_id));
|
||||||
|
if (erc!=FM_ERR_OK) return erc;
|
||||||
|
|
||||||
|
FM_INFO_LOG("Enqueue clear all alarm request: instant id (%s)", *inst_id);
|
||||||
|
enqueue(buff);
|
||||||
|
return FM_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -183,10 +183,13 @@ typedef enum{
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char alarm_id[FM_MAX_BUFFER_LENGTH];
|
char alarm_id[FM_MAX_BUFFER_LENGTH];
|
||||||
fm_ent_inst_t entity_instance_id;
|
fm_ent_inst_t entity_instance_id;
|
||||||
}AlarmFilter ;
|
}AlarmFilter;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* APIs to create, clear and query alarms.
|
||||||
|
*/
|
||||||
EFmErrorT fm_set_fault(const SFmAlarmDataT *alarm, fm_uuid_t *uuid);
|
EFmErrorT fm_set_fault(const SFmAlarmDataT *alarm, fm_uuid_t *uuid);
|
||||||
|
|
||||||
EFmErrorT fm_clear_fault(AlarmFilter *filter);
|
EFmErrorT fm_clear_fault(AlarmFilter *filter);
|
||||||
@ -196,10 +199,10 @@ EFmErrorT fm_clear_all(fm_ent_inst_t *inst_id);
|
|||||||
EFmErrorT fm_get_fault(AlarmFilter *filter, SFmAlarmDataT *alarm);
|
EFmErrorT fm_get_fault(AlarmFilter *filter, SFmAlarmDataT *alarm);
|
||||||
|
|
||||||
EFmErrorT fm_get_faults(fm_ent_inst_t *inst_id, SFmAlarmDataT *alarm,
|
EFmErrorT fm_get_faults(fm_ent_inst_t *inst_id, SFmAlarmDataT *alarm,
|
||||||
unsigned int *max_alarms_to_get);
|
unsigned int *max_alarms_to_get);
|
||||||
|
|
||||||
EFmErrorT fm_get_faults_by_id(fm_alarm_id *alarm_id, SFmAlarmDataT *alarm,
|
EFmErrorT fm_get_faults_by_id(fm_alarm_id *alarm_id, SFmAlarmDataT *alarm,
|
||||||
unsigned int *max_alarms_to_get);
|
unsigned int *max_alarms_to_get);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user