Skip to content

Commit

Permalink
Build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
externl committed May 29, 2024
1 parent 6ed7add commit 9208c1b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ jobs:
timeout-minutes: 30
with:
working_directory: ice-demos/cpp
msbuild_project: C++ demos.sln
msbuild_project: "C++ demos.sln"
51 changes: 25 additions & 26 deletions cpp/IceBT/talk/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// Copyright (c) ZeroC, Inc. All rights reserved.
//

#include "Talk.h"
#include <Ice/Ice.h>
#include <IceBT/IceBT.h>
#include <Talk.h>
#include <iostream>
#include <mutex>

using namespace std;
Expand All @@ -14,7 +15,7 @@ class TalkApp
public:
int run(const shared_ptr<Ice::Communicator>& communicator);

void connect(const shared_ptr<Talk::PeerPrx>&);
void connect(const optional<Talk::PeerPrx>&);
void message(const string&);
void disconnect(const Ice::Identity&, const shared_ptr<Ice::Connection>&, bool);
void closed();
Expand All @@ -29,27 +30,27 @@ class TalkApp

shared_ptr<Ice::Communicator> _communicator;
shared_ptr<Ice::ObjectAdapter> _adapter;
shared_ptr<Talk::PeerPrx> _local;
shared_ptr<Talk::PeerPrx> _remote;
optional<Talk::PeerPrx> _local;
optional<Talk::PeerPrx> _remote;
mutex _mutex;
};

//
// This servant listens for incoming connections from peers.
//
class IncomingPeerI : public Talk::Peer
class IncomingPeerI final : public Talk::Peer
{
public:
IncomingPeerI(TalkApp* app) : _app(app) {}

virtual void connect(shared_ptr<Talk::PeerPrx> peer, const Ice::Current& current) override
void connect(optional<Talk::PeerPrx> peer, const Ice::Current& current) final
{
_app->connect(peer->ice_fixed(current.con));
}

virtual void send(string text, const Ice::Current&) override { _app->message(text); }
void send(string text, const Ice::Current&) final { _app->message(text); }

virtual void disconnect(const Ice::Current& current) override { _app->disconnect(current.id, current.con, true); }
void disconnect(const Ice::Current& current) final { _app->disconnect(current.id, current.con, true); }

private:
TalkApp* _app;
Expand All @@ -58,19 +59,19 @@ class IncomingPeerI : public Talk::Peer
//
// This servant handles an outgoing session with a peer.
//
class OutgoingPeerI : public Talk::Peer
class OutgoingPeerI final : public Talk::Peer
{
public:
OutgoingPeerI(TalkApp* app) : _app(app) {}

virtual void connect(shared_ptr<Talk::PeerPrx>, const Ice::Current&) override
void connect(optional<Talk::PeerPrx>, const Ice::Current&) final
{
throw Talk::ConnectionException("already connected");
}

virtual void send(string text, const Ice::Current&) override { _app->message(text); }
void send(string text, const Ice::Current&) final { _app->message(text); }

virtual void disconnect(const Ice::Current& current) override { _app->disconnect(current.id, current.con, false); }
void disconnect(const Ice::Current& current) final { _app->disconnect(current.id, current.con, false); }

private:
TalkApp* _app;
Expand Down Expand Up @@ -190,7 +191,7 @@ TalkApp::run(const shared_ptr<Ice::Communicator>& communicator)
}

void
TalkApp::connect(const shared_ptr<Talk::PeerPrx>& peer)
TalkApp::connect(const optional<Talk::PeerPrx>& peer)
{
//
// Called for a new incoming connection request.
Expand All @@ -208,7 +209,6 @@ TalkApp::connect(const shared_ptr<Talk::PeerPrx>& peer)
//
auto con = peer->ice_getConnection();
con->setCloseCallback([this](const shared_ptr<Ice::Connection>&) { this->closed(); });
con->setACM(30, Ice::ACMClose::CloseOff, Ice::ACMHeartbeat::HeartbeatAlways);

_remote = peer->ice_invocationTimeout(10000);

Expand Down Expand Up @@ -241,7 +241,7 @@ TalkApp::disconnect(const Ice::Identity& id, const shared_ptr<Ice::Connection>&
if (_remote)
{
cout << ">>>> Peer disconnected" << endl;
_remote = nullptr;
_remote = nullopt;
}

if (!incoming)
Expand All @@ -257,7 +257,7 @@ TalkApp::closed()
{
lock_guard<mutex> lock(_mutex);

_remote = nullptr;
_remote = nullopt;

cout << ">>>> Connection to peer closed" << endl;
}
Expand All @@ -281,8 +281,8 @@ TalkApp::doConnect(const string& cmd)
}
string addr = cmd.substr(sp);

shared_ptr<Talk::PeerPrx> remote;
shared_ptr<Talk::PeerPrx> local;
optional<Talk::PeerPrx> remote;
optional<Talk::PeerPrx> local;
try
{
{
Expand Down Expand Up @@ -326,7 +326,6 @@ TalkApp::doConnect(const string& cmd)
// Install a connection callback and enable ACM heartbeats.
//
con->setCloseCallback([this](const shared_ptr<Ice::Connection>&) { this->closed(); });
con->setACM(30, Ice::ACMClose::CloseOff, Ice::ACMHeartbeat::HeartbeatAlways);

//
// Now we're ready to notify the peer that we'd like to connect.
Expand All @@ -346,7 +345,7 @@ TalkApp::doConnect(const string& cmd)

if (_remote == remote)
{
_remote = nullptr;
_remote = nullopt;
}
}
catch (const Ice::Exception& ex)
Expand All @@ -361,7 +360,7 @@ TalkApp::doConnect(const string& cmd)

if (_remote == remote)
{
_remote = nullptr;
_remote = nullopt;
}
}
}
Expand Down Expand Up @@ -406,7 +405,7 @@ TalkApp::doList()
void
TalkApp::doDisconnect()
{
shared_ptr<Talk::PeerPrx> peer;
optional<Talk::PeerPrx> peer;

{
lock_guard<mutex> lock(_mutex);
Expand All @@ -418,7 +417,7 @@ TalkApp::doDisconnect()
}

peer = _remote;
_remote = nullptr;
_remote = nullopt;
}

auto con = peer->ice_getCachedConnection();
Expand All @@ -441,7 +440,7 @@ TalkApp::doDisconnect()
void
TalkApp::doMessage(const string& text)
{
shared_ptr<Talk::PeerPrx> peer;
optional<Talk::PeerPrx> peer;

{
lock_guard<mutex> lock(_mutex);
Expand All @@ -468,12 +467,12 @@ TalkApp::doMessage(const string& text)
void
TalkApp::failed(const Ice::LocalException& ex)
{
shared_ptr<Talk::PeerPrx> peer;
optional<Talk::PeerPrx> peer;

{
lock_guard<mutex> lock(_mutex);
peer = _remote;
_remote = nullptr;
_remote = nullopt;
}

cout << ">>>> Action failed:" << endl << ex << endl;
Expand Down

0 comments on commit 9208c1b

Please sign in to comment.