📄 stafnotificationlist.cpp
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF) *//* (C) Copyright IBM Corp. 2001 *//* *//* This software is licensed under the Common Public License (CPL) V1.0. *//*****************************************************************************/#include "STAF.h"#include "STAFNotificationList.h"#include "STAFProc.h"#include "STAFTrace.h"STAFNotificationList::STAFNotificationList(){ /* Do Nothing */}STAFNotificationList::~STAFNotificationList(){ /* Do Nothing */}STAFRC_t STAFNotificationList::reg(const STAFString &machine, const STAFHandle_t handle, unsigned int priority){ unsigned int foundIt = 0; STAFMutexSemLock semLock(fNotifieeListSem); NotifieeList::iterator listIter; for(listIter = fNotifieeList.begin(); !foundIt && (listIter != fNotifieeList.end());) { Notifiee notifiee(*listIter); if ((notifiee.nameOrHandle == Notifiee::kHandle) && (notifiee.machine == machine) && (notifiee.handle == handle) && (notifiee.priority == priority)) { foundIt = 1; } else { ++listIter; } } if (!foundIt) fNotifieeList.push_back(Notifiee(machine, handle, priority)); return kSTAFOk;}STAFRC_t STAFNotificationList::reg(const STAFString &machine, const STAFString &process, unsigned int priority){ unsigned int foundIt = 0; STAFMutexSemLock semLock(fNotifieeListSem); NotifieeList::iterator listIter; for(listIter = fNotifieeList.begin(); !foundIt && (listIter != fNotifieeList.end());) { Notifiee notifiee(*listIter); if ((notifiee.nameOrHandle == Notifiee::kName) && (notifiee.machine == machine) && (notifiee.process == process) && (notifiee.priority == priority)) { foundIt = 1; } else { ++listIter; } } if (!foundIt) fNotifieeList.push_back(Notifiee(machine, process, priority)); return kSTAFOk;}STAFRC_t STAFNotificationList::unregister(const STAFString &machine, const STAFHandle_t handle, unsigned int priority){ unsigned int foundIt = 0; STAFRC_t rc = kSTAFOk; STAFMutexSemLock semLock(fNotifieeListSem); NotifieeList::iterator listIter; for(listIter = fNotifieeList.begin(); !foundIt && (listIter != fNotifieeList.end());) { Notifiee notifiee(*listIter); if ((notifiee.nameOrHandle == Notifiee::kHandle) && (notifiee.machine == machine) && (notifiee.handle == handle) && (notifiee.priority == priority)) { foundIt = 1; } else { ++listIter; } } if (foundIt) fNotifieeList.erase(listIter); else rc = kSTAFNotifieeDoesNotExist; return rc;}STAFRC_t STAFNotificationList::unregister(const STAFString &machine, const STAFString &process, unsigned int priority){ unsigned int foundIt = 0; STAFRC_t rc = kSTAFOk; STAFMutexSemLock semLock(fNotifieeListSem); NotifieeList::iterator listIter; for(listIter = fNotifieeList.begin(); !foundIt && (listIter != fNotifieeList.end());) { Notifiee notifiee(*listIter); if ((notifiee.nameOrHandle == Notifiee::kName) && (notifiee.machine == machine) && (notifiee.process == process) && (notifiee.priority == priority)) { foundIt = 1; } else { ++listIter; } } if (foundIt) fNotifieeList.erase(listIter); else rc = kSTAFNotifieeDoesNotExist; return rc;}STAFRC_t STAFNotificationList::sendNotificationToHandle( const STAFString &where, const STAFHandle_t handle, unsigned int priority, const STAFString &type, const STAFString &message){ STAFString request("QUEUE HANDLE " + STAFString(handle) + " PRIORITY " + STAFString(priority)); if (type.length() != 0) { request += " TYPE :" + STAFString(type.length(STAFString::kChar)) + ":" + type; } request += " MESSAGE :" + STAFString(message.length(STAFString::kChar)) + ":" + message; STAFResultPtr result = gSTAFProcHandlePtr->submit(where, "QUEUE", request); if (result->rc != kSTAFOk) { // XXX: Should a warning be logged for any error or just RC 7? // Regenerate the request with the MESSAGE option's value unmarshalled // XXX: If add support to the tracing infrastructure to support // handling "nested" marshalled data, then should remove here STAFString unmarshalledRequest("QUEUE HANDLE " + STAFString(handle) + " PRIORITY " + STAFString(priority)); if (type.length() != 0) { unmarshalledRequest += " TYPE :" + STAFString(type.length(STAFString::kChar)) + ":" + type; } unmarshalledRequest += " MESSAGE :" + STAFString(message.length(STAFString::kChar)) + ":" + STAFObject::unmarshall(message)->asFormattedString(); STAFString errorBuffer = STAFString( "STAFNotificationList::sendNotification failed with " + STAFString("RC=") + result->rc + ", Result=" + result->result + ", where=" + where + ", service=QUEUE, request=" + unmarshalledRequest); STAFTrace::trace(kSTAFTraceWarning, errorBuffer); } return result->rc;}STAFRC_t STAFNotificationList::sendNotificationToName( const STAFString &where, const STAFString &name, unsigned int priority, const STAFString &type, const STAFString &message){ STAFString request("QUEUE NAME :" + STAFString(name.length(STAFString::kChar)) + ":" + name + " PRIORITY " + STAFString(priority)); if (type.length() != 0) { request += " TYPE :" + STAFString(type.length(STAFString::kChar)) + ":" + type; } request += " MESSAGE :" + STAFString(message.length(STAFString::kChar)) + ":" + message; STAFResultPtr result = gSTAFProcHandlePtr->submit(where, "QUEUE", request); if (result->rc != kSTAFOk) { // XXX: Should a warning be logged for any error or just RC 7? // Regenerate the request with the MESSAGE option's value unmarshalled // XXX: If add support to the tracing infrastructure to support // handling "nested" marshalled data, then should remove here STAFString unmarshalledRequest( "QUEUE NAME :" + STAFString(name.length(STAFString::kChar)) + ":" + name + " PRIORITY " + STAFString(priority)); if (type.length() != 0) { unmarshalledRequest += " TYPE :" + STAFString(type.length(STAFString::kChar)) + ":" + type; } unmarshalledRequest += " MESSAGE :" + STAFString(message.length(STAFString::kChar)) + ":" + STAFObject::unmarshall(message)->asFormattedString(); STAFString errorBuffer = STAFString( "STAFNotificationList::sendNotification failed with " + STAFString("RC=") + result->rc + ", Result=" + result->result + ", where=" + where + ", service=QUEUE, request=" + unmarshalledRequest); STAFTrace::trace(kSTAFTraceWarning, errorBuffer); } return result->rc;}unsigned int STAFNotificationList::sendNotification(const STAFString &type, const STAFString &message){ unsigned int numSent = 0; NotifieeList notifieeList; // Lock the list temporarily to get a copy { STAFMutexSemLock semLock(fNotifieeListSem); notifieeList = fNotifieeList; } NotifieeList::iterator listIter; for(listIter = notifieeList.begin(); listIter != notifieeList.end(); ++listIter) { Notifiee notifiee = *listIter; STAFRC_t rc = kSTAFOk; if (notifiee.nameOrHandle == Notifiee::kHandle) { rc = sendNotificationToHandle( notifiee.machine, notifiee.handle, notifiee.priority, type, message); } else { rc = sendNotificationToName( notifiee.machine, notifiee.process, notifiee.priority, type, message); } if (rc == kSTAFOk) ++numSent; } return numSent;}STAFNotificationList::NotifieeList STAFNotificationList::getNotifieeListCopy(){ STAFMutexSemLock semLock(fNotifieeListSem); return fNotifieeList;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -