manager(parentManager),
63messageFile(messageFilename), lockFile(
string(messageFilename) +
".lock"),
64responder(responderObject), readOnly(isReadOnly), lastKnownSize(0)
66 TRACEMSG(
"monitoring message file "<< messageFilename);
74 TRACEMSG(
"FileMessenger: lock file established: "<< lockFile.
GetPath());
78 TRACEMSG(
"FileMessenger: unable to establish a lock for new PID - old PID is still running\n"<< pidge.ReportThis());
80 TRACEMSG(
"FileMessenger: write to PID-guarded file failed\n"<< pidge.ReportThis());
82 TRACEMSG(
"FileMessenger: unknown Toolkit PID-guard failure\n"<< pidge.ReportAll());
89 TRACEMSG(
"FileMessenger: unknown exception while creating lock");
108 for(
a=c->second.begin(), ae=c->second.end();
a!=ae; ++
a) {
109 if(
r->second.find(
a->first) ==
r->second.end())
112 if(
a!= ae)
break;
114 if(c == ce) okay =
true;
116 if(!okay)
WARNINGMSG(
"FileMessenger: did not receive a reply to all commands sent!");
121 if(lockStream.get() ==
NULL) {
127}
while(lockStream.get() ==
NULL&& nTries <= 30);
129 if(lockStream.get() !=
NULL) {
133 ERRORMSG(
"Timeout occurred when attempting to flush pending commands to file");
146 for(
a=c->second.begin(), ae=c->second.end();
a!=ae; ++
a) {
147 if(
r->second.find(
a->first) ==
r->second.end())
150 if(
a!= ae)
break;
152 if(c == ce) okay =
true;
154 if(!okay)
ERRORMSG(
"FileMessenger: did not send a reply to all commands received!");
162<<
" received but not written to read-only message file");
168 if(c !=
commandsSent.
end() && c->second.find(targetApp) != c->second.end()) {
169 ERRORMSG(
"Already sent command "<<
id<<
" to "<< targetApp <<
'!');
188 ERRORMSG(
"Can't reply; have not received command "<<
id<<
" from "<< targetApp <<
'!');
192 if(
r!=
repliesSent.
end() &&
r->second.find(targetApp) !=
r->second.end()) {
193 ERRORMSG(
"Already sent reply "<<
id<<
" to "<< targetApp <<
'!');
199 TRACEMSG(
"reply "<<
id<<
" to "<< targetApp
200<<
" logged but not written to read-only message file");
212 ERRORMSG(
"Unknown reply status "<< status <<
'!');
228 if(messageFileSize < 0) {
229 ERRORMSG(
"Couldn't get message file size!");
241 if(needToRead)
TRACEMSG(
"message file has grown since last read");
246 if(lockStream.get() ==
NULL)
259 ERRORMSG(
"Couldn't get message file size!");
288 TRACEMSG(
"receiving commands...");
293 ERRORMSG(
"cannot open message file for reading!");
297 #define GET_EXPECTED_LINE \ 298 if (!ReadSingleLine(*inStream, &line)) { \ 299 ERRORMSG("unexpected EOF!"); \
303 #define SKIP_THROUGH_END_OF_COMMAND \ 305 if (!ReadSingleLine(*inStream, &line)) { \ 306 ERRORMSG("no end-of-command marker found before EOF!"); \
309if (line == COMMAND_END) break; \
312 #define GET_ITEM(ident) \ 313 item = string(ident); \ 314 if (line.substr(0, item.size()) != item) { \ 315 ERRORMSG("Line does not begin with expected '"<< item << "'!"); \
318item = line.substr(item.size());
320 stringline, item, from;
344 command.id = strtoul(item.c_str(), &endptr, 10);
345 if(endptr == item.c_str()) {
352 if(line.substr(0, 9) !=
"Command: "&& line.substr(0, 7) !=
"Reply: ") {
353 ERRORMSG(
"Line does not begin with expected 'Command: ' or 'Reply: '!");
356 boolisCommand = (line.substr(0, 9) ==
"Command: ");
357 command.command = line.substr(isCommand ? 9 : 7);
392 if(
command.command ==
"OKAY")
394 else if(
command.command !=
"ERROR")
415 ERRORMSG(
"cannot open message file for writing!");
422 boolisReply = (c->command ==
"OKAY"|| c->command ==
"ERROR");
424<<
"To: "<< c->to <<
'\n' 426<<
"ID: "<< c->id <<
'\n' 427<< (isReply ?
"Reply: ":
"Command: ") << c->command <<
'\n';
428 if(c->data.size() > 0) {
429*outStream << c->data;
430 if(c->data[c->data.size() - 1] !=
'\n')
435 TRACEMSG(
"sent "<< (isReply ?
"reply ":
"command ") << c->id <<
" to "<< c->to);
442applicationName(appName)
448FileMessengerList::iterator m, me =
messengers.end();
456 if(!responderObject) {
457 ERRORMSG(
"CreateNewFileMessenger() - got NULL responderObject!");
467FileMessengerList::iterator
f, fe =
messengers.end();
475 ERRORMSG(
"DeleteFileMessenger() - given FileMessenger* not created by this FileMessagingManager!");
480FileMessengerList::iterator
f, fe =
messengers.end();
482(*f)->PollMessageFile();
492osa->SetUseIndentation(
false);
503identifier = identifier.substr(endb + 2);
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
CPIDGuard â Process guard.
const string applicationName
void DeleteFileMessenger(FileMessenger *messenger)
friend class FileMessenger
~FileMessagingManager(void)
FileMessenger * CreateNewFileMessenger(const string &messageFilename, MessageResponder *responderObject, bool readOnly)
FileMessagingManager(const string &appName)
void PollMessageFiles(void)
FileMessengerList messengers
FileMessenger(FileMessagingManager *parentManager, const string &messageFilename, MessageResponder *responderObject, bool isReadOnly)
void SendReply(const string &targetApp, unsigned long id, MessageResponder::ReplyStatus status, const string &data)
CommandReplies repliesReceived
void ReceiveCommands(void)
void PollMessageFile(void)
void SendPendingCommands(void)
CommandReplies repliesSent
CommandOriginators commandsReceived
const FileMessagingManager *const manager
MessageResponder *const responder
CommandOriginators commandsSent
const CDirEntry messageFile
void SendCommand(const string &targetApp, unsigned long id, const string &command, const string &data)
CommandList pendingCommands
virtual void ReceivedCommand(const string &fromApp, unsigned long id, const string &command, const string &data)=0
virtual void ReceivedReply(const string &fromApp, unsigned long id, ReplyStatus status, const string &data)=0
container_type::const_iterator const_iterator
container_type::iterator iterator
const_iterator begin() const
const_iterator end() const
const_iterator find(const key_type &key) const
Include a standard set of the NCBI C++ Toolkit most basic headers.
std::ofstream out("events_result.xml")
main entry point for tests
#define GET_EXPECTED_LINE
#define SKIP_THROUGH_END_OF_COMMAND
bool IdentifierToSeqId(const string &identifier, CRef< ncbi::objects::CSeq_id > &seqID)
bool SeqIdToIdentifier(const CRef< ncbi::objects::CSeq_id > &seqID, string &identifier)
static const string COMMAND_END
static CPIDGuard * CreateLock(const CDirEntry &lockFile)
#define WARNINGMSG(stream)
static bool ReadSingleLine(CNcbiIfstream &inStream, string *str)
static const char * str(char *buf, int n)
@ eNoOwnership
No ownership is assumed.
virtual bool Exists(void) const
Check the entry existence.
Int8 GetLength(void) const
Get size of file.
bool IsFile(EFollowLinks follow=eFollowLinks) const
Check whether a directory entry is a file.
const string & GetPath(void) const
Get entry path.
void SetReferenceDTD(bool use_dtd=true)
Make generated XML document reference DTD.
static CObjectOStream * Open(ESerialDataFormat format, CNcbiOstream &outStream, bool deleteOutStream)
Create serial object writer and attach it to an output stream.
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
void Reset(void)
Reset reference object.
bool Empty(void) const THROWS_NONE
Check if CRef is empty â not pointing to any object, which means having a null value.
int64_t Int8
8-byte (64-bit) signed integer
@ eWrite
Unable to write into the PID file.
@ eStillRunning
The process listed in the file is still around.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
NCBI_NS_STD::string::size_type SIZE_TYPE
static SIZE_TYPE Find(const CTempString str, const CTempString pattern, ECase use_case=eCase, EDirection direction=eForwardSearch, SIZE_TYPE occurrence=0)
Find the pattern in the string.
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
if(yy_accept[yy_current_state])
static Messenger messenger
void SleepSec(unsigned long sec, EInterruptOnSignal onsignal=eRestartOnSignal)
Sleep.
Defines NCBI C++ diagnostic APIs, classes, and macros.
std::istream & in(std::istream &in_, double &x_)
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4