Commit f6cd06d3 authored by François Grisez's avatar François Grisez

Wrappers generator: logging system reworking

parent a2f363ac
......@@ -18,10 +18,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import sys
import os
import argparse
import logging
import os
import pystache
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', 'tools'))
import abstractapi
......@@ -363,7 +364,11 @@ if __name__ == '__main__':
argparser = argparse.ArgumentParser(description='Generate a sphinx project to generate the documentation of Linphone Core API.')
argparser.add_argument('xmldir', type=str, help='directory holding the XML documentation of the C API generated by Doxygen')
argparser.add_argument('-o --output', type=str, help='directory into where Sphinx source files will be written', dest='outputdir', default='.')
argparser.add_argument('-v --verbose', action='store_true', default=False, dest='verbose_mode', help='Show warning and info messages')
args = argparser.parse_args()
loglevel = logging.INFO if args.verbose_mode else logging.ERROR
logging.basicConfig(format='%(levelname)s[%(name)s]: %(message)s', level=loglevel)
cProject = capi.Project()
cProject.initFromDir(args.xmldir)
......
......@@ -350,26 +350,23 @@ LINPHONE_PUBLIC void linphone_call_set_audio_route (LinphoneCall *call, Linphone
LINPHONE_PUBLIC int linphone_call_get_stream_count (const LinphoneCall *call);
/**
* Returns the type of stream for the given stream index.
* @param call
* @param stream_index
* @brief Returns the type of stream for the given stream index.
* @return the type (MSAudio, MSVideo, MSText) of the stream of given index.
* @donotwrap
**/
LINPHONE_PUBLIC MSFormatType linphone_call_get_stream_type (const LinphoneCall *call, int stream_index);
/**
* Returns the meta rtp transport for the given stream index.
* @param call
* @param stream_index
* @return a pointer to the meta rtp transport if it exists, NULL otherwise
* @brief Returns the meta rtp transport for the given stream index.
* @return a pointer to the meta rtp transport if it exists, NULL otherwise.
* @donotwrap
**/
LINPHONE_PUBLIC RtpTransport *linphone_call_get_meta_rtp_transport (const LinphoneCall *call, int stream_index);
/**
* Returns the meta rtcp transport for the given stream index.
* @param call
* @param stream_index
* @return a pointer to the meta rtcp transport if it exists, NULL otherwise
* @brief Returns the meta rtcp transport for the given stream index.
* @return a pointer to the meta rtcp transport if it exists, NULL otherwise.
* @donotwrap
**/
LINPHONE_PUBLIC RtpTransport *linphone_call_get_meta_rtcp_transport (const LinphoneCall *call, int stream_index);
......
......@@ -68,6 +68,7 @@ LINPHONE_PUBLIC const LinphoneAddress * linphone_call_log_get_from_address(const
* Get the RTP statistics computed locally regarding the call.
* @param[in] cl LinphoneCallLog object
* @return The RTP statistics that have been computed locally for the call.
* @donotwrap
**/
LINPHONE_PUBLIC const rtp_stats_t * linphone_call_log_get_local_stats(const LinphoneCallLog *cl);
......@@ -101,6 +102,7 @@ LINPHONE_PUBLIC LinphoneAddress * linphone_call_log_get_remote_address(const Lin
* @note Not implemented yet.
* @param[in] cl LinphoneCallLog object
* @return The RTP statistics that have been computed by the remote end for the call.
* @donotwrap
**/
LINPHONE_PUBLIC const rtp_stats_t * linphone_call_log_get_remote_stats(const LinphoneCallLog *cl);
......
......@@ -140,10 +140,11 @@ LINPHONE_PUBLIC float linphone_call_params_get_received_framerate(const Linphone
LINPHONE_PUBLIC const LinphoneVideoDefinition * linphone_call_params_get_received_video_definition(const LinphoneCallParams *cp);
/**
* Get the size of the video that is received.
* @param[in] cp LinphoneCallParams object
* @brief Get the size of the video that is received.
* @param[in] cp #LinphoneCallParams object
* @return The received video size or MS_VIDEO_SIZE_UNKNOWN if not available.
* @deprecated Use linphone_call_params_get_received_video_definition() instead
* @deprecated Use #linphone_call_params_get_received_video_definition() instead. Deprecated since 2017-03-28.
* @donotwrap
*/
LINPHONE_PUBLIC LINPHONE_DEPRECATED MSVideoSize linphone_call_params_get_received_video_size(const LinphoneCallParams *cp);
......@@ -176,10 +177,11 @@ LINPHONE_PUBLIC float linphone_call_params_get_sent_framerate(const LinphoneCall
LINPHONE_PUBLIC const LinphoneVideoDefinition * linphone_call_params_get_sent_video_definition(const LinphoneCallParams *cp);
/**
* Gets the size of the video that is sent.
* @param[in] cp LinphoneCalParams object
* @biref Gets the size of the video that is sent.
* @param[in] cp #LinphoneCalParams object
* @return The sent video size or MS_VIDEO_SIZE_UNKNOWN if not available.
* @deprecated Use linphone_call_params_get_sent_video_definition() instead
* @deprecated Use #linphone_call_params_get_sent_video_definition() instead. Deprecated since 2017-03-28.
* @donotwrap
*/
LINPHONE_PUBLIC LINPHONE_DEPRECATED MSVideoSize linphone_call_params_get_sent_video_size(const LinphoneCallParams *cp);
......
This diff is collapsed.
......@@ -55,12 +55,12 @@ LINPHONE_DEPRECATED typedef void (*LinphoneEcCalibrationAudioInit)(void *data);
LINPHONE_DEPRECATED typedef void (*LinphoneEcCalibrationAudioUninit)(void *data);
/**
*
* @brief Starts an echo calibration of the sound devices, in order to find adequate settings for the echo canceler automatically.
* @deprecated Use #linphone_core_start_echo_canceller_calibration() instead. To set the callbacks create or get an already instantiated
* #LinphoneCoreCbs and call #linphone_core_cbs_set_ec_calibration_result(), #linphone_core_cbs_set_ec_calibration_audio_init() and
* #linphone_core_cbs_set_ec_callibration_audio_uninit(). Deprecated since 2017-10-16.
* @ingroup misc
* @donotwrap
**/
LINPHONE_DEPRECATED LINPHONE_PUBLIC int linphone_core_start_echo_calibration(LinphoneCore *lc, LinphoneEcCalibrationCallback cb,
LinphoneEcCalibrationAudioInit audio_init_cb, LinphoneEcCalibrationAudioUninit audio_uninit_cb, void *cb_data);
......
......@@ -245,12 +245,14 @@ LINPHONE_PUBLIC const char** linphone_config_get_sections_names(LinphoneConfig *
LINPHONE_PUBLIC const bctbx_list_t * linphone_config_get_sections_names_list(LpConfig *lpconfig);
/**
* Call a function for each section present in the configuration.
* @brief Call a function for each section present in the configuration.
* @donotwrap
**/
void linphone_config_for_each_section(const LinphoneConfig *lpconfig, void (*callback)(const char *section, void *ctx), void *ctx);
/**
* Call a function for each entry present in a section configuration.
* @brief Call a function for each entry present in a section configuration.
* @donotwrap
**/
void linphone_config_for_each_entry(const LinphoneConfig *lpconfig, const char *section, void (*callback)(const char *entry, void *ctx), void *ctx);
......
......@@ -172,6 +172,7 @@ LINPHONE_PUBLIC void linphone_nat_policy_resolve_stun_server(LinphoneNatPolicy *
* WARNING: This function may block for up to 1 second.
* @param[in] policy LinphoneNatPolicy object
* @return addrinfo representation of the STUN server address.
* @donotwrap
*/
LINPHONE_PUBLIC const struct addrinfo * linphone_nat_policy_get_stun_server_addrinfo(LinphoneNatPolicy *policy);
......
This diff is collapsed.
......@@ -17,15 +17,20 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import argparse
import logging
import os
import six
import string
import sys
import xml.etree.ElementTree as ET
import xml.dom.minidom as minidom
import metadoc
logger = logging.getLogger(__name__)
class CObject:
def __init__(self, name):
self.name = name.strip()
......@@ -47,6 +52,10 @@ class CEnum(CObject):
CObject.__init__(self, name)
self.values = []
self.associatedTypedef = None
@property
def publicName(self):
return self.associatedTypedef.name if self.associatedTypedef is not None else self.name
def addValue(self, value):
self.values.append(value)
......@@ -239,7 +248,6 @@ class CClass(CObject):
class Project:
def __init__(self):
self.verbose = False
self.prettyPrint = False
self.enums = []
self.__structs = []
......@@ -251,37 +259,28 @@ class Project:
def add(self, elem):
if isinstance(elem, CClass):
if self.verbose:
print("Adding class " + elem.name)
logger.debug("Adding class " + elem.name)
self.classes.append(elem)
elif isinstance(elem, CEnum):
if self.verbose:
print("Adding enum " + elem.name)
for ev in elem.values:
print("\t" + ev.name)
msg = 'Adding enum {0}'.format(elem.name)
for value in elem.values:
msg += ('\t{0}'.format(value))
logger.debug(msg)
self.enums.append(elem)
elif isinstance(elem, CStruct):
if self.verbose:
print("Adding struct " + elem.name)
for sm in elem.members:
print("\t" + sm.ctype + " " + sm.name)
msg = "Adding struct " + elem.name
for sm in elem.members:
msg += ('\t{0} {1}'.format(sm.ctype, sm.name))
logger.debug(msg)
self.__structs.append(elem)
elif isinstance(elem, CTypedef):
if self.verbose:
print("Adding typedef " + elem.name)
print("\t" + elem.definition)
logger.debug('Adding typedef {0}\t{1}'.format(elem.name, elem.definition))
self.__typedefs.append(elem)
elif isinstance(elem, CEvent):
if self.verbose:
print("Adding event " + elem.name)
print("\tReturns: " + elem.returnArgument.ctype)
print("\tArguments: " + str(elem.arguments))
logger.debug('Adding event {0}\tReturns: {1}\tArguments: {2}'.format(elem.name, elem.returnArgument.ctype, elem.arguments))
self.__events.append(elem)
elif isinstance(elem, CFunction):
if self.verbose:
print("Adding function " + elem.name)
print("\tReturns: " + elem.returnArgument.ctype)
print("\tArguments: " + str(elem.arguments))
logger.debug('Adding event {0}\tReturns: {1}\tArguments: {2}'.format(elem.name, elem.returnArgument.ctype, elem.arguments))
self.__functions.append(elem)
def __cleanDescription(self, descriptionNode):
......@@ -330,7 +329,7 @@ class Project:
break
if not structFound:
name = td.definition[7:]
print("Structure with no associated typedef: " + name)
logger.warning("Structure with no associated typedef: " + name)
st = CStruct(name)
st.associatedTypedef = td
self.add(st)
......@@ -503,7 +502,7 @@ class Project:
if arg.description == None:
missingDocWarning += "\t'" + arg.name + "' parameter not documented\n";
if missingDocWarning != '':
print(name + ":\n" + missingDocWarning)
logger.warning(name + ":\n" + missingDocWarning)
f = CEvent(name, returnarg, argslist)
deprecatedNode = node.find(".//xrefsect[xreftitle='Deprecated']")
if deprecatedNode is not None:
......@@ -599,7 +598,7 @@ class Project:
if not f.location.endswith('.h'):
missingDocWarning += "\tNot documented in a header file ('" + f.location + "')\n";
if missingDocWarning != '':
print(name + ":\n" + missingDocWarning)
logger.warning(name + ":\n" + missingDocWarning)
return f
def __findCFunction(self, tree):
......@@ -614,11 +613,10 @@ class Project:
for f in xmlfiles:
tree = None
try:
if self.verbose:
print("Parsing XML file: " + f.name)
logger.debug("Parsing XML file: " + f)
tree = ET.parse(f)
except ET.ParseError as e:
print(e)
logger.error(e)
if tree is not None:
trees.append(tree)
for tree in trees:
......@@ -639,7 +637,7 @@ class Project:
for c in self.classes:
for name, p in six.iteritems(c.properties):
if p.getter is None and p.setter is not None:
print("Property '" + name + "' of class '" + c.name + "' has a setter but no getter")
logger.warning("Property '" + name + "' of class '" + c.name + "' has a setter but no getter")
class Generator:
......@@ -764,7 +762,7 @@ class Generator:
classNode.append(cclass.detailedDescription)
def generate(self, project):
print("Generating XML document of Linphone API to '" + self.__outputfile.name + "'")
logger.info("Generating XML document of Linphone API to '" + self.__outputfile.name + "'")
apiNode = ET.Element('api')
project.enums.sort(key = lambda e: e.name)
if len(project.enums) > 0:
......@@ -797,7 +795,9 @@ def main(argv = None):
args.outputfile = open('api.xml', 'w')
project = Project()
if args.verbose:
project.verbose = True
logger.setLogLevel(logging.DEBUG)
else:
logger.setLogLevel(logging.INFO)
if args.pretty:
project.prettyPrint = True
project.initFromDir(args.xmldir)
......
......@@ -14,8 +14,10 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import metaname
import abstractapi
import logging
import metaname
import re
......@@ -146,7 +148,7 @@ class ClassReference(Reference):
try:
self.relatedObject = api.classesIndex[self.cname]
except KeyError:
print('doc reference pointing on an unknown object ({0})'.format(self.cname))
logging.warning('doc reference pointing on an unknown object ({0})'.format(self.cname))
class FunctionReference(Reference):
......@@ -154,7 +156,7 @@ class FunctionReference(Reference):
try:
self.relatedObject = api.methodsIndex[self.cname]
except KeyError:
print('doc reference pointing on an unknown object ({0})'.format(self.cname))
logging.warning('doc reference pointing on an unknown object ({0})'.format(self.cname))
class Paragraph(MultiChildTreeNode):
......@@ -443,8 +445,8 @@ class Translator:
strPara += part
else:
strPara += part.translate(self)
except TranslationError as e:
print('error: {0}'.format(e.msg()))
except ReferenceTranslationError:
strPara += part.cname
return strPara
......
......@@ -144,7 +144,7 @@ class Name(object):
class ClassName(Name):
def to_c(self):
def to_c(self, addBrackets=False):
return self.to_camel_case(fullName=True)
def translate(self, translator, **params):
......@@ -152,7 +152,7 @@ class ClassName(Name):
class InterfaceName(ClassName):
def to_c(self):
def to_c(self, addBrackets=False):
return ClassName.to_c(self)[:-8] + 'Cbs'
def translate(self, translator, **params):
......@@ -183,16 +183,19 @@ class MethodName(Name):
self.overloadRef = int(suffix)
del self.words[-1]
def to_c(self):
def to_c(self, addBrackets=False):
suffix = ('_' + str(self.overloadRef)) if self.overloadRef > 0 else ''
return self.to_snake_case(fullName=True) + suffix
cName = self.to_snake_case(fullName=True) + suffix
if addBrackets:
cName += '()'
return cName
def translate(self, translator, **params):
return translator.translate_method_name(self, **params)
class ArgName(Name):
def to_c(self):
def to_c(self, addBrackets=False):
return self.to_snake_case()
def translate(self, translator, **params):
......
......@@ -42,16 +42,12 @@ blacklisted_events = [
'LinphoneCoreTextMessageReceivedCb' # not respecting naming convention
]
blacklisted_functions = [
'linphone_call_log_get_local_stats', # missing rtp_stats_t
'linphone_call_log_get_remote_stats', # missing rtp_stats_t
'linphone_call_params_get_privacy', # missing LinphonePrivacyMask
'linphone_call_params_set_privacy', # missing LinphonePrivacyMask
'linphone_chat_message_start_file_download', # callback function in parameter
'linphone_chat_message_state_to_string', # There is no use to wrap this function
'linphone_chat_room_send_chat_message', # Use linphone_chat_room_send_chat_message_2 instead
'linphone_chat_room_send_message2', # callback function in parameter
'linphone_config_for_each_entry', # to be handwritten because of callback
'linphone_config_for_each_section', # to be handwritten because of callback
'linphone_config_get_range', # to be handwritten because of result via arguments
'linphone_config_load_dict_to_section', # missing LinphoneDictionary
'linphone_config_section_to_dict', # missing LinphoneDictionary
......@@ -62,10 +58,7 @@ blacklisted_functions = [
'linphone_core_enable_logs_with_cb', # callback function in parameter
'linphone_core_get_audio_port_range', # to be handwritten because of result via arguments
'linphone_core_get_default_proxy',
'linphone_core_get_network_simulator_params', # missing OrtpNetworkSimulatorParams
'linphone_core_get_supported_video_sizes', # missing MSVideoSizeDef
'linphone_core_get_tunnel', # blacklisted LinphoneTunnel
'linphone_core_get_video_policy', # missing LinphoneVideoPolicy
'linphone_core_get_video_port_range', # to be handwritten because of result via arguments
'linphone_core_new', # replaced by linphone_factory_create_core
'linphone_core_new_with_config', # replaced by linphone_factory_create_core_with_config
......@@ -75,13 +68,7 @@ blacklisted_functions = [
'linphone_core_set_log_collection_max_file_size', # need to handle class properties
'linphone_core_set_log_collection_path', # need to handle class properties
'linphone_core_set_log_collection_prefix', # need to handle class properties
'linphone_core_set_log_file', # There is no use to wrap this function
'linphone_core_set_log_handler', # Hand-written but put directly in the linphone module
'linphone_core_set_log_level', # There is no use to wrap this function
'linphone_core_set_log_level_mask', # There is no use to wrap this function
'linphone_core_set_network_simulator_params', # missing OrtpNetworkSimulatorParams
'linphone_core_set_video_policy', # missing LinphoneVideoPolicy
'linphone_nat_policy_get_stun_server_addrinfo',
'linphone_proxy_config_get_privacy', # missing LinphonePrivacyMask
'linphone_proxy_config_normalize_number', # to be handwritten because of result via arguments
'linphone_proxy_config_set_file_transfer_server', # defined but not implemented in linphone core
......
......@@ -21,8 +21,10 @@ import pystache
import re
import argparse
import os
import os.path
import sys
import errno
import logging
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'tools'))
import genapixml as CApi
......@@ -58,9 +60,12 @@ class CppTranslator(object):
def translate_enumerator(self, enumerator):
enumeratorDict = {
'name' : enumerator.name.translate(self.nameTranslator),
'doc' : enumerator.briefDescription.translate(self.docTranslator),
'value' : enumerator.translate_value(self.langTranslator)
}
try:
enumeratorDict['doc'] = enumerator.briefDescription.translate(self.docTranslator)
except metadoc.TranslationError as e:
logging.error(e.msg())
return enumeratorDict
def translate_class(self, _class):
......@@ -92,8 +97,11 @@ class CppTranslator(object):
if _class.name.to_c() == 'LinphoneCore':
classDict['friendClasses'].append({'name': 'Factory'});
classDict['briefDoc'] = _class.briefDescription.translate(self.docTranslator, tagAsBrief=True)
classDict['detailedDoc'] = _class.detailedDescription.translate(self.docTranslator)
try:
classDict['briefDoc'] = _class.briefDescription.translate(self.docTranslator, tagAsBrief=True)
classDict['detailedDoc'] = _class.detailedDescription.translate(self.docTranslator)
except metadoc.TranslationError as e:
logging.error(e.msg())
if islistenable:
classDict['listenerClassName'] = _class.listenerInterface.name.translate(self.nameTranslator)
......@@ -115,24 +123,15 @@ class CppTranslator(object):
classDict['currentCallbacksGetter'] = _class.name.to_snake_case(fullName=True) + '_get_current_callbacks'
for _property in _class.properties:
try:
classDict['methods'] += self.translate_property(_property)
except AbsApi.Error as e:
print('error while translating {0} property: {1}'.format(_property.name.to_snake_case(), e.args[0]))
classDict['methods'] += self.translate_property(_property)
for method in _class.instanceMethods:
try:
methodDict = self.translate_method(method)
classDict['methods'].append(methodDict)
except AbsApi.Error as e:
print('Could not translate {0}: {1}'.format(method.name.to_snake_case(fullName=True), e.args[0]))
methodDict = self.translate_method(method)
classDict['methods'].append(methodDict)
for method in _class.classMethods:
try:
methodDict = self.translate_method(method)
classDict['staticMethods'].append(methodDict)
except AbsApi.Error as e:
print('Could not translate {0}: {1}'.format(method.name.to_snake_case(fullName=True), e.args[0]))
methodDict = self.translate_method(method)
classDict['staticMethods'].append(methodDict)
return classDict
......@@ -175,11 +174,8 @@ class CppTranslator(object):
'methods' : []
}
for method in interface.methods:
try:
methodDict = self.translate_method(method, genImpl=False)
intDict['methods'].append(methodDict)
except AbsApi.Error as e:
print('Could not translate {0}: {1}'.format(method.name.to_snake_case(fullName=True), e.args[0]))
methodDict = self.translate_method(method, genImpl=False)
intDict['methods'].append(methodDict)
return intDict
......@@ -199,10 +195,14 @@ class CppTranslator(object):
'implPrototype': method.translate_as_prototype(self.langTranslator, namespace=namespace),
'deprecated': method.deprecated,
'suffix': '',
'briefDoc': method.briefDescription.translate(self.docTranslator, tagAsBrief=True) if method.briefDescription is not None else None,
'detailedDoc': method.detailedDescription.translate(self.docTranslator) if method.detailedDescription is not None else None
}
try:
methodDict['briefDoc'] = method.briefDescription.translate(self.docTranslator, tagAsBrief=True) if method.briefDescription is not None else None
methodDict['detailedDoc'] = method.detailedDescription.translate(self.docTranslator) if method.detailedDescription is not None else None
except metadoc.TranslationError as e:
logging.error(e.msg())
if type(method.parent) is AbsApi.Interface:
if isinstance(method.returnType, AbsApi.BaseType) and method.returnType.name == 'void':
methodDict['suffix'] = ' {}'
......@@ -465,7 +465,7 @@ class GenWrapper(object):
if item[1] is not None:
header.add_enum(item[1])
else:
print('warning: {0} enum won\'t be translated because of parsing errors'.format(item[0]))
logging.info('{0} enum won\'t be translated because of parsing errors'.format(item[0]))
self.render(header, self.includedir + '/enums.hh')
self.mainHeader.add_include('enums.hh')
......@@ -491,44 +491,40 @@ class GenWrapper(object):
def render_header(self, _class):
if _class is not None:
try:
header = ClassHeader(_class, self.translator)
headerName = _class.name.to_snake_case() + '.hh'
self.mainHeader.add_include(headerName)
self.render(header, self.includedir + '/' + header.filename)
if type(_class) is not AbsApi.Interface:
self.impl.classes.append(header._class)
except AbsApi.Error as e:
print('Could not translate {0}: {1}'.format(_class.name.to_camel_case(fullName=True), e.args[0]))
header = ClassHeader(_class, self.translator)
headerName = _class.name.to_snake_case() + '.hh'
self.mainHeader.add_include(headerName)
self.render(header, self.includedir + '/' + header.filename)
if type(_class) is not AbsApi.Interface:
self.impl.classes.append(header._class)
def main():
argparser = argparse.ArgumentParser(description='Generate source files for the C++ wrapper')
argparser.add_argument('xmldir', type=str, help='Directory where the XML documentation of the Linphone\'s API generated by Doxygen is placed')
argparser.add_argument('-o --output', type=str, help='the directory where to generate the source files', dest='outputdir', default='.')
args = argparser.parse_args()
includedir = args.outputdir + '/include/linphone++'
srcdir = args.outputdir + '/src'
try:
os.makedirs(includedir)
except OSError as e:
if e.errno != errno.EEXIST:
print("Cannot create '{0}' directory: {1}".format(includedir, e.strerror))
sys.exit(1)
if __name__ == '__main__':
try:
os.makedirs(srcdir)
except OSError as e:
if e.errno != errno.EEXIST:
print("Cannot create '{0}' directory: {1}".format(srcdir, e.strerror))
sys.exit(1)
genwrapper = GenWrapper(includedir, srcdir, args.xmldir)
genwrapper.render_all()
argparser = argparse.ArgumentParser(description='Generate source files for the C++ wrapper')
argparser.add_argument('xmldir', type=str, help='Directory where the XML documentation of the Linphone\'s API generated by Doxygen is placed')
argparser.add_argument('-o --output', type=str, help='the directory where to generate the source files', dest='outputdir', default='.')
argparser.add_argument('-v --verbose', help='Show warning and info traces.', action='store_true', default=False, dest='verbose_mode')
argparser.add_argument('-d --debug', help='Show all traces.', action='store_true', default=False, dest='debug_mode')
args = argparser.parse_args()
if args.debug_mode:
loglevel = logging.DEBUG
elif args.verbose_mode:
loglevel = logging.INFO
else:
loglevel = logging.ERROR
logging.basicConfig(format='%(levelname)s[%(name)s]: %(message)s', level=loglevel)
includedir = args.outputdir + '/include/linphone++'
srcdir = args.outputdir + '/src'
if not os.path.exists(includedir):
os.makedirs(includedir)
if not os.path.exists(srcdir):
os.makedirs(srcdir)
if __name__ == '__main__':
main()
genwrapper = GenWrapper(includedir, srcdir, args.xmldir)
genwrapper.render_all()
except AbsApi.Error as e:
logging.critical(e)
......@@ -17,9 +17,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import argparse
import logging
import os
import sys
import pystache
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'tools'))
import genapixml as CApi
......@@ -401,20 +402,20 @@ class CsharpTranslator(object):
methodDict = self.translate_method(method, static=True, genImpl=True)
classDict['dllImports'].append(methodDict)
except AbsApi.Error as e:
print('Could not translate {0}: {1}'.format(method.name.to_c(), e.args[0]))
logging.error('Could not translate {0}: {1}'.format(method.name.to_c(), e.args[0]))
for prop in _class.properties:
try:
classDict['dllImports'] += self.translate_property(prop)
except AbsApi.Error as e:
print('error while translating {0} property: {1}'.format(prop.name.to_c(), e.args[0]))
logging.error('error while translating {0} property: {1}'.format(prop.name.to_c(), e.args[0]))
for method in _class.instanceMethods:
try:
methodDict = self.translate_method(method, static=False, genImpl=True)
classDict['dllImports'].append(methodDict)
except AbsApi.Error as e:
print('Could not translate {0}: {1}'.format(method.name.to_c(), e.args[0]))
logging.error('Could not translate {0}: {1}'.format(method.name.to_c(), e.args[0]))
return classDict
......@@ -469,12 +470,17 @@ def render(renderer, item, path):
f.write(content)
os.unlink(tmppath)
def main():
if __name__ == '__main__':
argparser = argparse.ArgumentParser(description='Generate source files for the C# wrapper')
argparser.add_argument('xmldir', type=str, help='Directory where the XML documentation of the Linphone\'s API generated by Doxygen is placed')
argparser.add_argument('-o --output', type=str, help='the directory where to generate the source files', dest='outputdir', default='.')
argparser.add_argument('-n --name', type=str, help='the name of the genarated source file', dest='outputfile', default='LinphoneWrapper.cs')
argparser.add_argument('-v --verbose', action='store_true', dest='verbose_mode', default=False, help='Verbose mode.')
args = argparser.parse_args()
loglevel = logging.INFO if args.verbose_mode else logging.ERROR
logging.basicConfig(format='%(levelname)s[%(name)s]: %(message)s', level=loglevel)
entries = os.listdir(args.outputdir)
......@@ -504,7 +510,7 @@ def main():
impl = EnumImpl(item[1], translator)
enums.append(impl)
else:
print('warning: {0} enum won\'t be translated because of parsing errors'.format(item[0]))
logging.warning('{0} enum won\'t be translated because of parsing errors'.format(item[0]))
interfaces = []
classes = []
......@@ -519,10 +525,7 @@ def main():
impl = InterfaceImpl(_class, translator)
interfaces.append(impl)
except AbsApi.Error as e:
print('Could not translate {0}: {1}'.format(_class.name.to_c(), e.args[0]))
logging.error('Could not translate {0}: {1}'.format(_class.name.to_c(), e.args[0]))
wrapper = WrapperImpl(enums, interfaces, classes)
render(renderer, wrapper, args.outputdir + "/" + args.outputfile)
if __name__ == '__main__':
main()
......@@ -18,13 +18,13 @@
# 02110-1301, USA.
import argparse
import errno
import logging
import os
import sys
import pystache
import errno
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'tools'))
print(sys.path)
import genapixml as CApi
import abstractapi as AbsApi
import metadoc
......@@ -456,7 +456,7 @@ class JavaTranslator(object):
classDict['methods'] += self.translate_property(_property)
classDict['jniMethods'] += self.translate_jni_property(_class.name, _property)
except AbsApi.Error as e:
print('error while translating {0} property: {1}'.format(_property.name.to_snake_case(), e.args[0]))
logging.error('error while translating {0} property: {1}'.format(_property.name.