Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove IceUtil namespace in C++ #2346

Merged
merged 8 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <Ice/Ice.h>
// Disable deprecation warnings from SecureTransport APIs
#include "IceUtil/DisableWarnings.h"
#include "../../src/IceUtil/DisableWarnings.h"

#if defined(ICE_USE_SECURE_TRANSPORT)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <Ice/Ice.h>
// Disable deprecation warnings from SecureTransport APIs
#include "IceUtil/DisableWarnings.h"
#include "../../src/IceUtil/DisableWarnings.h"

#if defined(ICE_USE_SECURE_TRANSPORT)
void
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/Ice/Communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ namespace Ice
friend ICE_API CommunicatorPtr initialize(StringSeq&, const InitializationData&, std::int32_t);
friend ICE_API CommunicatorPtr initialize(const InitializationData&, std::int32_t);
friend ICE_API IceInternal::InstancePtr IceInternal::getInstance(const Ice::CommunicatorPtr&);
friend ICE_API ::IceUtil::TimerPtr IceInternal::getInstanceTimer(const Ice::CommunicatorPtr&);
friend ICE_API ::Ice::TimerPtr IceInternal::getInstanceTimer(const Ice::CommunicatorPtr&);

const IceInternal::InstancePtr _instance;
};
Expand Down
60 changes: 59 additions & 1 deletion cpp/include/Ice/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,64 @@
#ifndef ICE_CONFIG_H
#define ICE_CONFIG_H

#include "IceUtil/Config.h"
// Compiler extensions to export and import symbols: see the documentation for Visual Studio, Clang and GCC.
#if defined(_MSC_VER)
# define ICE_DECLSPEC_EXPORT __declspec(dllexport)
# define ICE_DECLSPEC_IMPORT __declspec(dllimport)
// With Visual Studio, we can import/export member functions without importing/exporting the whole class.
# define ICE_MEMBER_IMPORT_EXPORT
#elif defined(__GNUC__) || defined(__clang__)
# define ICE_DECLSPEC_EXPORT __attribute__((visibility("default")))
# define ICE_DECLSPEC_IMPORT __attribute__((visibility("default")))
#else
# define ICE_DECLSPEC_EXPORT /**/
# define ICE_DECLSPEC_IMPORT /**/
#endif

#ifdef ICE_MEMBER_IMPORT_EXPORT
# define ICE_CLASS(API) /**/
# define ICE_MEMBER(API) API
#else
# define ICE_CLASS(API) API
# define ICE_MEMBER(API) /**/
#endif

#ifndef ICE_API
# if defined(ICE_STATIC_LIBS)
# define ICE_API /**/
# elif defined(ICE_API_EXPORTS)
# define ICE_API ICE_DECLSPEC_EXPORT
# else
# define ICE_API ICE_DECLSPEC_IMPORT
# endif
#endif

#ifdef __APPLE__
# include <TargetConditionals.h>
#endif

// The Ice version.
#define ICE_STRING_VERSION "3.8.0-alpha.0" // "A.B.C", with A=major, B=minor, C=patch
#define ICE_INT_VERSION 30850 // AABBCC, with AA=major, BB=minor, CC=patch
#define ICE_SO_VERSION "38a0" // "ABC", with A=major, B=minor, C=patch

#if !defined(ICE_BUILDING_ICE) && defined(ICE_API_EXPORTS)
# define ICE_BUILDING_ICE
#endif

#if defined(_MSC_VER)
# if !defined(ICE_STATIC_LIBS) && (!defined(_DLL) || !defined(_MT))
# error "Only multi-threaded DLL libraries can be used with Ice!"
# endif
# if defined(_DEBUG)
# define ICE_LIBNAME(NAME) NAME ICE_SO_VERSION "D.lib"
# else
# define ICE_LIBNAME(NAME) NAME ICE_SO_VERSION ".lib"
# endif
// Automatically link with Ice[D].lib when using MSVC
# if !defined(ICE_BUILDING_ICE) && !defined(ICE_BUILDING_SLICE_COMPILERS)
# pragma comment(lib, ICE_LIBNAME("Ice"))
# endif
#endif

#endif
58 changes: 55 additions & 3 deletions cpp/include/Ice/CtrlCHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,64 @@
#ifndef ICE_CTRL_C_HANDLER_H
#define ICE_CTRL_C_HANDLER_H

