Skip to content
Snippets Groups Projects
Commit ad9d0c47 authored by Craig Tiller's avatar Craig Tiller
Browse files

Remove dynamic_cast

parent 42bc87c0
No related branches found
No related tags found
No related merge requests found
......@@ -42,11 +42,19 @@
namespace grpc {
class ChannelArguments;
class ChannelInterface;
class SecureCredentials;
class Credentials {
public:
virtual ~Credentials();
protected:
friend std::unique_ptr<Credentials> ComposeCredentials(
const std::unique_ptr<Credentials>& creds1,
const std::unique_ptr<Credentials>& creds2);
virtual SecureCredentials* AsSecureCredentials() = 0;
private:
friend std::shared_ptr<ChannelInterface> CreateChannel(
const grpc::string& target, const std::unique_ptr<Credentials>& creds,
......
......@@ -50,6 +50,8 @@ class InsecureCredentialsImpl final : public Credentials {
args.SetChannelArgs(&channel_args);
return std::shared_ptr<ChannelInterface>(new Channel(target, grpc_channel_create(target.c_str(), &channel_args)));
}
SecureCredentials* AsSecureCredentials() { return nullptr; }
};
} // namespace
......
......@@ -42,7 +42,6 @@
namespace grpc {
namespace {
class SecureCredentials final : public Credentials {
public:
explicit SecureCredentials(grpc_credentials* c_creds) : c_creds_(c_creds) {}
......@@ -58,10 +57,15 @@ class SecureCredentials final : public Credentials {
grpc_secure_channel_create(c_creds_, target.c_str(), &channel_args)));
}
SecureCredentials* AsSecureCredentials() {
return this;
}
private:
grpc_credentials* const c_creds_;
};
namespace {
std::unique_ptr<Credentials> WrapCredentials(grpc_credentials* creds) {
return creds == nullptr
? nullptr
......@@ -116,8 +120,8 @@ std::unique_ptr<Credentials> ComposeCredentials(
// passed in here. This is OK because the underlying C objects (i.e.,
// creds1 and creds2) into grpc_composite_credentials_create will see their
// refcounts incremented.
SecureCredentials* s1 = dynamic_cast<SecureCredentials*>(creds1.get());
SecureCredentials* s2 = dynamic_cast<SecureCredentials*>(creds2.get());
SecureCredentials* s1 = creds1->AsSecureCredentials();
SecureCredentials* s2 = creds2->AsSecureCredentials();
if (s1 && s2) {
return WrapCredentials(grpc_composite_credentials_create(
s1->GetRawCreds(), s2->GetRawCreds()));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment