Exemplo n.º 1
0
def genHeader(out, obj, client, header):
	brief = 'obus {0} object {1} api'.format(getObjectName(obj), \
		'client' if client else 'server')

	writeHeader(out, brief)
	if header:
		guard = os.path.splitext(os.path.basename(out.fd.name))[0].upper()
		out.write("#ifndef _%s_H_\n", guard)
		out.write("#define _%s_H_\n", guard)
		out.write("\n")
		out.write("#include \"libobus.h\"\n")
		out.write("\n/* *INDENT-OFF* */\nOBUS_BEGIN_DECLS\n/* *INDENT-ON* */\n")
		out.write("\n")
	else:
		out.write("#ifndef _GNU_SOURCE\n")
		out.write("#define _GNU_SOURCE\n")
		out.write("#endif\n")
		out.write("\n")
		out.write("#include <stdio.h>\n")
		out.write("#include <stdlib.h>\n")
		out.write("#include <errno.h>\n")
		out.write("#include <stdint.h>\n")
		out.write("#include <string.h>\n")
		out.write("\n")
		out.write("#define OBUS_USE_PRIVATE\n")
		out.write("#include \"libobus.h\"\n")
		out.write("#include \"libobus_private.h\"\n")
		out.write("#include \"%s.h\"\n", getObjectName(obj))
		out.write("\n")
Exemplo n.º 2
0
def main(options, xmlFile):
	# Only server api available
	if options.client:
		logging.error("Client api generation not available for vala")
		sys.exit(1)

	try:
		bus = ObusBus(xmlFile)
	except ObusException as ex:
		logging.error(ex)
		return

	if options.listFiles:
		listFiles(options, bus)
		mainC(options, xmlFile)
		return

	vapiPath = os.path.join(options.outdir, bus.name.lower() + ".vapi")
	out = Writer(vapiPath)
	writeHeader(out, bus.name + " bus vala interface file")
	out.write("\n")
	out.write("namespace %s {\n", toCamelcase(bus.name, False))
	writeBus(out, bus)
	for obj in bus.objects.values():
		writeObject(out, obj)
	out.write("}\n")
	out.close()

	# And now call c generator
	mainC(options, xmlFile)
Exemplo n.º 3
0
def main(options, xmlFile):
    # Only server api available
    if options.client:
        logging.error("Client api generation not available for vala")
        sys.exit(1)

    try:
        bus = ObusBus(xmlFile)
    except ObusException as ex:
        logging.error(ex)
        return

    if options.listFiles:
        listFiles(options, bus)
        mainC(options, xmlFile)
        return

    vapiPath = os.path.join(options.outdir, bus.name.lower() + ".vapi")
    out = Writer(vapiPath)
    writeHeader(out, bus.name + " bus vala interface file")
    out.write("\n")
    out.write("namespace %s {\n", toCamelcase(bus.name, False))
    writeBus(out, bus)
    for obj in bus.objects.values():
        writeObject(out, obj)
    out.write("}\n")
    out.close()

    # And now call c generator
    mainC(options, xmlFile)
Exemplo n.º 4
0
def main(options, xmlFile):

	# Only client api available
	if not options.client:
		logging.error("Server api generation not available for java")
		sys.exit(1)

	try:
		bus = ObusBus(xmlFile)
	except ObusException as ex:
		logging.error(ex)
		return

	if options.listFiles:
		listFiles(options, bus)
		return

	# create package path
	intfPath = os.path.join(options.outdir, options.javaPackage.replace('.', '/'))
	implPath = os.path.join(intfPath, "impl")
	mockPath = os.path.join(intfPath, "mock")
	try:
		os.makedirs(intfPath)
	except OSError as ex:
		if ex.errno != errno.EEXIST:
			logging.error(ex)
			return
	try:
		os.makedirs(implPath)
	except OSError as ex:
		if ex.errno != errno.EEXIST:
			logging.error(ex)
			return
	try:
		os.makedirs(mockPath)
	except OSError as ex:
		if ex.errno != errno.EEXIST:
			logging.error(ex)
			return

	busName = bus.name

	# Generate bus Event interface file
	fileName = getInterfaceNameBus(bus.name) + ".java"
	filePath = os.path.join(intfPath, fileName)
	out = Writer(filePath)
	writeHeader(out, getInterfaceNameBus(bus.name))
	genBusEventIntf(options, bus, out)
	out.close()

	# Generate bus file
	fileName = getClassNameBus(bus.name) + ".java"
	filePath = os.path.join(implPath, fileName)
	out = Writer(filePath)
	writeHeader(out, getClassNameBus(bus.name))
	genBus(options, bus, out)
	out.close()

	# Generate object files
	for obj in bus.objects.values():
		# interface
		objName = obj.name
		fileName = getIntfNameObject(busName, objName) + ".java"
		filePath = os.path.join(intfPath, fileName)
		out = Writer(filePath)
		writeHeader(out, getIntfNameObject(busName, objName))
		genObjIntf(options, bus, obj, out)
		out.close()

		# implementation
		objName = obj.name
		fileName = getClassNameObject(busName, objName) + ".java"
		filePath = os.path.join(implPath, fileName)
		out = Writer(filePath)
		writeHeader(out, getClassNameObject(busName, objName))
		genObj(options, bus, obj, out)
		out.close()

		# mock implementation
		objName = obj.name
		fileName = getClassNameMockObject(busName, objName) + ".java"
		filePath = os.path.join(mockPath, fileName)
		out = Writer(filePath)
		writeHeader(out, getClassNameMockObject(busName, objName))
		genMockObj(options, bus, obj, out)
		out.close()