Skip to content

Commit

Permalink
provide missing publish() function overload for qt (#167)
Browse files Browse the repository at this point in the history
Co-authored-by: Serhii Mamontov <parfeon@me.com>
  • Loading branch information
Xavrax and parfeon committed Nov 9, 2023
1 parent d858d8c commit c1975f2
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 12 deletions.
21 changes: 13 additions & 8 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: c-core
schema: 1
version: "4.6.0"
version: "4.6.1"
scm: github.com/pubnub/c-core
changelog:
- date: 2023-11-08
version: v4.6.1
changes:
- type: bug
text: "Provide missing `publish()` function overload for QT wrapper that allows set publish related options."
- date: 2023-10-30
version: v4.6.0
changes:
Expand Down Expand Up @@ -748,7 +753,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.6.0
location: https://github.com/pubnub/c-core/releases/tag/v4.6.1
requires:
-
name: "miniz"
Expand Down Expand Up @@ -814,7 +819,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.6.0
location: https://github.com/pubnub/c-core/releases/tag/v4.6.1
requires:
-
name: "miniz"
Expand Down Expand Up @@ -880,7 +885,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.6.0
location: https://github.com/pubnub/c-core/releases/tag/v4.6.1
requires:
-
name: "miniz"
Expand Down Expand Up @@ -942,7 +947,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.6.0
location: https://github.com/pubnub/c-core/releases/tag/v4.6.1
requires:
-
name: "miniz"
Expand Down Expand Up @@ -1003,7 +1008,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.6.0
location: https://github.com/pubnub/c-core/releases/tag/v4.6.1
requires:
-
name: "miniz"
Expand Down Expand Up @@ -1059,7 +1064,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.6.0
location: https://github.com/pubnub/c-core/releases/tag/v4.6.1
requires:
-
name: "miniz"
Expand Down Expand Up @@ -1112,7 +1117,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.6.0
location: https://github.com/pubnub/c-core/releases/tag/v4.6.1
requires:
-
name: "miniz"
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v4.6.1
November 08 2023

#### Fixed
- Provide missing `publish()` function overload for QT wrapper that allows set publish related options.

## v4.6.0
October 30 2023

Expand Down
12 changes: 10 additions & 2 deletions core/pubnub_coreapi_ex.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */
#ifndef PUBNUB_QT
#include "core/pbcc_set_state.h"
#include "core/pubnub_api_types.h"
#include "core/pubnub_coreapi.h"
#endif
#include "core/pubnub_api_types.h"
#include "pubnub_internal.h"
#include "pubnub_log.h"

#ifndef PUBNUB_QT
#include "pubnub_ccore.h"
#include "pubnub_netcore.h"
#include "pubnub_assert.h"
#include "pubnub_timers.h"
#endif
#include "pubnub_assert.h"
#include "pubnub_crypto.h"
#include "pubnub_server_limits.h"
#include "pubnub_coreapi_ex.h"
Expand All @@ -31,6 +35,8 @@ struct pubnub_publish_options pubnub_publish_defopts(void)
return result;
}

#ifndef PUBNUB_QT

