From 63a0b4aaa59569bb5340a1dfc99120dc36539816 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 26 Jun 2017 12:58:43 +0200 Subject: [PATCH] let's not create a callback hell --- .vscode/settings.json | 27 ++++++++++++++++++++++++++- audio/AudioInputPHP.cpp | 9 +++++---- audio/AudioInputPHP.h | 1 - audio/AudioOutputPHP.cpp | 9 ++++----- audio/AudioOutputPHP.h | 1 - main.cpp | 8 +++----- 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 38e529d..8472877 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,31 @@ "initializer_list": "cpp", "utility": "cpp", "system_error": "cpp", - "type_traits": "cpp" + "type_traits": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cwchar": "cpp", + "exception": "cpp", + "iosfwd": "cpp", + "new": "cpp", + "stdexcept": "cpp", + "tuple": "cpp", + "typeinfo": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstring": "cpp", + "cwctype": "cpp", + "functional": "cpp", + "istream": "cpp", + "limits": "cpp", + "memory": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "streambuf": "cpp" } } \ No newline at end of file diff --git a/audio/AudioInputPHP.cpp b/audio/AudioInputPHP.cpp index e5962c5..2c4588c 100644 --- a/audio/AudioInputPHP.cpp +++ b/audio/AudioInputPHP.cpp @@ -17,7 +17,6 @@ AudioInputPHP::AudioInputPHP(Php::Value callbacks){ startMethod = callbacks["start"]; stopMethod = callbacks["stop"]; configureMethod = callbacks["configure"]; - call = callbacks["call"]; } @@ -25,18 +24,20 @@ AudioInputPHP::~AudioInputPHP(){ } void AudioInputPHP::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels) { - configureMethod(static_cast call, (int32_t)sampleRate, (int32_t)bitsPerSample, (int32_t)channels); + configureMethod((int32_t)sampleRate, (int32_t)bitsPerSample, (int32_t)channels); } void AudioInputPHP::Start(){ if(running) return; - startMethod(static_cast call); + startMethod(); + running = true; } void AudioInputPHP::Stop(){ - stopMethod(static_cast call); + stopMethod(); + running = false; } void AudioInputPHP::writeFrames(Php::Parameters ¶ms){ if(!running) diff --git a/audio/AudioInputPHP.h b/audio/AudioInputPHP.h index 3d374cf..d42a7d6 100644 --- a/audio/AudioInputPHP.h +++ b/audio/AudioInputPHP.h @@ -26,7 +26,6 @@ private: Php::Value configureMethod; Php::Value startMethod; Php::Value stopMethod; - void* call; bool running; }; }} diff --git a/audio/AudioOutputPHP.cpp b/audio/AudioOutputPHP.cpp index 648a289..0bc4e47 100644 --- a/audio/AudioOutputPHP.cpp +++ b/audio/AudioOutputPHP.cpp @@ -17,24 +17,23 @@ AudioOutputPHP::AudioOutputPHP(Php::Value callbacks){ stopMethod = callbacks["stop"]; configureMethod = callbacks["configure"]; getLevelMethod = callbacks["get_level"]; - call = callbacks["call"]; } void AudioOutputPHP::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels){ - configureMethod(static_cast call, (int32_t)sampleRate, (int32_t)bitsPerSample, (int32_t)channels); + configureMethod((int32_t)sampleRate, (int32_t)bitsPerSample, (int32_t)channels); } void AudioOutputPHP::Start(){ if(running) return; + startMethod(); running = true; - startMethod(static_cast call); } void AudioOutputPHP::Stop(){ if(!running) return; - stopMethod(static_cast call); + stopMethod(); running = false; } @@ -43,7 +42,7 @@ bool AudioOutputPHP::IsPlaying(){ } float AudioOutputPHP::GetLevel(){ - return (double)getLevelMethod(static_cast call); + return (double)getLevelMethod(); } Php::Value AudioOutputPHP::readFrames() { diff --git a/audio/AudioOutputPHP.h b/audio/AudioOutputPHP.h index fdbd6db..6223031 100644 --- a/audio/AudioOutputPHP.h +++ b/audio/AudioOutputPHP.h @@ -30,7 +30,6 @@ private: Php::Value stopMethod; Php::Value isPlayingMethod; Php::Value getLevelMethod; - void* call; bool running; }; }} diff --git a/main.cpp b/main.cpp index 4a580bc..7d0f0e5 100644 --- a/main.cpp +++ b/main.cpp @@ -35,11 +35,12 @@ If not, see . #include "libtgvoip/NetworkSocket.cpp" #include "libtgvoip/os/posix/NetworkSocketPosix.cpp" +#include "audio/AudioInputPHP.h" +#include "audio/AudioOutputPHP.h" + #include "libtgvoip/audio/AudioInput.cpp" #include "libtgvoip/audio/AudioOutput.cpp" -#include "audio/AudioInputPHP.h" -#include "audio/AudioOutputPHP.h" using namespace tgvoip; @@ -52,8 +53,6 @@ public: setStateMethod = params[0]; madeline = params[3]; current_call = params[4]; - params[1]["call"] = static_cast(this); - params[2]["call"] = static_cast(this); inst=new VoIPController(params[1], params[2]); inst->implData = static_cast(this); inst->SetStateCallback([](tgvoip::VoIPController *controller, int state) { @@ -282,7 +281,6 @@ extern "C" { Php::ByVal("frames", Php::Type::String) }); - voip.constant("STATE_READY_TO_INIT", 0); voip.constant("STATE_WAIT_INIT", 1); voip.constant("STATE_WAIT_INIT_ACK", 2); voip.constant("STATE_ESTABLISHED", 3);