#include "IceUtil/CtrlCHandler.h"
#include "Config.h"
#include <functional>

namespace Ice
{
using CtrlCHandlerCallback = IceUtil::CtrlCHandlerCallback;
using CtrlCHandler = IceUtil::CtrlCHandler;
/**
* Invoked when a signal occurs. The callback must not raise exceptions.
* On Linux and macOS, the callback is NOT a signal handler and can call
* functions that are not async-signal safe.
* @param sig The signal number that occurred.
*/
using CtrlCHandlerCallback = std::function<void(int sig)>;

/**
* Provides a portable way to handle Ctrl-C and Ctrl-C like signals.
* On Linux and macOS, the CtrlCHandler handles SIGHUP, SIGINT and SIGTERM.
* On Windows, it is essentially a wrapper for SetConsoleCtrlHandler().
*
* \headerfile Ice/Ice.h
*/
class ICE_API CtrlCHandler
{
public:
/**
* Registers a callback function that handles Ctrl-C like signals.
* On Linux and macOS, this constructor masks the SIGHUP, SIGINT and SIGTERM
* signals and then creates a thread that waits for these signals using sigwait.
* On Windows, this constructor calls SetConsoleCtrlCHandler to register a handler
* routine that calls the supplied callback function.
* Only a single CtrlCHandler object can exist in a process at a give time.
* @param cb The callback function to invoke when a signal is received.
*/
explicit CtrlCHandler(CtrlCHandlerCallback cb = nullptr);

/**
* Unregisters the callback function.
* On Linux and macOS, this destructor joins and terminates the thread created
* by the constructor but does not "unmask" SIGHUP, SIGINT and SIGTERM. As a result,
* these signals are ignored after this destructor completes.
* On Windows, this destructor unregisters the SetConsoleCtrlHandler handler
* routine, and as a result a Ctrl-C or similar signal will terminate the application
* after this destructor completes.
*/
~CtrlCHandler();

/**
* Replaces the signal callback.
* @param cb The new callback.
* @return The old callback, or nil if no callback is currently set.
*/
CtrlCHandlerCallback setCallback(CtrlCHandlerCallback cb);

/**
* Obtains the signal callback.
* @return The callback.
*/
CtrlCHandlerCallback getCallback() const;
};
}

#endif
10 changes: 5 additions & 5 deletions cpp/include/Ice/IconvStringConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#ifndef _WIN32
# include "Config.h"
# include "Exception.h"
# include "IceUtil/StringUtil.h"
# include "StringConverter.h"
# include "StringUtil.h"

# include <algorithm>
# include <cassert>
Expand Down Expand Up @@ -71,7 +71,7 @@ namespace IceInternal
// opening / closing iconv_t objects all the time.
//
//
template<typename charT> class IconvStringConverter final : public IceUtil::BasicStringConverter<charT>
template<typename charT> class IconvStringConverter final : public Ice::BasicStringConverter<charT>
{
public:
IconvStringConverter(const std::string&);
Expand Down Expand Up @@ -196,7 +196,7 @@ namespace IceInternal
throw Ice::IllegalConversionException(
__FILE__,
__LINE__,
errno == 0 ? "Unknown error" : IceUtilInternal::errorToString(errno));
errno == 0 ? "Unknown error" : IceInternal::errorToString(errno));
}
return outbuf;
}
Expand Down Expand Up @@ -256,7 +256,7 @@ namespace IceInternal
throw Ice::IllegalConversionException(
__FILE__,
__LINE__,
errno == 0 ? "Unknown error" : IceUtilInternal::errorToString(errno));
errno == 0 ? "Unknown error" : IceInternal::errorToString(errno));
}

target.resize(target.size() - (outbytesleft / sizeof(charT)));
Expand All @@ -272,7 +272,7 @@ namespace Ice
* @throws IconvInitializationException If the code is not supported.
*/
template<typename charT>
std::shared_ptr<IceUtil::BasicStringConverter<charT>>
std::shared_ptr<Ice::BasicStringConverter<charT>>
createIconvStringConverter(const std::string& internalCodeWithDefault = "")
{
std::string internalCode = internalCodeWithDefault;
Expand Down
31 changes: 3 additions & 28 deletions cpp/include/Ice/Initialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
#include "CommunicatorF.h"
#include "Connection.h"
#include "Ice/BuiltinSequences.h"
#include "IceUtil/Timer.h"
#include "Ice/Timer.h"
#include "InstanceF.h"
#include "Instrumentation.h"
#include "Logger.h"
#include "Plugin.h"
#include "PropertiesF.h"
#include "SSL/ClientAuthenticationOptions.h"
#include "StringUtil.h"
#include "ValueFactory.h"

namespace Ice
Expand Down Expand Up @@ -678,32 +679,6 @@ namespace Ice
CommunicatorPtr _communicator;
};