enum pubnub_res pubnub_publish_ex(pubnub_t* pb,
const char* channel,
const char* message,
Expand Down Expand Up @@ -304,3 +310,5 @@ enum pubnub_res pubnub_set_state_ex(pubnub_t *p,
: pubnub_set_state(p, channel, opts.channel_group, opts.user_id, state);
}

#endif PUBNUB_QT

2 changes: 1 addition & 1 deletion core/pubnub_version_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define INC_PUBNUB_VERSION_INTERNAL


#define PUBNUB_SDK_VERSION "4.6.0"
#define PUBNUB_SDK_VERSION "4.6.1"


#endif /* !defined INC_PUBNUB_VERSION_INTERNAL */
2 changes: 1 addition & 1 deletion qt/pubnub_gui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TEMPLATE = app
QT += widgets network
CONFIG += C++11
HEADERS += pubnub_qt.h pubnub_qt_gui_sample.h
SOURCES += pubnub_qt.cpp pubnub_qt_gui_sample.cpp ../core/pubnub_ccore_pubsub.c ../core/pubnub_ccore.c ../core/pbcc_subscribe_v2.c ../core/pbcc_advanced_history.c ../core/pbcc_objects_api.c ../core/pbcc_actions_api.c ../core/pubnub_url_encode.c ../core/pubnub_assert_std.c ../core/pubnub_json_parse.c ../core/pubnub_helper.c ../lib/pbcrc32.c ../lib/pb_strnlen_s.c ../lib/pb_strncasecmp.c ../core/pubnub_memory_block.c ../core/pbcc_set_state.c
SOURCES += pubnub_qt.cpp pubnub_qt_gui_sample.cpp ../core/pubnub_ccore_pubsub.c ../core/pubnub_ccore.c ../core/pbcc_subscribe_v2.c ../core/pbcc_advanced_history.c ../core/pbcc_objects_api.c ../core/pbcc_actions_api.c ../core/pubnub_url_encode.c ../core/pubnub_assert_std.c ../core/pubnub_json_parse.c ../core/pubnub_helper.c ../lib/pbcrc32.c ../lib/pb_strnlen_s.c ../lib/pb_strncasecmp.c ../core/pubnub_memory_block.c ../core/pbcc_set_state.c ../core/pubnub_coreapi_ex.c
win32:SOURCES += ../core/c99/snprintf.c

DEFINES += PUBNUB_QT PUBNUB_QT_MOVE_TO_THREAD
Expand Down
16 changes: 16 additions & 0 deletions qt/pubnub_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,22 @@ pubnub_res pubnub_qt::publish(QString const& channel, QString const& message)
}


pubnub_res pubnub_qt::publish(QString const& channel, QString const& message, publish_options& opt)
{
QMutexLocker lk(&d_mutex);
pubnub_publish_options opt_data = opt.data();

return startRequest(pbcc_publish_prep(d_context.data(),
channel.toLatin1().data(),
message.toLatin1().data(),
opt_data.store,
!opt_data.replicate,
opt_data.meta,
opt_data.method),
PBTT_PUBLISH);
}


pubnub_res pubnub_qt::publish_via_post(QString const& channel,
QByteArray const& message)
{
Expand Down
71 changes: 71 additions & 0 deletions qt/pubnub_qt.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,65 @@ class QNetworkReply;
class QSslError;
QT_END_NAMESPACE

/** A wrapper class for publish options, enabling a nicer
usage. Something like:
pn.publish(chan, msg, publish_options().store(true).ttl(22));
*/
class publish_options {
pubnub_publish_options d_;
QString d_meta;

public:

publish_options() : d_(pubnub_publish_defopts()) {}

/** If true, the message is stored in history. If false,
the message is _not_ stored in history.
*/
publish_options& store(bool store)
{
d_.store = store;

return *this;
}

/** If `true`, the message is replicated, thus will be received by
all subscribers. If `false`, the message is _not_ replicated
and will be only delivered to BLOCK event handlers. Setting
`false` here and `false` on store is sometimes referred to as
a "fire" (instead of a "publish").
*/
publish_options& replicate(bool replicate)
{
d_.replicate = replicate;

return *this;
}

/** An optional JSON object, used to send additional ("meta") data
about the message, which can be used for stream filtering.
*/
publish_options& meta(QString const& meta)
{
d_meta = meta;
d_.meta = d_meta.isEmpty() ? 0 : d_meta.toLatin1().data();

return *this;
}

/** Defines the method by which publish transaction will be performed */
publish_options& method(pubnub_method method)
{
d_.method = method;

return *this;
}

pubnub_publish_options data() { return d_; }
};


/** A wrapper class for set_state options, enabling a nicer
usage. Something like:
Expand Down Expand Up @@ -613,6 +672,18 @@ class pubnub_qt : public QObject
*/
pubnub_res publish(QString const &channel, QString const &message);

/** Publish the @p message (in JSON format) on @p p channel, using the
@p p context. This actually means "initiate a publish
transaction".
This function is similar to casual publish, but it allows you to
specify additional options for the publish operation.
See @publish and @p publish_options for more details.
*/
pubnub_res publish(QString const &channel, QString const &message, publish_options& opt);


/** Function that initiates 'publish' transaction via POST method
@param channel The string with the channel
@param message The message to publish, expected to be in JSON format
Expand Down

0 comments on commit c1975f2

Please sign in to comment.