1
0
mirror of https://github.com/danog/php-libtgvoip.git synced 2024-11-30 04:19:26 +01:00

let's not create a callback hell

This commit is contained in:
Daniil Gentili 2017-06-26 12:58:43 +02:00
parent 70ecd6db72
commit 63a0b4aaa5
6 changed files with 38 additions and 17 deletions

27
.vscode/settings.json vendored
View File

@ -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"
}
}

View File

@ -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<VoIP*> 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<VoIP*> call);
startMethod();
running = true;
}
void AudioInputPHP::Stop(){
stopMethod(static_cast<VoIP*> call);
stopMethod();
running = false;
}
void AudioInputPHP::writeFrames(Php::Parameters &params){
if(!running)

View File

@ -26,7 +26,6 @@ private:
Php::Value configureMethod;
Php::Value startMethod;
Php::Value stopMethod;
void* call;
bool running;
};
}}

View File

@ -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<VoIP*> 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<VoIP*> call);
}
void AudioOutputPHP::Stop(){
if(!running)
return;
stopMethod(static_cast<VoIP*> call);
stopMethod();
running = false;
}
@ -43,7 +42,7 @@ bool AudioOutputPHP::IsPlaying(){
}
float AudioOutputPHP::GetLevel(){
return (double)getLevelMethod(static_cast<VoIP*> call);
return (double)getLevelMethod();
}
Php::Value AudioOutputPHP::readFrames() {

View File

@ -30,7 +30,6 @@ private:
Php::Value stopMethod;
Php::Value isPlayingMethod;
Php::Value getLevelMethod;
void* call;
bool running;
};
}}

View File

@ -35,11 +35,12 @@ If not, see <http://www.gnu.org/licenses/>.
#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<void*>(this);
params[2]["call"] = static_cast<void*>(this);
inst=new VoIPController(params[1], params[2]);
inst->implData = static_cast<void*>(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);