/**
* The output mode for xxxToString method such as identityToString and proxyToString. The actual encoding format for
* the string is the same for all modes: you don't need to specify an encoding format or mode when reading such a
* string.
*/
enum class ToStringMode : std::uint8_t
{
/**
* Characters with ordinal values greater than 127 are kept as-is in the resulting string. Non-printable ASCII
* characters with ordinal values 127 and below are encoded as \\t, \\n (etc.) or \\unnnn.
*/
Unicode,
/**
* Characters with ordinal values greater than 127 are encoded as universal character names in the resulting
* string: \\unnnn for BMP characters and \\Unnnnnnnn for non-BMP characters. Non-printable ASCII characters
* with ordinal values 127 and below are encoded as \\t, \\n (etc.) or \\unnnn.
*/
ASCII,
/**
* Characters with ordinal values greater than 127 are encoded as a sequence of UTF-8 bytes using octal escapes.
* Characters with ordinal values 127 and below are encoded as \\t, \\n (etc.) or an octal escape. Use this mode
* to generate strings compatible with Ice 3.6 and earlier.
*/
Compat
};

/**
* Converts a stringified identity into an Identity.
* @param str The stringified identity.
Expand All @@ -728,7 +703,7 @@ namespace IceInternal
// to be used by modules such as Freeze.
//
ICE_API InstancePtr getInstance(const Ice::CommunicatorPtr&);
ICE_API IceUtil::TimerPtr getInstanceTimer(const Ice::CommunicatorPtr&);
ICE_API Ice::TimerPtr getInstanceTimer(const Ice::CommunicatorPtr&);
}

#endif
33 changes: 31 additions & 2 deletions cpp/include/Ice/MetricsObserverI.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "Connection.h"
#include "Endpoint.h"
#include "Ice/Metrics.h"
#include "IceUtil/StopWatch.h"
#include "Instrumentation.h"
#include "MetricsAdminI.h"
#include "MetricsFunctional.h"
Expand All @@ -17,6 +16,36 @@
#include <sstream>
#include <stdexcept>

namespace IceInternal
{
class StopWatch
{
public:
StopWatch() {}

void start() { _start = std::chrono::steady_clock::now(); }

std::chrono::microseconds stop()
{
assert(isStarted());
auto duration =
std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - _start);
_start = std::chrono::steady_clock::time_point();
return duration;
}

bool isStarted() const { return _start != std::chrono::steady_clock::time_point(); }

std::chrono::microseconds delay()
{
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - _start);
}

private:
std::chrono::steady_clock::time_point _start;
};
}

namespace IceMX
{
/// \cond INTERNAL
Expand Down Expand Up @@ -400,7 +429,7 @@ namespace IceMX

private:
EntrySeqType _objects;
IceUtilInternal::StopWatch _watch;
IceInternal::StopWatch _watch;
std::chrono::microseconds _previousDelay;
};

Expand Down
4 changes: 2 additions & 2 deletions cpp/include/Ice/OutgoingAsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "CommunicatorF.h"
#include "ConnectionF.h"
#include "ConnectionIF.h"
#include "IceUtil/Timer.h"
#include "Ice/Timer.h"
#include "InputStream.h"
#include "LocalException.h"
#include "ObjectAdapterF.h"
Expand Down Expand Up @@ -138,7 +138,7 @@ namespace IceInternal
// correct notified of failures and make sure the retry task is
// correctly canceled when the invocation completes.
//
class ICE_API ProxyOutgoingAsyncBase : public OutgoingAsyncBase, public IceUtil::TimerTask
class ICE_API ProxyOutgoingAsyncBase : public OutgoingAsyncBase, public Ice::TimerTask
{
public:
virtual AsyncStatus invokeRemote(const Ice::ConnectionIPtr&, bool, bool) = 0;
Expand Down
Loading
Loading