linphone-iphone/wrappers/cpp/class_impl.mustache
2017-01-17 15:41:57 +01:00

130 lines
4.9 KiB
Text

/*
Copyright (C) 2017 Belledonne Communications SARL
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "linphone.hh"
using namespace {{{namespace}}};
{{#_class}}
{{#isNotListener}}
{{{namespace}}}::{{{className}}}::{{{className}}}(::belle_sip_object_t *ptr, bool takeRef): {{{parentClassName}}}(ptr, takeRef) {}
{{/isNotListener}}
{{#ismonolistenable}}
void {{{namespace}}}::{{{className}}}::setListener(const std::shared_ptr<{{{listenerClassName}}}> & listener) {
ListenableObject::setListener(std::static_pointer_cast<Listener>(listener));
{{{cListenerName}}} *cbs = {{{cCbsGetter}}}(({{{cClassName}}} *)mPrivPtr);
if (listener == nullptr) {
{{#wrapperCbs}}
{{{callbackSetter}}}(cbs, NULL);
{{/wrapperCbs}}
} else {
{{#wrapperCbs}}
{{{callbackSetter}}}(cbs, {{{cbName}}});
{{/wrapperCbs}}
}
}
{{/ismonolistenable}}
{{#ismultilistenable}}
{{{cListenerName}}} *{{{className}}}::createCallbacks(const std::shared_ptr<{{{listenerClassName}}}> &listener) {
{{{cListenerName}}} *cbs = {{{listenerCreator}}}(linphone_factory_get());
{{{userDataSetter}}}(cbs, listener.get());
{{#wrapperCbs}}
{{{callbackSetter}}}(cbs, {{{cbName}}});
{{/wrapperCbs}}
return cbs;
}
void {{{className}}}::addListener(std::shared_ptr<{{{listenerClassName}}}> &listener) {
MultiListenableObject::addListener(std::static_pointer_cast<Listener,{{{listenerClassName}}}>(listener));
{{{cListenerName}}} *cbs = createCallbacks(listener);
{{{callbacksAdder}}}(({{{cClassName}}} *)mPrivPtr, cbs);
listener->setCallbacks((::belle_sip_object_t *)cbs);
belle_sip_object_unref(cbs);
}
void {{{className}}}::removeListener(std::shared_ptr<{{{listenerClassName}}}> &listener) {
::belle_sip_object_t *cbs = belle_sip_object_ref(listener->getCallbacks());
{{{callbacksRemover}}}(({{{cClassName}}} *)mPrivPtr, ({{{cListenerName}}} *)cbs);
listener->setCallbacks(NULL);
belle_sip_object_unref(cbs);
MultiListenableObject::removeListener(listener);
}
{{/ismultilistenable}}
{{#isfactory}}
std::shared_ptr<Core> Factory::createCore(const std::shared_ptr<CoreListener> & cbs, const std::string & configPath, const std::string & factoryConfigPath) const {
::LinphoneFactory *factory = linphone_factory_get();
::LinphoneCoreCbs *c_cbs = cbs != nullptr ? Core::createCallbacks(cbs) : NULL;
::LinphoneCore *core_ptr = linphone_factory_create_core(factory, c_cbs, configPath.c_str(), factoryConfigPath.c_str());
std::shared_ptr<Core> core = cPtrToSharedPtr<Core>((belle_sip_object_t *)core_ptr, false);
if (core != nullptr && cbs != nullptr) {
std::static_pointer_cast<MultiListenableObject,Core>(core)->addListener(cbs);
cbs->setCallbacks((belle_sip_object_t *)c_cbs);
}
if (c_cbs) linphone_core_cbs_unref(c_cbs);
return core;
}
std::shared_ptr<Core> Factory::createCoreWithConfig(const std::shared_ptr<CoreListener> & cbs, const std::shared_ptr<Config> & config) const {
::LinphoneFactory *factory = linphone_factory_get();
::LinphoneCoreCbs *c_cbs = cbs != nullptr ? Core::createCallbacks(cbs) : NULL;
::LinphoneCore *core_ptr = linphone_factory_create_core_with_config(factory, c_cbs, (::LinphoneConfig *)sharedPtrToCPtr(config));
std::shared_ptr<Core> core = cPtrToSharedPtr<Core>((belle_sip_object_t *)core_ptr, false);
if (core != nullptr && cbs != nullptr) {
std::static_pointer_cast<MultiListenableObject,Core>(core)->addListener(cbs);
cbs->setCallbacks((belle_sip_object_t *)c_cbs);
}
if (c_cbs) linphone_core_cbs_unref(c_cbs);
return core;
}
{{/isfactory}}
{{#isVcard}}
std::shared_ptr<belcard::BelCard> &Vcard::getVcard() {
return *(shared_ptr<belcard::BelCard> *)linphone_vcard_get_belcard((LinphoneVcard *)mPrivPtr);
}
{{/isVcard}}
{{#methods}}
{{{implPrototype}}} {
{{{sourceCode}}}
}
{{/methods}}
{{#staticMethods}}
{{{implPrototype}}} {
{{{sourceCode}}}
}
{{/staticMethods}}
{{#wrapperCbs}}
{{{returnType}}} {{{className}}}::{{{cbName}}}({{{declArgs}}}) {
{{#ismonolistenable}}std::shared_ptr<{{{cppListenerName}}}> listener = std::static_pointer_cast<{{{cppListenerName}}},Listener>(getListenerFromObject((::belle_sip_object_t *){{{firstArgName}}}));{{/ismonolistenable}}
{{#ismultilistenable}}
LinphoneCoreCbs *cbs = linphone_core_get_current_callbacks(lc);
CoreListener *listener = (CoreListener *)linphone_core_cbs_get_user_data(cbs);
{{/ismultilistenable}}
{{#hasReturnValue}}return {{/hasReturnValue}}{{{cppMethodCallingLine}}};
}
{{/wrapperCbs}}
{{/_class}}