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 "Properties.h"
16#include "SSL/ClientAuthenticationOptions.h"
17#include "SliceLoader.h"
18#include "StringUtil.h"
19#include "TimerTask.h"
20
21#include <algorithm>
22
23namespace Ice
24{
25 /// Represents a set of options that you can specify when initializing a communicator.
26 /// @headerfile Ice/Ice.h
28 {
29 /// The properties for the communicator.
30 /// When not-null, this corresponds to the object returned by the Communicator::getProperties function.
32
33 /// The logger for the communicator.
35
36 /// The communicator observer used by the Ice runtime.
38
39#if defined(__clang__)
40# pragma clang diagnostic push
41# pragma clang diagnostic ignored "-Wdocumentation" // param/return is not recognized for std::function data members
42#endif
43
44 /// A function that the communicator calls when it starts a new thread.
45 std::function<void()> threadStart{};
46
47 /// A function that the communicator calls when it destroys a thread.
48 std::function<void()> threadStop{};
49
50 /// A function that the communicator calls to execute dispatches and async invocation callbacks.
51 /// @param call Represents the function to execute. The executor must eventually execute this function.
52 /// @param con The connection associated with this call. May be null.
53 std::function<void(std::function<void()> call, const Ice::ConnectionPtr& con)> executor{};
54
55 /// The batch request interceptor, which is called by the Ice runtime to enqueue a batch request.
56 /// @param req An object representing the batch request.
57 /// @param count The number of requests currently in the queue.
58 /// @param size The number of bytes consumed by the requests currently in the queue.
59 std::function<void(const Ice::BatchRequest& req, int count, int size)> batchRequestInterceptor{};
60
61#if defined(__clang__)
62# pragma clang diagnostic pop
63#endif
64
65 /// The authentication options for SSL client connections. When set, the SSL transport ignores all IceSSL
66 /// configuration properties and uses these options.
67 /// @see SSL::OpenSSLClientAuthenticationOptions
68 /// @see SSL::SecureTransportClientAuthenticationOptions
69 /// @see SSL::SchannelClientAuthenticationOptions
70 std::optional<SSL::ClientAuthenticationOptions> clientAuthenticationOptions{};
71
72 /// A list of plug-in factories. The corresponding plug-ins are created during communicator initialization,
73 /// in order, before all other plug-ins.
74 std::vector<PluginFactory> pluginFactories{};
75
76 /// The Slice loader, used to unmarshal Slice classes and exceptions.
78 };
79
80 /// Creates a new communicator.
81 /// @param initData Options for the new communicator.
82 /// @return The new communicator.
83 /// @remark This is the main initialize function. All other overloads are provided for convenience and call this
84 /// function.
86
87 /// Creates a new communicator, using Ice properties parsed from the command-line arguments.
88 /// @tparam ArgvT The type of the argument vector, such as char**, const char**, or wchar_t** (on Windows).
89 /// @param[in,out] argc The number of arguments in @p argv. When this function parses properties from @p argv, it
90 /// reshuffles the arguments so that the remaining arguments start at the beginning of @p argv, and updates @p argc
91 /// accordingly.
92 /// @param argv The command-line arguments. This function parses arguments starting with `--` and one of the
93 /// reserved prefixes (Ice, IceSSL, etc.) as properties for the new communicator. If there is an argument starting
94 /// with `--Ice.Config`, this function loads the specified configuration file. When the same property is set in a
95 /// configuration file and through a command-line argument, the command-line setting takes precedence.
96 /// @return The new communicator.
97 template<typename ArgvT> inline CommunicatorPtr initialize(int& argc, ArgvT argv)
98 {
99 auto properties = std::make_shared<Properties>(argc, argv);
100 if (properties->getProperty("Ice.ProgramName").empty() && argc > 0)
101 {
102 StringSeq args = argsToStringSeq(argc, argv);
103 std::string programName = args[0];
104 // Replace any backslashes in this value with forward slashes, in case this value is used by the event
105 // logger.
106 std::replace(programName.begin(), programName.end(), '\\', '/');
107 properties->setProperty("Ice.ProgramName", std::move(programName));
108 }
109
110 InitializationData initData;
111 initData.properties = properties;
112 return initialize(std::move(initData));
113 }
114
115 /// Gets the per-process logger. This logger is used by all communicators that do not have their own specific logger
116 /// configured at the time the communicator is created.
117 /// @return The current per-process logger instance.
119
120 /// Sets the per-process logger. This logger is used by all communicators that do not have their own specific logger
121 /// configured at the time the communicator is created.
122 /// @param logger The new per-process logger instance.
123 ICE_API void setProcessLogger(const LoggerPtr& logger);
124
125 /// Converts a stringified identity into an Identity.
126 /// @param str The stringified identity.
127 /// @return An Identity containing the name and category components.
128 ICE_API Identity stringToIdentity(std::string_view str);
129
130 /// Converts an Identity into a string using the specified mode.
131 /// @param id The identity.
132 /// @param mode Specifies how to handle non-ASCII characters and non-printable ASCII characters.
133 /// @return The stringified identity.
134 ICE_API std::string identityToString(const Identity& id, ToStringMode mode = ToStringMode::Unicode);
135}
136
137namespace IceInternal
138{
139 ICE_API InstancePtr getInstance(const Ice::CommunicatorPtr&);
140 ICE_API TimerPtr getInstanceTimer(const Ice::CommunicatorPtr&);
141}
142
143#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.
std::shared_ptr< Connection > ConnectionPtr
A shared pointer to a Connection.
Definition ConnectionF.h:18
CommunicatorPtr initialize(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:37
SliceLoaderPtr sliceLoader
The Slice loader, used to unmarshal Slice classes and exceptions.
Definition Initialize.h:77
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:53
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:59
PropertiesPtr properties
The properties for the communicator.
Definition Initialize.h:31
LoggerPtr logger
The logger for the communicator.
Definition Initialize.h:34
std::function< void()> threadStop
A function that the communicator calls when it destroys a thread.
Definition Initialize.h:48
std::optional< SSL::ClientAuthenticationOptions > clientAuthenticationOptions
The authentication options for SSL client connections.
Definition Initialize.h:70
std::function< void()> threadStart
A function that the communicator calls when it starts a new thread.
Definition Initialize.h:45
std::vector< PluginFactory > pluginFactories
A list of plug-in factories.
Definition Initialize.h:74
Represents a set of options that you can specify when initializing a communicator.
Definition Initialize.h:28