Ice 3.8
C++ API Reference
Loading...
Searching...
No Matches
Initialize.h
1// Copyright (c) ZeroC, Inc.
2
3#ifndef ICE_INITIALIZE_H
4#define ICE_INITIALIZE_H
5
6#include "BatchRequest.h"
7#include "CommunicatorF.h"
8#include "Connection.h"
9#include "Ice/BuiltinSequences.h"
10#include "InstanceF.h"
11#include "Instrumentation.h"
12#include "Logger.h"
13#include "Plugin.h"
14#include "PluginFactory.h"
15#include "PropertiesF.h"
16#include "SSL/ClientAuthenticationOptions.h"
17#include "SliceLoader.h"
18#include "StringUtil.h"
19#include "TimerTask.h"
20
21namespace Ice
22{
23 /// Converts an argument vector into a string sequence.
24 /// @param argc The number of arguments in argv.
25 /// @param argv The arguments.
26 /// @return A string sequence containing the arguments.
27 ICE_API StringSeq argsToStringSeq(int argc, const char* const argv[]);
28
29#if defined(_WIN32) || defined(ICE_DOXYGEN)
30 /// @copydoc argsToStringSeq(int, const char* const[])
31 /// @remark Windows only.
32 ICE_API StringSeq argsToStringSeq(int argc, const wchar_t* const argv[]);
33#endif
34
35 /// Updates @p argv to match the contents of @p seq. This function assumes that @p seq contains only elements of
36 /// @p argv. The function shifts the argument vector elements so that the vector matches the contents of the
37 /// sequence.
38 /// @param seq The string sequence returned from a call to #argsToStringSeq.
39 /// @param[in,out] argc The number of arguments, updated to reflect the size of the sequence.
40 /// @param argv The arguments, shifted to match @p seq.
41 ICE_API void stringSeqToArgs(const StringSeq& seq, int& argc, const char* argv[]);
42
43 /// @copydoc stringSeqToArgs(const StringSeq&, int&, const char*[])
44 inline void stringSeqToArgs(const StringSeq& seq, int& argc, char* argv[])
45 {
46 return stringSeqToArgs(seq, argc, const_cast<const char**>(argv));
47 }
48
49#if defined(_WIN32) || defined(ICE_DOXYGEN)
50 /// @copydoc stringSeqToArgs(const StringSeq&, int&, const char*[])
51 /// @remark Windows only.
52 ICE_API void stringSeqToArgs(const StringSeq& seq, int& argc, const wchar_t* argv[]);
53
54 /// @copydoc stringSeqToArgs(const StringSeq&, int&, const char*[])
55 /// @remark Windows only.
56 inline void stringSeqToArgs(const StringSeq& seq, int& argc, wchar_t* argv[])
57 {
58 return stringSeqToArgs(seq, argc, const_cast<const wchar_t**>(argv));
59 }
60#endif
61
62 /// Represents a set of options that you can specify when initializing a communicator.
63 /// @headerfile Ice/Ice.h
65 {
66 /// The properties for the communicator.
68
69 /// The logger for the communicator.
71
72 /// The communicator observer used by the Ice runtime.
74
75#if defined(__clang__)
76# pragma clang diagnostic push
77# pragma clang diagnostic ignored "-Wdocumentation" // param/return is not recognized for std::function data members
78#endif
79
80 /// A function that the communicator calls when it starts a new thread.
81 std::function<void()> threadStart{};
82
83 /// A function that the communicator calls when it destroys a thread.
84 std::function<void()> threadStop{};
85
86 /// A function that the communicator calls to execute dispatches and async invocation callbacks.
87 /// @param call Represents the function to execute. The executor must eventually execute this function.
88 /// @param con The connection associated with this call. May be null.
89 std::function<void(std::function<void()> call, const Ice::ConnectionPtr& con)> executor{};
90
91 /// The batch request interceptor, which is called by the Ice runtime to enqueue a batch request.
92 /// @param req An object representing the batch request.
93 /// @param count The number of requests currently in the queue.
94 /// @param size The number of bytes consumed by the requests currently in the queue.
95 std::function<void(const Ice::BatchRequest& req, int count, int size)> batchRequestInterceptor{};
96
97#if defined(__clang__)
98# pragma clang diagnostic pop
99#endif
100
101 /// The authentication options for SSL client connections. When set, the SSL transport ignores all IceSSL
102 /// configuration properties and uses these options.
103 /// @see SSL::OpenSSLClientAuthenticationOptions
104 /// @see SSL::SecureTransportClientAuthenticationOptions
105 /// @see SSL::SchannelClientAuthenticationOptions
106 std::optional<SSL::ClientAuthenticationOptions> clientAuthenticationOptions{};
107
108 /// A list of plug-in factories. The corresponding plug-ins are created during communicator initialization,
109 /// in order, before all other plug-ins.
110 std::vector<PluginFactory> pluginFactories{};
111
112 /// The Slice loader, used to unmarshal Slice classes and exceptions.
114 };
115
116 /// Creates a new communicator.
117 /// @param[in,out] argc The number of arguments in @p argv. When this function parses properties from @p argv, it
118 /// reshuffles the arguments so that the remaining arguments start at the beginning of @p argv, and updates @p argc
119 /// accordingly.
120 /// @param argv The command-line arguments. This function parses arguments starting with `--` and one of the
121 /// reserved prefixes (Ice, IceSSL, etc.) as properties for the new communicator. If there is an argument starting
122 /// with `--Ice.Config`, this function loads the specified configuration file. When the same property is set in a
123 /// configuration file and through a command-line argument, the command-line setting takes precedence.
124 /// @param initData Options for the new communicator.
125 /// @return The new communicator.
126 ICE_API CommunicatorPtr initialize(int& argc, const char* argv[], InitializationData initData = {});
127
128 /// @copydoc initialize(int&, const char*[], InitializationData)
129 inline CommunicatorPtr initialize(int& argc, char* argv[], InitializationData initData = {})
130 {
131 return initialize(argc, const_cast<const char**>(argv), std::move(initData));
132 }
133
134 /// Creates a new communicator.
135 /// @param[in,out] argc The number of arguments in @p argv. When this function parses properties from @p argv, it
136 /// reshuffles the arguments so that the remaining arguments start at the beginning of @p argv, and updates @p argc.
137 /// @param argv The command-line arguments. This function parses arguments starting with `--` and one of the
138 /// reserved prefixes (Ice, IceSSL, etc.) as properties for the new communicator.
139 /// @param configFile The name of an Ice configuration file.
140 /// @return The new communicator.
141 ICE_API CommunicatorPtr initialize(int& argc, const char* argv[], std::string_view configFile);
142
143 /// @copydoc initialize(int&, const char*[], std::string_view)
144 inline CommunicatorPtr initialize(int& argc, char* argv[], std::string_view configFile)
145 {
146 return initialize(argc, const_cast<const char**>(argv), configFile);
147 }
148
149#if defined(_WIN32) || defined(ICE_DOXYGEN)
150 /// @copydoc initialize(int&, const char*[], InitializationData)
151 /// @remark Windows only.
152 ICE_API CommunicatorPtr initialize(int& argc, const wchar_t* argv[], InitializationData initData = {});
153
154 /// @copydoc initialize(int&, const char*[], InitializationData)
155 /// @remark Windows only.
156 inline CommunicatorPtr initialize(int& argc, wchar_t* argv[], InitializationData initData = {})
157 {
158 return initialize(argc, const_cast<const wchar_t**>(argv), std::move(initData));
159 }
160
161 // @copydoc initialize(int&, const char*[], std::string_view)
162 /// @remark Windows only.
163 ICE_API CommunicatorPtr initialize(int& argc, const wchar_t* argv[], std::string_view configFile);
164
165 // @copydoc initialize(int&, const char*[], std::string_view)
166 /// @remark Windows only.
167 inline CommunicatorPtr initialize(int& argc, wchar_t* argv[], std::string_view configFile)
168 {
169 return initialize(argc, const_cast<const wchar_t**>(argv), configFile);
170 }
171#endif
172
173 /// Creates a new communicator.
174 /// @param[in,out] seq The command-line arguments. This function parses arguments starting with `--` and one of the
175 /// reserved prefixes (Ice, IceSSL, etc.) as properties for the new communicator and removes these elements from the
176 /// list. If there is an argument starting with `--Ice.Config`, this function loads the specified configuration
177 /// file. When the same property is set in a configuration file and through a command-line argument, the
178 /// command-line setting takes precedence.
179 /// @param initData Options for the new communicator.
180 /// @return The new communicator.
182
183 /// Creates a new communicator.
184 /// @param[in,out] seq The command-line arguments. This function parses arguments starting with `--` and one of the
185 /// reserved prefixes (Ice, IceSSL, etc.) as properties for the new communicator and removes these elements from the
186 /// list.
187 /// @param configFile The name of an Ice configuration file.
188 /// @return The new communicator.
189 ICE_API CommunicatorPtr initialize(StringSeq& seq, std::string_view configFile);
190
191 /// Creates a new communicator.
192 /// @param initData Options for the new communicator.
193 /// @return The new communicator.
195
196 /// Creates a new communicator.
197 /// @param configFile The name of an Ice configuration file.
198 /// @return The new communicator.
199 ICE_API CommunicatorPtr initialize(std::string_view configFile);
200
201 /// Gets the per-process logger. This logger is used by all communicators that do not have their own specific logger
202 /// configured at the time the communicator is created.
203 /// @return The current per-process logger instance.
205
206 /// Sets the per-process logger. This logger is used by all communicators that do not have their own specific logger
207 /// configured at the time the communicator is created.
208 /// @param logger The new per-process logger instance.
209 ICE_API void setProcessLogger(const LoggerPtr& logger);
210
211 /// Converts a stringified identity into an Identity.
212 /// @param str The stringified identity.
213 /// @return An Identity containing the name and category components.
214 ICE_API Identity stringToIdentity(std::string_view str);
215
216 /// Converts an Identity into a string using the specified mode.
217 /// @param id The identity.
218 /// @param mode Specifies how to handle non-ASCII characters and non-printable ASCII characters.
219 /// @return The stringified identity.
220 ICE_API std::string identityToString(const Identity& id, ToStringMode mode = ToStringMode::Unicode);
221}
222
223namespace IceInternal
224{
225 ICE_API InstancePtr getInstance(const Ice::CommunicatorPtr&);
226 ICE_API TimerPtr getInstanceTimer(const Ice::CommunicatorPtr&);
227}
228
229#endif
Represents a batch request.
std::shared_ptr< CommunicatorObserver > CommunicatorObserverPtr
A shared pointer to a CommunicatorObserver.
void setProcessLogger(const LoggerPtr &logger)
Sets the per-process logger.
std::shared_ptr< Communicator > CommunicatorPtr
A shared pointer to a Communicator.
std::shared_ptr< Properties > PropertiesPtr
A shared pointer to a Properties.
Definition PropertiesF.h:13
std::string identityToString(const Identity &id, ToStringMode mode=ToStringMode::Unicode)
Converts an Identity into a string using the specified mode.
StringSeq argsToStringSeq(int argc, const char *const argv[])
Converts an argument vector into a string sequence.
LoggerPtr getProcessLogger()
Gets the per-process logger.
std::shared_ptr< SliceLoader > SliceLoaderPtr
A shared pointer to a SliceLoader.
Definition SliceLoader.h:44
ToStringMode
The output mode for xxxToString methods such as identityToString and proxyToString.
Definition StringUtil.h:18
@ Unicode
Characters with ordinal values greater than 127 are kept as-is in the resulting string.
Definition StringUtil.h:21
std::shared_ptr< Logger > LoggerPtr
A shared pointer to a Logger.
Definition Logger.h:16
std::vector< std::string > StringSeq
A sequence of strings.
void stringSeqToArgs(const StringSeq &seq, int &argc, const char *argv[])
Updates argv to match the contents of seq.
std::shared_ptr< Connection > ConnectionPtr
A shared pointer to a Connection.
Definition ConnectionF.h:18
CommunicatorPtr initialize(int &argc, const char *argv[], InitializationData initData={})
Creates a new communicator.
Identity stringToIdentity(std::string_view str)
Converts a stringified identity into an Identity.
The Ice RPC framework.
Definition SampleEvent.h:59
Represents the identity of an Ice object.
Definition Identity.h:40
Instrumentation::CommunicatorObserverPtr observer
The communicator observer used by the Ice runtime.
Definition Initialize.h:73
SliceLoaderPtr sliceLoader
The Slice loader, used to unmarshal Slice classes and exceptions.
Definition Initialize.h:113
std::function< void(std::function< void()> call, const Ice::ConnectionPtr &con)> executor
A function that the communicator calls to execute dispatches and async invocation callbacks.
Definition Initialize.h:89
std::function< void(const Ice::BatchRequest &req, int count, int size)> batchRequestInterceptor
The batch request interceptor, which is called by the Ice runtime to enqueue a batch request.
Definition Initialize.h:95
PropertiesPtr properties
The properties for the communicator.
Definition Initialize.h:67
LoggerPtr logger
The logger for the communicator.
Definition Initialize.h:70
std::function< void()> threadStop
A function that the communicator calls when it destroys a thread.
Definition Initialize.h:84
std::optional< SSL::ClientAuthenticationOptions > clientAuthenticationOptions
The authentication options for SSL client connections.
Definition Initialize.h:106
std::function< void()> threadStart
A function that the communicator calls when it starts a new thread.
Definition Initialize.h:81
std::vector< PluginFactory > pluginFactories
A list of plug-in factories.
Definition Initialize.h:110
Represents a set of options that you can specify when initializing a communicator.
Definition Initialize.h:65