Skip to content

Commit fab3f6f

Browse files
committed
Add a user interface with a custom name prefix.
1 parent 16b138d commit fab3f6f

File tree

13 files changed

+160
-143
lines changed

13 files changed

+160
-143
lines changed

include/libipc/def.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,9 @@ struct relat_trait<wr<Rp, Rc, Ts>> {
6565
template <template <typename> class Policy, typename Flag>
6666
struct relat_trait<Policy<Flag>> : relat_trait<Flag> {};
6767

68+
// the prefix tag of a channel
69+
struct prefix {
70+
char const *str;
71+
};
72+
6873
} // namespace ipc

include/libipc/ipc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct IPC_EXPORT chan_impl {
2222
static ipc::handle_t inited();
2323

2424
static bool connect (ipc::handle_t * ph, char const * name, unsigned mode);
25+
static bool connect (ipc::handle_t * ph, prefix, char const * name, unsigned mode);
2526
static bool reconnect (ipc::handle_t * ph, unsigned mode);
2627
static void disconnect(ipc::handle_t h);
2728
static void destroy (ipc::handle_t h);
@@ -54,6 +55,10 @@ class chan_wrapper {
5455
: connected_{this->connect(name, mode)} {
5556
}
5657

58+
chan_wrapper(prefix pref, char const * name, unsigned mode = ipc::sender)
59+
: connected_{this->connect(pref, name, mode)} {
60+
}
61+
5762
chan_wrapper(chan_wrapper&& rhs) noexcept
5863
: chan_wrapper{} {
5964
swap(rhs);
@@ -102,6 +107,11 @@ class chan_wrapper {
102107
detail_t::disconnect(h_); // clear old connection
103108
return connected_ = detail_t::connect(&h_, name, mode_ = mode);
104109
}
110+
bool connect(prefix pref, char const * name, unsigned mode = ipc::sender | ipc::receiver) {
111+
if (name == nullptr || name[0] == '\0') return false;
112+
detail_t::disconnect(h_); // clear old connection
113+
return connected_ = detail_t::connect(&h_, pref, name, mode_ = mode);
114+
}
105115

106116
/**
107117
* Try connecting with new mode flags.

src/libipc/circ/elem_array.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class elem_array : public ipc::circ::conn_head<Policy> {
3737
elem_t block_[elem_max] {};
3838

3939
/**
40-
* @remarks 'warning C4348: redefinition of default parameter' with MSVC.
41-
* @see
40+
* \remarks 'warning C4348: redefinition of default parameter' with MSVC.
41+
* \see
4242
* - https://stackoverflow.com/questions/12656239/redefinition-of-default-template-parameter
4343
* - https://developercommunity.visualstudio.com/content/problem/425978/incorrect-c4348-warning-in-nested-template-declara.html
4444
*/

0 commit comments

Comments
 (0)