Skip to content

Commit

Permalink
Create Interface for AudioManagers, and refactor to use that instead …
Browse files Browse the repository at this point in the history
…of sigc++
  • Loading branch information
silverchris committed Aug 6, 2022
1 parent 40916f1 commit afcfccc
Show file tree
Hide file tree
Showing 12 changed files with 212 additions and 167 deletions.
20 changes: 12 additions & 8 deletions include/autoapp/Managers/AudioManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <dbus-cxx.h>
#include <nlohmann/json.hpp>

#include <autoapp/Signals/AudioSignals.hpp>
#include <autoapp/Managers/IAudioManager.hpp>

#include <com_xsembedded_ServiceProvider_objectProxy.h>

Expand All @@ -21,20 +21,21 @@ struct Stream {
std::string type;
};

class AudioManagerClient {
class AudioManager: public IAudioManager {
private:
AudioSignals::Pointer audiosignals_;
bool inCall = false;
std::vector<std::string> MazdaDestinations;
std::map<aasdk::messenger::ChannelId, Stream *> streams;
// std::map<std::string, int> ExistingStreams;
std::map<int, Stream *> streamsByID;

std::shared_ptr<DBus::Connection> dbusConnection;
std::shared_ptr<com_xsembedded_ServiceProvider_objectProxy> AudioInterface;
std::shared_ptr<com_xsembedded_ServiceProviderProxy> AudioProxy;
std::shared_ptr<DBus::Object> AudioObject;
std::shared_ptr<DBus::Interface> AudioRequestInterface;

std::shared_ptr<DBus::Connection> connection;
sigc::connection notifyConnection;

std::shared_ptr<DBus::ObjectProxy> object;

Expand All @@ -52,14 +53,17 @@ class AudioManagerClient {
std::string RequestHandler(const std::string &methodName, const std::string &arguments);

public:
AudioManagerClient(AudioSignals::Pointer audiosignals, const std::shared_ptr<DBus::Connection> &);
AudioManager(const std::shared_ptr<DBus::Connection> &);

~AudioManagerClient();
~AudioManager();

void start() override;
void stop() override;

//calling requestAudioFocus directly doesn't work on the audio mgr
void audioMgrRequestAudioFocus(aasdk::messenger::ChannelId, aasdk::proto::enums::AudioFocusType_Enum aa_type);
void requestFocus(aasdk::messenger::ChannelId channelId, aasdk::proto::enums::AudioFocusType_Enum aa_type) override;

void audioMgrReleaseAudioFocus(aasdk::messenger::ChannelId);
void releaseFocus(aasdk::messenger::ChannelId channelId) override;

static void onNotify(const std::string &signalName, const std::string &payload);

Expand Down
40 changes: 40 additions & 0 deletions include/autoapp/Managers/IAudioManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include <vector>
#include <autoapp/Managers/IManager.hpp>
#include <aasdk_proto/AudioFocusStateEnum.pb.h>
#include <aasdk_proto/AudioFocusTypeEnum.pb.h>
#include <aasdk/Messenger/ChannelId.hpp>



class IAudioManager: public IManager{
public:
using Pointer = std::shared_ptr<IAudioManager>;
using focusCallback = std::function<void(aasdk::messenger::ChannelId channelId, aasdk::proto::enums::AudioFocusState_Enum focus)>;

private:
std::vector<focusCallback> focusCallbacks;

public:
IAudioManager() = default;
virtual ~IAudioManager() = default;

virtual void start() = 0;
virtual void stop() = 0;

virtual void requestFocus(aasdk::messenger::ChannelId channelId, aasdk::proto::enums::AudioFocusType_Enum focus) = 0;
virtual void releaseFocus(aasdk::messenger::ChannelId channelId) = 0;


void registerFocusCallback(const focusCallback &callback) {
focusCallbacks.emplace_back(callback);
};

void updateFocus(aasdk::messenger::ChannelId channelId, aasdk::proto::enums::AudioFocusState_Enum focus) {
for (auto &callback : focusCallbacks) {
callback(channelId, focus);
}
}

};
10 changes: 5 additions & 5 deletions include/autoapp/Projection/InputDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace autoapp::projection {
class InputDevice : public IInputDevice {

public:
InputDevice(asio::io_service &ioService, AudioSignals::Pointer audiosignals, IVideoManager::Pointer videosignals);
InputDevice(asio::io_service &ioService, IAudioManager::Pointer AudioManager, IVideoManager::Pointer videosignals);

void start(IInputDeviceEventHandler &eventHandler) override;

Expand All @@ -57,7 +57,7 @@ class InputDevice : public IInputDevice {
private:
asio::basic_waitable_timer<std::chrono::steady_clock> timer_;
asio::io_service::strand strand_;
AudioSignals::Pointer audiosignals_;
IAudioManager::Pointer audioManager;
IVideoManager::Pointer videoManger;
IInputDeviceEventHandler *eventHandler_;
std::mutex mutex_;
Expand All @@ -75,13 +75,13 @@ class InputDevice : public IInputDevice {
sigc::connection audioFocusChanged;
sigc::connection videoFocusChanged;

void handle_key(input_event *ev);
void handle_key(input_event *inputEvent);

void handle_touch(input_event *ev);
void handle_touch(input_event *inputEvent);

void audio_focus(aasdk::messenger::ChannelId channel_id, aasdk::proto::enums::AudioFocusState_Enum state);
void video_focus(bool state);
void poll(asio::error_code ec);
void poll(asio::error_code error);
bool canceled_;
};
}
13 changes: 7 additions & 6 deletions include/autoapp/Service/AudioService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
#include <aasdk/Channel/AV/IAudioServiceChannelEventHandler.hpp>
#include <autoapp/Projection/IAudioOutput.hpp>
#include <autoapp/Service/IService.hpp>
#include <autoapp/Signals/AudioSignals.hpp>
#include <autoapp/Managers/IAudioManager.hpp>
#include "aasdk/Messenger/IMessenger.hpp"

namespace autoapp::service {

class AudioTimer {
public:
typedef aasdk::io::Promise<void> Promise;
using Promise = aasdk::io::Promise<void>;

explicit AudioTimer(asio::io_service &ioService);
void request(Promise::Pointer promise);
Expand All @@ -54,13 +54,13 @@ class AudioService
public IService,
public std::enable_shared_from_this<AudioService> {
public:
typedef std::shared_ptr<AudioService> Pointer;
using Pointer = std::shared_ptr<AudioService>;

AudioService(asio::io_service &ioService,
aasdk::messenger::IMessenger::Pointer messenger,
aasdk::messenger::ChannelId channelID,
std::vector<projection::IAudioOutput::Pointer> audioOutput,
AudioSignals::Pointer audiosignals);
IAudioManager::Pointer AudioManager);

~AudioService() noexcept override;

Expand All @@ -76,17 +76,18 @@ class AudioService
void onAVMediaWithTimestampIndication(aasdk::messenger::Timestamp::ValueType timestamp,
const aasdk::common::DataConstBuffer &buffer) override;
void onAVMediaIndication(const aasdk::common::DataConstBuffer &buffer) override;
void onChannelError(const aasdk::error::Error &e) override;
void onChannelError(const aasdk::error::Error &error) override;

protected:
using std::enable_shared_from_this<AudioService>::shared_from_this;

private:
asio::io_service::strand strand_;
asio::io_service::strand WriterStrand;
aasdk::channel::av::IAudioServiceChannel::Pointer channel_;
std::vector<projection::IAudioOutput::Pointer> audioOutput_;
int32_t session_;
AudioSignals::Pointer audiosignals_;
IAudioManager::Pointer audioManager;
AudioTimer timer_;
};

Expand Down
22 changes: 0 additions & 22 deletions include/autoapp/Signals/AudioSignals.hpp

This file was deleted.

18 changes: 13 additions & 5 deletions include/autoapp/Signals/Signals.hpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
#pragma once
#pragma once

#include <memory>
#include <utility>
#include <sigc++/sigc++.h>

#include "AudioSignals.hpp"
#include "AASignals.hpp"
#include "NavigationSignals.hpp"
#include "autoapp/Managers/IVideoManager.hpp"
#include "autoapp/Managers/IGPSManager.hpp"
#include <autoapp/Managers/INightManager.hpp>
#include <autoapp/Managers/IAudioManager.hpp>

class Signals : public sigc::trackable {
public:
typedef std::shared_ptr<Signals> Pointer;

IVideoManager::Pointer videoManager;
AudioSignals::Pointer audioSignals = std::make_shared<AudioSignals>();
IAudioManager::Pointer audioManager;
IGPSManager::Pointer gpsManager;
AASignals::Pointer aaSignals;
NavigationSignals::Pointer navSignals = std::make_shared<NavigationSignals>();
INightManager::Pointer nightManager;

explicit Signals(IVideoManager::Pointer VideoManager, IGPSManager::Pointer GPSManager, AASignals::Pointer AaSignals, INightManager::Pointer NightManager) : videoManager(std::move(
VideoManager)), gpsManager(std::move(GPSManager)), aaSignals(std::move(AaSignals)), nightManager(std::move(NightManager)) {
explicit Signals(IVideoManager::Pointer VideoManager,
IAudioManager::Pointer AudioManager,
IGPSManager::Pointer GPSManager,
AASignals::Pointer AaSignals,
INightManager::Pointer NightManager) :
videoManager(std::move(VideoManager)),
audioManager(std::move(AudioManager)),
gpsManager(std::move(GPSManager)),
aaSignals(std::move(AaSignals)),
nightManager(std::move(NightManager)) {
};
};
Loading

0 comments on commit afcfccc

Please sign in to comment.