Save Notification Service Topology to an XML file. More...
#include <XML_Saver.h>


Public Member Functions | |
| XML_Saver (bool timestamp=true) | |
| virtual | ~XML_Saver () |
| bool | open (const ACE_TString &file_name, size_t backup_count) |
| virtual bool | begin_object (CORBA::Long id, const ACE_CString &type, const NVPList &attrs, bool changed) |
| virtual void | end_object (CORBA::Long id, const ACE_CString &type) |
| virtual void | close (void) |
| Close the saver. | |
Private Member Functions | |
| void | backup_file_name (ACE_TCHAR *file_path, size_t nfile) |
Private Attributes | |
| FILE * | output_ |
| A stream representing our current output. | |
| bool | close_out_ |
| ACE_TString | base_name_ |
| the name of the output file | |
| size_t | backup_count_ |
| bool | timestamp_ |
| true to enable timestamping | |
| ACE_CString | indent_ |
| A string consisting of spaces that is our current indentation level. | |
Save Notification Service Topology to an XML file.
Definition at line 33 of file XML_Saver.h.
| TAO_Notify::XML_Saver::XML_Saver | ( | bool | timestamp = true |
) |
Construct an XML_Saver. Initialization is deferred to "open()"
Definition at line 11 of file XML_Saver.cpp.
{
extern const char TOPOLOGY_ID_NAME[];
XML_Saver::XML_Saver(bool timestamp)
| TAO_Notify::XML_Saver::~XML_Saver | ( | ) | [virtual] |
Definition at line 19 of file XML_Saver.cpp.
{
}
XML_Saver::~XML_Saver()
{
if (this->output_ != 0)
| void TAO_Notify::XML_Saver::backup_file_name | ( | ACE_TCHAR * | file_path, | |
| size_t | nfile | |||
| ) | [private] |
Definition at line 30 of file XML_Saver.cpp.
| bool TAO_Notify::XML_Saver::begin_object | ( | CORBA::Long | id, | |
| const ACE_CString & | type, | |||
| const NVPList & | attrs, | |||
| bool | changed | |||
| ) | [virtual] |
Definition at line 153 of file XML_Saver.cpp.
{
ACE_ASSERT(this->output_ != 0);
FILE * const out = this->output_;
ACE_OS::fprintf (out, "%s%s%s", indent_.c_str(), "<", type.c_str());
if (id != 0)
{
// not all ostreams know what to do with a CORBA::Long
long const lid = id;
ACE_OS::fprintf (out, " %s%s%ld%s", TOPOLOGY_ID_NAME, "=\"", lid, "\"");
}
ACE_TString::size_type const BUF_SIZE = 512;
ACE_TString tmp(BUF_SIZE);
for (size_t idx = 0; idx < attrs.size(); ++idx)
{
ACE_TString valuetmp (ACE_TEXT_CHAR_TO_TCHAR (attrs[idx].value.c_str()));
ACEXML_escape_string(valuetmp, tmp);
ACE_OS::fprintf (out, "%s%s%s%s%s"," ",
attrs[idx].name.c_str (),
| void TAO_Notify::XML_Saver::close | ( | void | ) | [virtual] |
Close the saver.
This is not pure virtual. The default implementation does nothing.
There should be a corresponding open, but the signature may vary based on the type of saver, so we can't include it in the interface.
Reimplemented from TAO_Notify::Topology_Saver.
Definition at line 38 of file XML_Saver.cpp.
{
if (this->close_out_ && this->output_ != 0)
{
this->end_object(0, "notification_service");
ACE_OS::fclose(this->output_);
this->output_ = 0;
// delete the oldest backup file (if it exists)
size_t nfile = this->backup_count_ - 1;
ACE_TCHAR old_path [MAXPATHLEN + 1];
backup_file_name (old_path, nfile);
ACE_OS::unlink (old_path);
while (nfile != 0)
{
ACE_TCHAR new_path [MAXPATHLEN + 1];
nfile -= 1;
backup_file_name (new_path, nfile);
// this may fail, we don't care
ACE_OS::rename (new_path, old_path);
ACE_OS::strcpy (old_path, new_path);
}
// old_path now contains the name of the backup file
ACE_TString xml_name = this->base_name_;
xml_name += ACE_TEXT(".xml");
ACE_OS::rename (xml_name.c_str (), old_path);
| void TAO_Notify::XML_Saver::end_object | ( | CORBA::Long | id, | |
| const ACE_CString & | type | |||
| ) | [virtual] |
Definition at line 185 of file XML_Saver.cpp.
{
ACE_ASSERT(this->output_ != 0);
FILE * const out = this->output_;
if (this->indent_.length() >= 2)
| bool TAO_Notify::XML_Saver::open | ( | const ACE_TString & | file_name, | |
| size_t | backup_count | |||
| ) |
Open the output file.
| file_name | the fully qualified file name |
Definition at line 76 of file XML_Saver.cpp.
{
this->base_name_ = base_name;
this->backup_count_ = backup_count;
if (base_name == ACE_TEXT("cout"))
{
this->output_ = stdout;
this->close_out_ = false;
}
else if (base_name == ACE_TEXT("cerr"))
{
this->output_ = stderr;
this->close_out_ = false;
}
else
{
ACE_TString file_name = base_name;
file_name += ACE_TEXT(".new");
this->output_ = ACE_OS::fopen (file_name.c_str(), ACE_TEXT("wb"));
if (this->output_) {
this->close_out_ = true;
} else {
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%P|%t) XML_Saver unable to open %s\n"),
base_name.c_str()));
}
}
if (this->output_ != 0)
{
FILE * const out = this->output_;
ACE_OS::fprintf (out, "<?xml version=\"1.0\"?>\n");
try
{
bool changed = true;
NVPList attrs;
ACE_Time_Value const now = ACE_High_Res_Timer::gettimeofday();
ACE_UINT64 nowus = now.usec();
static const ACE_UINT64 USECSPERSEC = 1000 * 1000;
ACE_UINT64 const tmpus = now.sec();
nowus += tmpus * USECSPERSEC;
ACE_TCHAR nowusstr[128];
#ifdef ACE_LACKS_LONGLONG_T
nowus.as_string(nowusstr);
#else
ACE_OS::sprintf(nowusstr, ACE_UINT64_FORMAT_SPECIFIER, nowus);
#endif /* ACE_LACKS_LONGLONG_T */
attrs.push_back(NVP("version", "1.0"));
if (this->timestamp_)
{
attrs.push_back(NVP("timestamp", ACE_TEXT_ALWAYS_CHAR(nowusstr)));
}
this->begin_object(0, "notification_service", attrs, changed);
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception (
ACE_TEXT (
"(%P|%t) XML_Saver Unknown exception\n"));
if (this->close_out_ && this->output_ != 0)
{
(void) ACE_OS::fclose (this->output_);
}
size_t TAO_Notify::XML_Saver::backup_count_ [private] |
Definition at line 70 of file XML_Saver.h.
ACE_TString TAO_Notify::XML_Saver::base_name_ [private] |
the name of the output file
Definition at line 69 of file XML_Saver.h.
bool TAO_Notify::XML_Saver::close_out_ [private] |
Definition at line 66 of file XML_Saver.h.
ACE_CString TAO_Notify::XML_Saver::indent_ [private] |
A string consisting of spaces that is our current indentation level.
Definition at line 76 of file XML_Saver.h.
FILE* TAO_Notify::XML_Saver::output_ [private] |
A stream representing our current output.
Definition at line 65 of file XML_Saver.h.
bool TAO_Notify::XML_Saver::timestamp_ [private] |
true to enable timestamping
Definition at line 73 of file XML_Saver.h.
1.7.0