summaryrefslogtreecommitdiff
path: root/cpp/src/slice2freeze/Main.cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2008-11-20 10:22:31 -0330
committerDwayne Boone <dwayne@zeroc.com>2008-11-20 10:22:31 -0330
commitaa4f3340e17e227a26659a75a8f60d24c2dd5323 (patch)
treec118d1d651d48f236c911d25f8a3f3b34320783f /cpp/src/slice2freeze/Main.cpp
parentBug 3550 - slice compiler not able to open tmp file on Vista (diff)
downloadice-aa4f3340e17e227a26659a75a8f60d24c2dd5323.tar.bz2
ice-aa4f3340e17e227a26659a75a8f60d24c2dd5323.tar.xz
ice-aa4f3340e17e227a26659a75a8f60d24c2dd5323.zip
Refactored CtrlCHandler usage in slice compilers
Diffstat (limited to 'cpp/src/slice2freeze/Main.cpp')
-rw-r--r--cpp/src/slice2freeze/Main.cpp110
1 files changed, 63 insertions, 47 deletions
diff --git a/cpp/src/slice2freeze/Main.cpp b/cpp/src/slice2freeze/Main.cpp
index 4b3072b066f..762f3338b5b 100644
--- a/cpp/src/slice2freeze/Main.cpp
+++ b/cpp/src/slice2freeze/Main.cpp
@@ -10,12 +10,12 @@
#include <IceUtil/DisableWarnings.h>
#include <IceUtil/Options.h>
#include <IceUtil/CtrlCHandler.h>
+#include <IceUtil/StaticMutex.h>
#include <Slice/Preprocessor.h>
#include <Slice/Util.h>
#include <Slice/CPlusPlusUtil.h>
#include <IceUtil/OutputUtil.h>
#include <IceUtil/StringUtil.h>
-#include <Slice/SignalHandler.h>
#include <cstring>
using namespace std;
@@ -23,16 +23,15 @@ using namespace IceUtil;
using namespace IceUtilInternal;
using namespace Slice;
-static ::IceUtilInternal::Output _H;
-static ::IceUtilInternal::Output _CPP;
+static IceUtil::StaticMutex _mutex = ICE_STATIC_MUTEX_INITIALIZER;
+static bool _interrupted = false;
-//
-// Callback for Crtl-C signal handling
-//
-static void closeCallback()
+void
+interruptedCallback(int signal)
{
- _H.close();
- _CPP.close();
+ IceUtil::StaticMutex::Lock lock(_mutex);
+
+ _interrupted = true;
}
static string ICE_ENCODING_COMPARE = "Freeze::IceEncodingCompare";
@@ -1794,7 +1793,7 @@ main(int argc, char* argv[])
int status = EXIT_SUCCESS;
IceUtil::CtrlCHandler ctrlCHandler;
- ctrlCHandler.setCallback(SignalHandler::removeFilesOnInterrupt);
+ ctrlCHandler.setCallback(interruptedCallback);
for(vector<string>::size_type idx = 1; idx < args.size(); ++idx)
{
@@ -1839,6 +1838,15 @@ main(int argc, char* argv[])
u->destroy();
return EXIT_FAILURE;
}
+
+ {
+ IceUtil::StaticMutex::Lock lock(_mutex);
+
+ if(_interrupted)
+ {
+ return EXIT_FAILURE;
+ }
+ }
}
if(status == EXIT_SUCCESS && !preprocess)
@@ -1853,29 +1861,27 @@ main(int argc, char* argv[])
}
}
- SignalHandler::setCloseCallback(closeCallback);
-
- SignalHandler::addFileForCleanup(fileH);
- _H.open(fileH.c_str());
- if(!_H)
+ IceUtilInternal::Output H;
+ H.open(fileH.c_str());
+ if(!H)
{
cerr << argv[0] << ": can't open `" << fileH << "' for writing: " << strerror(errno) << endl;
u->destroy();
return EXIT_FAILURE;
}
- printHeader(_H);
- printFreezeTypes(_H, dicts, indices);
+ printHeader(H);
+ printFreezeTypes(H, dicts, indices);
- SignalHandler::addFileForCleanup(fileC);
- _CPP.open(fileC.c_str());
- if(!_CPP)
+ IceUtilInternal::Output CPP;
+ CPP.open(fileC.c_str());
+ if(!CPP)
{
cerr << argv[0] << ": can't open `" << fileC << "' for writing: " << strerror(errno) << endl;
u->destroy();
return EXIT_FAILURE;
}
- printHeader(_CPP);
- printFreezeTypes(_CPP, dicts, indices);
+ printHeader(CPP);
+ printFreezeTypes(CPP, dicts, indices);
for(vector<string>::const_iterator i = extraHeaders.begin(); i != extraHeaders.end(); ++i)
{
@@ -1889,57 +1895,57 @@ main(int argc, char* argv[])
}
if(!guard.empty())
{
- _CPP << "\n#ifndef " << guard;
- _CPP << "\n#define " << guard;
+ CPP << "\n#ifndef " << guard;
+ CPP << "\n#define " << guard;
}
- _CPP << "\n#include <";
+ CPP << "\n#include <";
if(!include.empty())
{
- _CPP << include << '/';
+ CPP << include << '/';
}
- _CPP << hdr << '>';
+ CPP << hdr << '>';
if(!guard.empty())
{
- _CPP << "\n#endif";
+ CPP << "\n#endif";
}
}
string s = fileH;
transform(s.begin(), s.end(), s.begin(), ToIfdef());
- _H << "\n#ifndef __" << s << "__";
- _H << "\n#define __" << s << "__";
- _H << '\n';
+ H << "\n#ifndef __" << s << "__";
+ H << "\n#define __" << s << "__";
+ H << '\n';
if(dicts.size() > 0)
{
- _H << "\n#include <Freeze/Map.h>";
+ H << "\n#include <Freeze/Map.h>";
}
if(indices.size() > 0)
{
- _H << "\n#include <Freeze/Index.h>";
+ H << "\n#include <Freeze/Index.h>";
}
{
for(StringList::const_iterator p = includes.begin(); p != includes.end(); ++p)
{
- _H << "\n#include <" << changeInclude(*p, includePaths) << "." + headerExtension + ">";
+ H << "\n#include <" << changeInclude(*p, includePaths) << "." + headerExtension + ">";
}
}
- _CPP << "\n#include <Ice/BasicStream.h>";
- _CPP << "\n#include <";
+ CPP << "\n#include <Ice/BasicStream.h>";
+ CPP << "\n#include <";
if(include.size())
{
- _CPP << include << '/';
+ CPP << include << '/';
}
- _CPP << includeH << '>';
+ CPP << includeH << '>';
- printVersionCheck(_H);
- printVersionCheck(_CPP);
+ printVersionCheck(H);
+ printVersionCheck(CPP);
- printDllExportStuff(_H, dllExport);
+ printDllExportStuff(H, dllExport);
if(dllExport.size())
{
dllExport += " ";
@@ -1950,7 +1956,7 @@ main(int argc, char* argv[])
{
try
{
- if(!writeDict(argv[0], u, *p, _H, _CPP, dllExport))
+ if(!writeDict(argv[0], u, *p, H, CPP, dllExport))
{
u->destroy();
return EXIT_FAILURE;
@@ -1969,7 +1975,7 @@ main(int argc, char* argv[])
{
try
{
- if(!writeIndex(argv[0], u, *q, _H, _CPP, dllExport))
+ if(!writeIndex(argv[0], u, *q, H, CPP, dllExport))
{
u->destroy();
return EXIT_FAILURE;
@@ -1985,14 +1991,24 @@ main(int argc, char* argv[])
}
- _H << "\n\n#endif\n";
- _CPP << '\n';
+ H << "\n\n#endif\n";
+ CPP << '\n';
- _H.close();
- _CPP.close();
+ H.close();
+ CPP.close();
}
u->destroy();
+ {
+ IceUtil::StaticMutex::Lock lock(_mutex);
+
+ if(_interrupted)
+ {
+ return EXIT_FAILURE;
+ }
+ }
+
+
return status;
}