summaryrefslogtreecommitdiff
path: root/cpp/src/IcePatch2/Client.cpp
diff options
context:
space:
mode:
authorAustin Henriksen <austin.r.henriksen79@gmail.com>2018-09-19 10:56:16 -0400
committerGitHub <noreply@github.com>2018-09-19 10:56:16 -0400
commitf71fcb1ab9477721b5599b7b76dff498841ce10f (patch)
tree9b15158398b416d16126de313ed69315d43caf7b /cpp/src/IcePatch2/Client.cpp
parentFix slice2objc bogus generated code for Ice::Value data member (diff)
downloadice-f71fcb1ab9477721b5599b7b76dff498841ce10f.tar.bz2
ice-f71fcb1ab9477721b5599b7b76dff498841ce10f.tar.xz
ice-f71fcb1ab9477721b5599b7b76dff498841ce10f.zip
Removed Application from Ice Services (#196)
Removed Application from Ice services, fixes #50
Diffstat (limited to 'cpp/src/IcePatch2/Client.cpp')
-rw-r--r--cpp/src/IcePatch2/Client.cpp140
1 files changed, 74 insertions, 66 deletions
diff --git a/cpp/src/IcePatch2/Client.cpp b/cpp/src/IcePatch2/Client.cpp
index 3027bb73b0f..1960573cc36 100644
--- a/cpp/src/IcePatch2/Client.cpp
+++ b/cpp/src/IcePatch2/Client.cpp
@@ -9,7 +9,7 @@
#include <IceUtil/Options.h>
#include <IceUtil/StringUtil.h>
-#include <Ice/Application.h>
+#include <Ice/Ice.h>
#include <Ice/ConsoleUtil.h>
#include <IcePatch2Lib/Util.h>
#include <IcePatch2/ClientUtil.h>
@@ -22,12 +22,9 @@
#endif
using namespace std;
-using namespace Ice;
using namespace IceInternal;
-using namespace IcePatch2;
-using namespace IcePatch2Internal;
-class TextPatcherFeedback : public PatcherFeedback
+class TextPatcherFeedback : public IcePatch2::PatcherFeedback
{
public:
@@ -83,7 +80,7 @@ public:
virtual bool
checksumProgress(const string& path)
{
- consoleOut << "Calculating checksum for " << getBasename(path) << endl;
+ consoleOut << "Calculating checksum for " << IcePatch2Internal::getBasename(path) << endl;
return !keyPressed();
}
@@ -108,7 +105,7 @@ public:
}
virtual bool
- fileListProgress(Int percent)
+ fileListProgress(Ice::Int percent)
{
for(unsigned int i = 0; i < _lastProgress.size(); ++i)
{
@@ -129,7 +126,7 @@ public:
}
virtual bool
- patchStart(const string& path, Long size, Long totalProgress, Long totalSize)
+ patchStart(const string& path, Ice::Long size, Ice::Long totalProgress, Ice::Long totalSize)
{
if(!_pressAnyKeyMessage)
{
@@ -140,12 +137,12 @@ public:
ostringstream s;
s << "0/" << size << " (" << totalProgress << '/' << totalSize << ')';
_lastProgress = s.str();
- consoleOut << getBasename(path) << ' ' << _lastProgress << flush;
+ consoleOut << IcePatch2Internal::getBasename(path) << ' ' << _lastProgress << flush;
return !keyPressed();
}
virtual bool
- patchProgress(Long progress, Long size, Long totalProgress, Long totalSize)
+ patchProgress(Ice::Long progress, Ice::Long size, Ice::Long totalProgress, Ice::Long totalSize)
{
for(unsigned int i = 0; i < _lastProgress.size(); ++i)
{
@@ -255,71 +252,111 @@ private:
bool _pressAnyKeyMessage;
};
-class Client : public Ice::Application
+int run(const Ice::StringSeq&);
+
+Ice::CommunicatorPtr communicator;
+
+void
+destroyCommunicator(int)
{
-public:
+ communicator->destroy();
+}
- virtual int run(int, char*[]);
+int
+#ifdef _WIN32
+wmain(int argc, wchar_t* argv[])
+#else
+main(int argc, char* argv[])
+#endif
+{
+ int status = 0;
-private:
+ try
+ {
+ Ice::CtrlCHandler ctrlCHandler;
+ Ice::CommunicatorHolder ich(argc, argv);
+ communicator = ich.communicator();
- void usage(const std::string&);
-};
+ ctrlCHandler.setCallback(&destroyCommunicator);
+
+ status = run(Ice::argsToStringSeq(argc, argv));
+ }
+ catch(const std::exception& ex)
+ {
+ consoleErr << ex.what() << endl;
+ status = 1;
+ }
+
+ return status;
+}
+
+void
+usage(const string& appName)
+{
+ string options =
+ "Options:\n"
+ "-h, --help Show this message.\n"
+ "-v, --version Display the Ice version.\n"
+ "-t, --thorough Recalculate all checksums.";
+
+ consoleErr << "Usage: " << appName << " [options] [DIR]" << endl;
+ consoleErr << options << endl;
+}
int
-Client::run(int argc, char* argv[])
+run(const Ice::StringSeq& args)
{
- PropertiesPtr properties = communicator()->getProperties();
+ Ice::PropertiesPtr properties = communicator->getProperties();
IceUtilInternal::Options opts;
opts.addOpt("h", "help");
opts.addOpt("v", "version");
opts.addOpt("t", "thorough");
- vector<string> args;
+ vector<string> props;
try
{
- args = opts.parse(argc, const_cast<const char**>(argv));
+ props = opts.parse(args);
}
catch(const IceUtilInternal::BadOptException& e)
{
consoleErr << e.reason << endl;
- usage(argv[0]);
- return EXIT_FAILURE;
+ usage(args[0]);
+ return 1;
}
if(opts.isSet("help"))
{
- usage(argv[0]);
- return EXIT_SUCCESS;
+ usage(args[0]);
+ return 0;
}
if(opts.isSet("version"))
{
consoleOut << ICE_STRING_VERSION << endl;
- return EXIT_SUCCESS;
+ return 0;
}
if(opts.isSet("thorough"))
{
properties->setProperty("IcePatch2Client.Thorough", "1");
}
- if(args.size() > 1)
+ if(props.size() > 1)
{
- consoleErr << argv[0] << ": too many arguments" << endl;
- usage(argv[0]);
- return EXIT_FAILURE;
+ consoleErr << args[0] << ": too many arguments" << endl;
+ usage(args[0]);
+ return 1;
}
- if(args.size() == 1)
+ if(props.size() == 1)
{
- properties->setProperty("IcePatch2Client.Directory", simplify(args[0]));
+ properties->setProperty("IcePatch2Client.Directory", IcePatch2Internal::simplify(props[0]));
}
bool aborted = false;
try
{
- PatcherFeedbackPtr feedback = new TextPatcherFeedback;
- PatcherPtr patcher = PatcherFactory::create(communicator(), feedback);
+ IcePatch2::PatcherFeedbackPtr feedback = new TextPatcherFeedback;
+ IcePatch2::PatcherPtr patcher = IcePatch2::PatcherFactory::create(communicator, feedback);
aborted = !patcher->prepare();
@@ -335,46 +372,17 @@ Client::run(int argc, char* argv[])
}
catch(const exception& ex)
{
- consoleErr << argv[0] << ": " << ex.what() << endl;
- return EXIT_FAILURE;
+ consoleErr << args[0] << ": " << ex.what() << endl;
+ return 1;
}
if(aborted)
{
consoleOut << "\n[Aborted]" << endl;
- return EXIT_FAILURE;
+ return 1;
}
else
{
- return EXIT_SUCCESS;
+ return 0;
}
}
-
-void
-Client::usage(const string& appName)
-{
- string options =
- "Options:\n"
- "-h, --help Show this message.\n"
- "-v, --version Display the Ice version.\n"
- "-t, --thorough Recalculate all checksums.";
-
- consoleErr << "Usage: " << appName << " [options] [DIR]" << endl;
- consoleErr << options << endl;
-}
-
-#ifdef _WIN32
-
-int
-wmain(int argc, wchar_t* argv[])
-
-#else
-
-int
-main(int argc, char* argv[])
-
-#endif
-{
- Client app;
- return app.main(argc, argv);
-}