Skip to content

C++ client: string_t to string #8063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/SignalR/clients/cpp/include/signalrclient/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace signalr
class connection
{
public:
typedef std::function<void __cdecl(const utility::string_t&)> message_received_handler;
typedef std::function<void __cdecl(const std::string&)> message_received_handler;

SIGNALRCLIENT_API explicit connection(const utility::string_t& url, trace_level trace_level = trace_level::all, std::shared_ptr<log_writer> log_writer = nullptr);
SIGNALRCLIENT_API explicit connection(const std::string& url, trace_level trace_level = trace_level::all, std::shared_ptr<log_writer> log_writer = nullptr);

SIGNALRCLIENT_API ~connection();

Expand All @@ -31,7 +31,7 @@ namespace signalr

SIGNALRCLIENT_API pplx::task<void> __cdecl start();

SIGNALRCLIENT_API pplx::task<void> __cdecl send(const utility::string_t& data);
SIGNALRCLIENT_API pplx::task<void> __cdecl send(const std::string& data);

SIGNALRCLIENT_API void __cdecl set_message_received(const message_received_handler& message_received_callback);
SIGNALRCLIENT_API void __cdecl set_disconnected(const std::function<void __cdecl()>& disconnected_callback);
Expand All @@ -41,7 +41,7 @@ namespace signalr
SIGNALRCLIENT_API pplx::task<void> __cdecl stop();

SIGNALRCLIENT_API connection_state __cdecl get_connection_state() const noexcept;
SIGNALRCLIENT_API utility::string_t __cdecl get_connection_id() const;
SIGNALRCLIENT_API std::string __cdecl get_connection_id() const;

private:
// The recommended smart pointer to use when doing pImpl is the `std::unique_ptr`. However
Expand Down
10 changes: 5 additions & 5 deletions src/SignalR/clients/cpp/include/signalrclient/hub_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace signalr
public:
typedef std::function<void __cdecl (const web::json::value&)> method_invoked_handler;

SIGNALRCLIENT_API explicit hub_connection(const utility::string_t& url, trace_level trace_level = trace_level::all,
SIGNALRCLIENT_API explicit hub_connection(const std::string& url, trace_level trace_level = trace_level::all,
std::shared_ptr<log_writer> log_writer = nullptr);

SIGNALRCLIENT_API ~hub_connection();
Expand All @@ -35,17 +35,17 @@ namespace signalr
SIGNALRCLIENT_API pplx::task<void> __cdecl stop();

SIGNALRCLIENT_API connection_state __cdecl get_connection_state() const;
SIGNALRCLIENT_API utility::string_t __cdecl get_connection_id() const;
SIGNALRCLIENT_API std::string __cdecl get_connection_id() const;

SIGNALRCLIENT_API void __cdecl set_disconnected(const std::function<void __cdecl()>& disconnected_callback);

SIGNALRCLIENT_API void __cdecl set_client_config(const signalr_client_config& config);

SIGNALRCLIENT_API void __cdecl on(const utility::string_t& event_name, const method_invoked_handler& handler);
SIGNALRCLIENT_API void __cdecl on(const std::string& event_name, const method_invoked_handler& handler);

SIGNALRCLIENT_API pplx::task<web::json::value> invoke(const utility::string_t& method_name, const web::json::value& arguments = web::json::value::array());
SIGNALRCLIENT_API pplx::task<web::json::value> invoke(const std::string& method_name, const web::json::value& arguments = web::json::value::array());

SIGNALRCLIENT_API pplx::task<void> send(const utility::string_t& method_name, const web::json::value& arguments = web::json::value::array());
SIGNALRCLIENT_API pplx::task<void> send(const std::string& method_name, const web::json::value& arguments = web::json::value::array());

private:
std::shared_ptr<hub_connection_impl> m_pImpl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@

#include <stdexcept>
#include "signalr_exception.h"
#include "cpprest/details/basic_types.h"

namespace signalr
{
class hub_exception : public signalr_exception
{
public:
hub_exception(const utility::string_t &what)
hub_exception(const std::string &what)
: signalr_exception(what)
{}
};
Expand Down
6 changes: 2 additions & 4 deletions src/SignalR/clients/cpp/include/signalrclient/log_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

#pragma once

#include "cpprest/details/basic_types.h"

namespace signalr
{
class log_writer
{
public:
// NOTE: the caller does not enforce thread safety of this call
virtual void __cdecl write(const utility::string_t &entry) = 0;
virtual void __cdecl write(const std::string &entry) = 0;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
#pragma once

#include <stdexcept>
#include "cpprest/details/basic_types.h"
#include "cpprest/asyncrt_utils.h"

namespace signalr
{
class signalr_exception : public std::runtime_error
{
public:
explicit signalr_exception(const utility::string_t &what)
: runtime_error(utility::conversions::to_utf8string(what))
explicit signalr_exception(const std::string &what)
: runtime_error(what)
{}
};
}
6 changes: 2 additions & 4 deletions src/SignalR/clients/cpp/include/signalrclient/web_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
#pragma once

#include <stdexcept>
#include "cpprest/details/basic_types.h"
#include "cpprest/asyncrt_utils.h"

namespace signalr
{
class web_exception : public std::runtime_error
{
public:
web_exception(const utility::string_t &what, unsigned short status_code)
: runtime_error(utility::conversions::to_utf8string(what)), m_status_code(status_code)
web_exception(const std::string &what, unsigned short status_code)
: runtime_error(what), m_status_code(status_code)
{}

unsigned short status_code() const noexcept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
class logger : public signalr::log_writer
{
// Inherited via log_writer
virtual void __cdecl write(const utility::string_t & entry) override
virtual void __cdecl write(const std::string & entry) override
{
//std::cout << utility::conversions::to_utf8string(entry) << std::endl;
}
};

void send_message(signalr::hub_connection& connection, const utility::string_t& name, const utility::string_t& message)
void send_message(signalr::hub_connection& connection, const std::string& name, const std::string& message)
{
web::json::value args{};
args[0] = web::json::value::string(name);
args[1] = web::json::value(message);
args[0] = web::json::value::string(utility::conversions::to_string_t(name));
args[1] = web::json::value(utility::conversions::to_string_t(message));

// if you get an internal compiler error uncomment the lambda below or install VS Update 4
connection.invoke(U("Invoke"), args/*, [](const web::json::value&){}*/)
connection.invoke("Invoke", args/*, [](const web::json::value&){}*/)
.then([](pplx::task<web::json::value> invoke_task) // fire and forget but we need to observe exceptions
{
try
Expand All @@ -39,10 +39,10 @@ void send_message(signalr::hub_connection& connection, const utility::string_t&
});
}

void chat(const utility::string_t& name)
void chat(const std::string& name)
{
signalr::hub_connection connection(U("http://localhost:5000/default"), signalr::trace_level::all, std::make_shared<logger>());
connection.on(U("Send"), [](const web::json::value& m)
signalr::hub_connection connection("http://localhost:5000/default", signalr::trace_level::all, std::make_shared<logger>());
connection.on("Send", [](const web::json::value& m)
{
ucout << std::endl << m.at(0).as_string() << /*U(" wrote:") << m.at(1).as_string() <<*/ std::endl << U("Enter your message: ");
});
Expand All @@ -53,10 +53,10 @@ void chat(const utility::string_t& name)
ucout << U("Enter your message:");
for (;;)
{
utility::string_t message;
std::getline(ucin, message);
std::string message;
std::getline(std::cin, message);

if (message == U(":q"))
if (message == ":q")
{
break;
}
Expand Down Expand Up @@ -85,8 +85,8 @@ void chat(const utility::string_t& name)
int main()
{
ucout << U("Enter your name: ");
utility::string_t name;
std::getline(ucin, name);
std::string name;
std::getline(std::cin, name);

chat(name);

Expand Down
10 changes: 5 additions & 5 deletions src/SignalR/clients/cpp/src/signalrclient/callback_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace signalr
}

// note: callback must not throw except for the `on_progress` callback which will never be invoked from the dtor
utility::string_t callback_manager::register_callback(const std::function<void(const web::json::value&)>& callback)
std::string callback_manager::register_callback(const std::function<void(const web::json::value&)>& callback)
{
auto callback_id = get_callback_id();

Expand All @@ -33,7 +33,7 @@ namespace signalr


// invokes a callback and stops tracking it if remove callback set to true
bool callback_manager::invoke_callback(const utility::string_t& callback_id, const web::json::value& arguments, bool remove_callback)
bool callback_manager::invoke_callback(const std::string& callback_id, const web::json::value& arguments, bool remove_callback)
{
std::function<void(const web::json::value& arguments)> callback;

Expand All @@ -58,7 +58,7 @@ namespace signalr
return true;
}

bool callback_manager::remove_callback(const utility::string_t& callback_id)
bool callback_manager::remove_callback(const std::string& callback_id)
{
{
std::lock_guard<std::mutex> lock(m_map_lock);
Expand All @@ -81,10 +81,10 @@ namespace signalr
}
}

utility::string_t callback_manager::get_callback_id()
std::string callback_manager::get_callback_id()
{
const auto callback_id = m_id++;
utility::stringstream_t ss;
std::stringstream ss;
ss << callback_id;
return ss.str();
}
Expand Down
10 changes: 5 additions & 5 deletions src/SignalR/clients/cpp/src/signalrclient/callback_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ namespace signalr
callback_manager(const callback_manager&) = delete;
callback_manager& operator=(const callback_manager&) = delete;

utility::string_t register_callback(const std::function<void(const web::json::value&)>& callback);
bool invoke_callback(const utility::string_t& callback_id, const web::json::value& arguments, bool remove_callback);
bool remove_callback(const utility::string_t& callback_id);
std::string register_callback(const std::function<void(const web::json::value&)>& callback);
bool invoke_callback(const std::string& callback_id, const web::json::value& arguments, bool remove_callback);
bool remove_callback(const std::string& callback_id);
void clear(const web::json::value& arguments);

private:
std::atomic<int> m_id { 0 };
std::unordered_map<utility::string_t, std::function<void(const web::json::value&)>> m_callbacks;
std::unordered_map<std::string, std::function<void(const web::json::value&)>> m_callbacks;
std::mutex m_map_lock;
const web::json::value m_dtor_clear_arguments;

utility::string_t get_callback_id();
std::string get_callback_id();
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace signalr
// Note: These functions are not pretending to be all-purpose helpers for case insensitive string comparison. Rather
// we use them to compare hub and hub method names which are expected to be almost exclusively ASCII and this is the
// simplest thing that would work without having to take dependencies on third party libraries.
struct case_insensitive_equals : std::binary_function<utility::string_t, utility::string_t, bool>
struct case_insensitive_equals : std::binary_function<std::string, std::string, bool>
{
bool operator()(const utility::string_t& s1, const utility::string_t& s2) const
bool operator()(const std::string& s1, const std::string& s2) const
{
if (s1.length() != s2.length())
{
Expand All @@ -33,9 +33,9 @@ namespace signalr
}
};

struct case_insensitive_hash : std::unary_function<utility::string_t, std::size_t>
struct case_insensitive_hash : std::unary_function<std::string, std::size_t>
{
std::size_t operator()(const utility::string_t& s) const noexcept
std::size_t operator()(const std::string& s) const noexcept
{
size_t hash = 0;
std::hash<size_t> hasher;
Expand Down
6 changes: 3 additions & 3 deletions src/SignalR/clients/cpp/src/signalrclient/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace signalr
{
connection::connection(const utility::string_t& url, trace_level trace_level, std::shared_ptr<log_writer> log_writer)
connection::connection(const std::string& url, trace_level trace_level, std::shared_ptr<log_writer> log_writer)
: m_pImpl(connection_impl::create(url, trace_level, std::move(log_writer)))
{}

Expand All @@ -21,7 +21,7 @@ namespace signalr
return m_pImpl->start();
}

pplx::task<void> connection::send(const utility::string_t& data)
pplx::task<void> connection::send(const std::string& data)
{
return m_pImpl->send(data);
}
Expand Down Expand Up @@ -51,7 +51,7 @@ namespace signalr
return m_pImpl->get_connection_state();
}

utility::string_t connection::get_connection_id() const
std::string connection::get_connection_id() const
{
return m_pImpl->get_connection_id();
}
Expand Down
Loading