summaryrefslogtreecommitdiff
path: root/cpp/src/slice2cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2008-11-19 11:06:31 -0330
committerDwayne Boone <dwayne@zeroc.com>2008-11-19 11:06:31 -0330
commit7f24f7fd2361ff5d43775e4523bc78ffdb108306 (patch)
tree62d26962d53259163ee997a7172af5a8fb550a1d /cpp/src/slice2cpp
parentBug 3541 - Slice signal handling unsafe (diff)
downloadice-7f24f7fd2361ff5d43775e4523bc78ffdb108306.tar.bz2
ice-7f24f7fd2361ff5d43775e4523bc78ffdb108306.tar.xz
ice-7f24f7fd2361ff5d43775e4523bc78ffdb108306.zip
Added use of CtrlChandler to slice compilers
Diffstat (limited to 'cpp/src/slice2cpp')
-rw-r--r--cpp/src/slice2cpp/Gen.cpp27
-rw-r--r--cpp/src/slice2cpp/Main.cpp5
2 files changed, 27 insertions, 5 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 4c0eb293823..73a3673e655 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -23,6 +23,19 @@ using namespace Slice;
using namespace IceUtil;
using namespace IceUtilInternal;
+//
+// Callback for Crtl-C signal handling
+//
+static Gen* _gen = 0;
+
+static void closeCallback()
+{
+ if(_gen != 0)
+ {
+ _gen->closeOutput();
+ }
+}
+
static string
getDeprecateSymbol(const ContainedPtr& p1, const ContainedPtr& p2)
{
@@ -51,6 +64,9 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte
_stream(stream),
_ice(ice)
{
+ _gen = this;
+ SignalHandler::setCloseCallback(closeCallback);
+
for(vector<string>::iterator p = _includePaths.begin(); p != _includePaths.end(); ++p)
{
*p = fullPath(*p);
@@ -71,8 +87,6 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte
fileImplH = dir + '/' + fileImplH;
fileImplC = dir + '/' + fileImplC;
}
- SignalHandler::addFile(fileImplH);
- SignalHandler::addFile(fileImplC);
struct stat st;
if(stat(fileImplH.c_str(), &st) == 0)
@@ -86,6 +100,7 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte
return;
}
+ SignalHandler::addFileForCleanup(fileImplH);
implH.open(fileImplH.c_str());
if(!implH)
{
@@ -93,6 +108,7 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte
return;
}
+ SignalHandler::addFileForCleanup(fileImplC);
implC.open(fileImplC.c_str());
if(!implC)
{
@@ -118,9 +134,8 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte
fileH = dir + '/' + fileH;
fileC = dir + '/' + fileC;
}
- SignalHandler::addFile(fileH);
- SignalHandler::addFile(fileC);
+ SignalHandler::addFileForCleanup(fileH);
H.open(fileH.c_str());
if(!H)
{
@@ -128,6 +143,7 @@ Slice::Gen::Gen(const string& name, const string& base, const string& headerExte
return;
}
+ SignalHandler::addFileForCleanup(fileC);
C.open(fileC.c_str());
if(!C)
{
@@ -161,6 +177,9 @@ Slice::Gen::~Gen()
implH << "\n\n#endif\n";
implC << '\n';
}
+
+ _gen = 0;
+ SignalHandler::setCloseCallback(0);
}
bool
diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp
index 0fef7634add..4ead491dd22 100644
--- a/cpp/src/slice2cpp/Main.cpp
+++ b/cpp/src/slice2cpp/Main.cpp
@@ -8,6 +8,7 @@
// **********************************************************************
#include <IceUtil/Options.h>
+#include <IceUtil/CtrlCHandler.h>
#include <Slice/Preprocessor.h>
#include <Slice/SignalHandler.h>
#include <Gen.h>
@@ -151,7 +152,9 @@ main(int argc, char* argv[])
for(i = args.begin(); i != args.end(); ++i)
{
- SignalHandler sigHandler;
+ SignalHandler::clearCleanupFileList();
+ IceUtil::CtrlCHandler ctrlCHandler;
+ ctrlCHandler.setCallback(SignalHandler::removeFilesOnInterrupt);
if(depend)
{