Exemplo n.º 1
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.º 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 genBus(bus, options, header):
	# create object file
	fileName = bus.name + '_bus' + ('.h' if header else '.c')
	filePath = os.path.join(options.outdir, fileName)
	out = Writer(filePath)
	genBusHeader(out, bus, options.client, header)

	if header:
		out.write("\n/**\n")
		out.write(" * @brief %s bus descriptor.\n", bus.name)
		out.write(" *\n")
		out.write(" * Reference to %s bus descripor.\n", bus.name)
		out.write(" **/\n")
		out.write("extern const struct obus_bus_desc *%s_bus_desc;\n", bus.name)

		ObusBusEventsWriter(bus).declareEventStruct(out)
		ObusBusEventsWriter(bus).declareEvents(out)
		ObusBusEventsWriter(bus).writeEventTypeStr(out, header)
		ObusBusEventsWriter(bus).writeEventsApi(out, options, header)
	else:

		# write events desc
		ObusBusEventsWriter(bus).writeEventsDesc(out)

		out.write("\n/* referenced objects supported by %s bus */\n", bus.name)
		for obj in bus.objects.values():
			out.write("extern const struct obus_object_desc %s_desc;\n",
				getObjectName(obj))

		out.write("\n/* array of %s objects descriptors */", bus.name)
		out.write("\nstatic const struct obus_object_desc *const objects[] = {\n")
		for obj in bus.objects.values():
			out.write("\t&%s_desc,\n", getObjectName(obj))
		out.write("};\n")

		out.write("/* %s bus description */", bus.name)
		out.write("\nstatic const struct obus_bus_desc %s_desc = {\n",
				 bus.name)
		out.write("\t.name = \"%s\",\n", bus.name)
		out.write("\t.n_objects = OBUS_SIZEOF_ARRAY(objects),\n")
		out.write("\t.objects = objects,\n")
		if bus.events:
			out.write("\t.n_events = OBUS_SIZEOF_ARRAY(%s),\n", ObusBusEventsWriter(bus).getEventsDescSymbol())
			out.write("\t.events = %s,\n", ObusBusEventsWriter(bus).getEventsDescSymbol())
		else:
			out.write("\t.n_events = 0,\n")
			out.write("\t.events = NULL,\n")

		out.write("\t.crc = 0,\n")
		out.write("};\n")

		out.write("\n/*public reference to %s  */\n", bus.name)
		out.write("const struct obus_bus_desc *%s_bus_desc = &%s_desc;\n", bus.name, bus.name)

		ObusBusEventsWriter(bus).writeEventTypeStr(out, header)
		ObusBusEventsWriter(bus).writeEventsApi(out, options, header)

	genBusFooter(out, header)
	out.close()
	indentFile(filePath)
Exemplo n.º 4
0
def genObject(obj, options, header):
	# create object file
	fileName = getObjectName(obj) + ('.h' if header else '.c')
	filePath = os.path.join(options.outdir, fileName)
	out = Writer(filePath)
	genHeader(out, obj, options.client, header)

	# generate object uid
	if header:
		out.write("/**\n")
		out.write(" * @brief %s object uid\n", getObjectName(obj))
		out.write(" **/\n")
		out.write("#define %s_%s_UID %d\n", obj.bus.name.upper(),
				obj.name.upper(), obj.uid)

	# generate enums
	for enum in obj.enums.values():
		if header:
			ObusEnumWriter(enum).writeDeclaration(out)
		else:
			ObusEnumWriter(enum).writeDriver(out)

	# generate object events
	if header:
		ObusEventsWriter(obj).declareEvents(out)
	else:
		# generate object struct
		genObjectStruct(out, obj)
		# generate events
		ObusEventsWriter(obj).writeEventsDesc(out)

	ObusEventsWriter(obj).writeEventTypeStr(out, header)

	if not header:
		# generate object methods struct
		ObusMethodsWriter(obj).writeMethodsDesc(out)
		# generate object desc
		genObjectDesc(out, obj)

	# generate object api
	genObjectApi(out, obj, options, header)

	# generate events api for client
	if options.client:
		ObusEventsWriter(obj).writeEventsApi(out, header)

	if options.client:
		# generate methods api
		ObusMethodsWriter(obj).writeMethodsApi(out, header)
		# generate object provider api
		genProviderApi(out, obj, options, header)

	genFooter(out, header)
	out.close()
	indentFile(filePath)
Exemplo n.º 5
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()