Example #1
0
	def visitInterface(self, node):
		self.__allInterfaces.append(node)
	
		scopedName = id.Name(node.scopedName())
		
		cxx_fqname = scopedName.fullyQualify()
		impl_flat_name = impl_fullname(scopedName)

		fqname = scopedName.fullyQualify(cxx = 0)

		
		# build methods corresponding to attributes, operations etc.
		# attributes[] and operations[] will contain lists of function
		# signatures eg
		#   [ char *echoString(const char *mesg) ]
		attributes = []
		operations = []
		virtual_operations = []

		# we need to consider all callables, including inherited ones
		# since this implementation class is not inheriting from anywhere
		# other than the IDL skeleton
		allInterfaces = [node] + ast.allInherits(node)
		allCallables = util.fold( map(lambda x:x.callables(), allInterfaces),
								  [], lambda x, y: x + y )


		# declarations[] contains a list of in-class decl signatures
		# implementations[] contains a list of out of line impl signatures
		# (typically differ by classname::)
		declarations = []
		implementations = []
		
		for c in allCallables:

			if isinstance(c, idlast.Attribute) :
				attrType = types.Type(c.attrType())
				d_attrType = attrType.deref()

				for i in c.identifiers():
					attribname = id.mapID(i)
					returnType = attrType.op(types.RET)
					inType = attrType.op(types.IN)
					attributes.append(returnType + " " + attribname + "()")
					# need a set method if not a readonly attribute
					if not c.readonly():
						args = attribname + "(" + inType + ")"
						declarations.append("void " + args)
						implementations.append("void " + impl_flat_name +\
											   "::" + args)
					if not attribname in self.ignore_operations:
						declarations.append(returnType + " " + attribname + "()")
						implementations.append(returnType + " " + impl_flat_name+\
										   "::" + attribname + "()")
			elif isinstance(c, idlast.Operation):
				params = []
				for p in c.parameters():
					paramType = types.Type(p.paramType())
					cxx_type = paramType.op(types.direction(p), use_out = 0)
					
					argname = id.mapID(p.identifier())
					params.append(cxx_type + " " + argname)

				# deal with possible "context"
				if c.contexts() != []:
					params.append("CORBA::Context_ptr _ctxt")

				return_type = types.Type(c.returnType()).op(types.RET)

				opname = id.mapID(c.identifier())
				if not opname in self.ignore_operations:
					arguments = string.join(params, ", ")
					args = opname + "(" + arguments + ")"
					declarations.append(return_type + " " + args)
					implementations.append(return_type + " " + \
										   impl_flat_name + \
										   "::" + args)
			else:
				util.fatalError("Internal error generating interface member")
				raise "No code for interface member: " + repr(c)

		# the class definition has no actual code...
		defs = string.join(map(lambda x:x + ";\n", declarations), "")

		# Output the class definition of the implementation
		self.stream_h.out(interface_def,
						  impl_fqname = impl_flat_name,
						  impl_name = impl_flat_name,
						  fq_name = fqname,
						  fq_POA_name = "POA_" + cxx_fqname,
						  operations = defs)

		# Output the class methods implementations
		impls = string.join(map(lambda x: x + """\

{
  // Please insert your code here and remove the following warning pragma
#ifndef WIN32
  #warning "Code missing in function <""" + x + """>"
#endif
}

""",
								implementations), "")
		
		self.stream_cpp.out(interface_code,
							fqname = fqname,
							impl_name = impl_flat_name,
							impl_fqname = impl_flat_name,
							operations = impls)
Example #2
0
    def visitInterface(self, node):
        self.__allInterfaces.append(node)
    
        scopedName = id.Name(node.scopedName())
        
        cxx_fqname = scopedName.fullyQualify()
        impl_flat_name = impl_fullname(scopedName)

        fqname = scopedName.fullyQualify(cxx = 0)

        
        # build methods corresponding to attributes, operations etc.
        # attributes[] and operations[] will contain lists of function
        # signatures eg
        #   [ char *echoString(const char *mesg) ]
        attributes = []
        operations = []
        virtual_operations = []

        # we need to consider all callables, including inherited ones
        # since this implementation class is not inheriting from anywhere
        # other than the IDL skeleton
        allInterfaces = [node] + ast.allInherits(node)
        allCallables = util.fold( map(lambda x:x.callables(), allInterfaces),
                                  [], lambda x, y: x + y )


        # declarations[] contains a list of in-class decl signatures
        # implementations[] contains a list of out of line impl signatures
        # (typically differ by classname::)
        declarations = []
        implementations = []
        
        for c in allCallables:
            if isinstance(c, idlast.Attribute):
                attrType = types.Type(c.attrType())
                d_attrType = attrType.deref()

                for i in c.identifiers():
                    attribname = id.mapID(i)
                    returnType = attrType.op(types.RET)
                    inType = attrType.op(types.IN)
                    attributes.append(returnType + " " + attribname + "()")
                    # need a set method if not a readonly attribute
                    if not c.readonly():
                        args = attribname + "(" + inType + ")"
                        declarations.append("void " + args)
                        implementations.append("void " + impl_flat_name +\
                                               "::" + args)
                    declarations.append(returnType + " " + attribname + "()")
                    implementations.append(returnType + " " + impl_flat_name+\
                                           "::" + attribname + "()")
            elif isinstance(c, idlast.Operation):
                params = []
                for p in c.parameters():
                    paramType = types.Type(p.paramType())
                    cxx_type = paramType.op(types.direction(p), use_out = 0)
                    
                    argname = id.mapID(p.identifier())
                    params.append(cxx_type + " " + argname)

                # deal with possible "context"
                if c.contexts() != []:
                    params.append("CORBA::Context_ptr _ctxt")

                return_type = types.Type(c.returnType()).op(types.RET)

                opname = id.mapID(c.identifier())
                arguments = string.join(params, ", ")
                args = opname + "(" + arguments + ")"
                declarations.append(return_type + " " + args)
                implementations.append(return_type + " " + impl_flat_name +\
                                       "::" + args)
            else:
                util.fatalError("Internal error generating interface member")
                raise AssertionError("No code for interface member: "+repr(c))

        # the class definition has no actual code...
        defs = string.join(map(lambda x:x + ";\n", declarations), "")
            
        # Output the _i class definition definition
        self.stream.out(template.interface_def,
                        impl_fqname = impl_flat_name,
                        impl_name = impl_flat_name,
                        fq_name = fqname,
                        fq_POA_name = "POA_" + cxx_fqname,
                        operations = defs)

        # Output the implementations of the class methods
        impls = string.join(map(lambda x: x + """\
{
  // insert code here and remove the warning
  #warning "Code missing in function <""" + x + """>"
}

""",
                                implementations), "")
               
        self.stream.out(template.interface_code,
                        fqname = fqname,
                        impl_name = impl_flat_name,
                        impl_fqname = impl_flat_name,
                        operations = impls)