class_impl.mustache 6.3 KB
Newer Older
François Grisez's avatar
François Grisez committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
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.
*/

19 20 21 22 23
#include <belle-sip/object.h>
#include <linphone/linphonecore.h>
#include <linphone/linphone_tunnel.h>
#include <linphone/linphonecore_utils.h>
#include <linphone/wrapper_utils.h>
François Grisez's avatar
François Grisez committed
24
#include "linphone++/linphone.hh"
25
#include "tools.hh"
26

27
using namespace std;
28 29
using namespace {{{namespace}}};

30
{{#classes}}
31

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
{{#wrapperCbs}}
static {{{returnType}}} {{{cbName}}}({{{declArgs}}}) {
	{{#ismonolistenable}}
	std::shared_ptr<{{{cppListenerName}}}> listener = std::static_pointer_cast<{{{cppListenerName}}},Listener>(ListenableObject::getListenerFromObject((::belle_sip_object_t *){{{firstArgName}}}));
	{{#hasReturnValue}}return {{/hasReturnValue}}{{{cppMethodCallingLine}}};
	{{/ismonolistenable}}
	
	{{#ismultilistenable}}
	{{{cListenerName}}} *cbs = {{{currentCallbacksGetter}}}({{{firstArgName}}});
	std::list<std::shared_ptr<Listener> > &listeners = *(std::list<std::shared_ptr<Listener> > *){{{userDataGetter}}}(cbs);
	for(auto it=listeners.begin(); it!=listeners.end(); it++) {
		std::shared_ptr<{{{cppListenerName}}}> listener = std::static_pointer_cast<{{{cppListenerName}}},Listener>(*it);
		{{{cppMethodCallingLine}}};
	}
	{{/ismultilistenable}}
}
{{/wrapperCbs}}

50
{{#isNotListener}}
51
{{#isrefcountable}}
52
{{{namespace}}}::{{{className}}}::{{{className}}}(void *ptr, bool takeRef): {{{parentClassName}}}(ptr, takeRef) {
53
	{{#ismultilistenable}}
54 55
	mCallbacks = ({{{cListenerName}}} *)createCallbacks(&getListeners());
	{{{callbacksAdder}}}(({{{cClassName}}} *)mPrivPtr, ({{{cListenerName}}} *)mCallbacks);
56 57
	{{/ismultilistenable}}
}
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
{{/isrefcountable}}

{{#isnotrefcountable}}
{{{namespace}}}::{{{className}}}::{{{className}}}() {
	mPrivPtr = new {{{cClassName}}};
	memset(mPrivPtr, 0, sizeof({{{cClassName}}}));
}

{{{namespace}}}::{{{className}}}::{{{className}}}(const {{{className}}} &src) {
	mPrivPtr = new {{{cClassName}}}(*({{{cClassName}}} *)src.mPrivPtr);
}

{{{namespace}}}::{{{className}}}::{{{className}}}(const void *src) {
	mPrivPtr = new {{{cClassName}}}(*({{{cClassName}}} *)src);
}

{{{namespace}}}::{{{className}}}::~{{{className}}}() {
	delete ({{{cClassName}}} *)mPrivPtr;
}
{{/isnotrefcountable}}
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
{{/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}}
97
{{{className}}}::~{{{className}}}() {
98
	{{{callbacksRemover}}}(({{{cClassName}}} *)mPrivPtr, ({{{cListenerName}}} *)mCallbacks);
99
	belle_sip_object_unref(mCallbacks);
100 101
}

102
void {{{className}}}::addListener(const std::shared_ptr<{{{listenerClassName}}}> &listener) {
103 104 105
	MultiListenableObject::addListener(std::static_pointer_cast<Listener,{{{listenerClassName}}}>(listener));
}

106 107 108 109
void {{{className}}}::removeListener(const std::shared_ptr<{{{listenerClassName}}}> &listener) {
	MultiListenableObject::removeListener(std::static_pointer_cast<Listener,{{{listenerClassName}}}>(listener));
}

110
void *{{{className}}}::createCallbacks(void *userData) {
111 112 113 114 115 116
	{{{cListenerName}}} *cbs = {{{listenerCreator}}}(linphone_factory_get());
	{{#wrapperCbs}}
	{{{callbackSetter}}}(cbs, {{{cbName}}});
	{{/wrapperCbs}}
	{{{userDataSetter}}}(cbs, userData);
	return cbs;
117 118 119 120
}
{{/ismultilistenable}}

{{#isfactory}}
121 122
std::shared_ptr<Core> Factory::createCore(const std::shared_ptr<CoreListener> & listener, const std::string & configPath, const std::string & factoryConfigPath) const {
	::LinphoneCoreCbs *cbs = NULL;
123
	std::list<std::shared_ptr<Listener> > listeners;
124 125
	if (listener != nullptr) {
		listeners.push_back(std::static_pointer_cast<Listener,CoreListener>(listener));
126
		cbs = (::LinphoneCoreCbs *)Core::createCallbacks(&listeners);
127 128
	}
	
129
	::LinphoneFactory *factory = linphone_factory_get();
130
	::LinphoneCore *core_ptr = linphone_factory_create_core(factory, cbs, StringUtilities::cppStringToC(configPath), StringUtilities::cppStringToC(factoryConfigPath));
131 132 133 134
	
	if (cbs != NULL) {
		linphone_core_remove_callbacks(core_ptr, cbs);
		linphone_core_cbs_unref(cbs);
135
	}
136 137 138 139
	
	std::shared_ptr<Core> cppCore = cPtrToSharedPtr<Core>((::belle_sip_object_t *)core_ptr, false);
	if (listener != nullptr) cppCore->addListener(listener);
	return cppCore;
140 141
}

142 143
std::shared_ptr<Core> Factory::createCoreWithConfig(const std::shared_ptr<CoreListener> & listener, const std::shared_ptr<Config> & config) const {
	::LinphoneCoreCbs *cbs = NULL;
144
	std::list<std::shared_ptr<Listener> > listeners;
145 146
	if (listener != nullptr) {
		listeners.push_back(std::static_pointer_cast<Listener,CoreListener>(listener));
147
		cbs = (::LinphoneCoreCbs *)Core::createCallbacks(&listeners);
148 149
	}
	
150
	::LinphoneFactory *factory = linphone_factory_get();
151 152 153 154 155
	::LinphoneCore *core_ptr = linphone_factory_create_core_with_config(factory, cbs, (::LinphoneConfig *)sharedPtrToCPtr(config));
	
	if (cbs != NULL) {
		linphone_core_remove_callbacks(core_ptr, cbs);
		linphone_core_cbs_unref(cbs);
156
	}
157 158 159 160
	
	std::shared_ptr<Core> cppCore = cPtrToSharedPtr<Core>((::belle_sip_object_t *)core_ptr, false);
	if (listener != nullptr) cppCore->addListener(listener);
	return cppCore;
161 162 163
}
{{/isfactory}}

164 165 166 167 168 169
{{#isVcard}}
std::shared_ptr<belcard::BelCard> &Vcard::getVcard() {
	return *(shared_ptr<belcard::BelCard> *)linphone_vcard_get_belcard((LinphoneVcard *)mPrivPtr);
}
{{/isVcard}}

170 171 172 173 174 175 176 177 178 179 180 181
{{#methods}}
{{{implPrototype}}} {
	{{{sourceCode}}}
}
{{/methods}}

{{#staticMethods}}
{{{implPrototype}}} {
	{{{sourceCode}}}
}
{{/staticMethods}}

182
{{/classes}}