Ice 3.8
C++ API Reference
Loading...
Searching...
No Matches
ImplicitContext.h
1// Copyright (c) ZeroC, Inc.
2
3#ifndef ICE_IMPLICIT_CONTEXT_H
4#define ICE_IMPLICIT_CONTEXT_H
5
6#include "Config.h"
7#include "Ice/Context.h"
8
9#include <memory>
10#include <mutex>
11#include <string>
12
13namespace Ice
14{
15 class OutputStream;
16
17 /// Represents the request context associated with a communicator.
18 /// When you make a remote invocation without an explicit request context parameter, Ice uses the per-proxy request
19 /// context (if any) combined with the `ImplicitContext` associated with your communicator. The property
20 /// `Ice.ImplicitContext` controls if your communicator has an associated implicit context, and when it does,
21 /// whether this implicit context is per-thread or shared by all threads.
22 /// @headerfile Ice/Ice.h
23 class ICE_API ImplicitContext final
24 {
25 public:
26 /// Gets a copy of the request context maintained by this object.
27 /// @return A copy of the request context.
28 [[nodiscard]] Context getContext() const;
29
30 /// Sets the request context.
31 /// @param newContext The new request context.
32 void setContext(Context newContext);
33
34 /// Checks if this key has an associated value in the request context.
35 /// @param key The key.
36 /// @return `true` if the key has an associated value, `false` otherwise.
37 [[nodiscard]] bool containsKey(std::string_view key) const;
38
39 /// Gets the value associated with the specified key in the request context.
40 /// @param key The key.
41 /// @return The value associated with the key, or the empty string if no value is associated with the key.
42 [[nodiscard]] std::string get(std::string_view key) const;
43
44 /// Creates or updates a key/value entry in the request context.
45 /// @param key The key.
46 /// @param value The value.
47 /// @return The previous value associated with the key, if any.
48 std::string put(std::string key, std::string value);
49
50 /// Removes the entry for the specified key in the request context.
51 /// @param key The key.
52 /// @return The value associated with the key, if any.
53 std::string remove(std::string_view key);
54
55 /// Marshals this request context plus the specified request context. Entries in @p context overwrite entries
56 /// in this request context.
57 /// @param context The request context to write to the output stream.
58 /// @param os The output stream.
59 void write(const Context& context, Ice::OutputStream* os) const;
60
61 /// Combines this request context plus the specified request context. Entries in @p context overwrite entries in
62 /// this request context.
63 /// @param context The request context to combine with this request context.
64 /// @param combined The combined request context.
65 void combine(const Context& context, Context& combined) const;
66
67 private:
68 mutable std::mutex _mutex;
69 Context _context;
70 };
71
72 /// A shared pointer to an ImplicitContext.
73 using ImplicitContextPtr = std::shared_ptr<ImplicitContext>;
74}
75
76#endif
std::string remove(std::string_view key)
Removes the entry for the specified key in the request context.
std::string put(std::string key, std::string value)
Creates or updates a key/value entry in the request context.
std::string get(std::string_view key) const
Gets the value associated with the specified key in the request context.
void combine(const Context &context, Context &combined) const
Combines this request context plus the specified request context.
bool containsKey(std::string_view key) const
Checks if this key has an associated value in the request context.
void write(const Context &context, Ice::OutputStream *os) const
Marshals this request context plus the specified request context.
void setContext(Context newContext)
Sets the request context.
Context getContext() const
Gets a copy of the request context maintained by this object.
Represents the request context associated with a communicator.
Represents a byte buffer used for marshaling data using the Slice encoding.
std::shared_ptr< ImplicitContext > ImplicitContextPtr
A shared pointer to an ImplicitContext.
std::map< std::string, std::string, std::less<> > Context
Represents additional information carried by an Ice request.
Definition Context.h:28
The Ice RPC framework.
Definition SampleEvent.h:59