def _generate_route_m(self, route, namespace, route_args, extra_args, task_type_name, func_suffix): """Generates route method implementation for the given route.""" user_args = list(route_args) transport_args = [ ('route', 'route'), ('arg', 'arg' if not is_void_type(route.arg_data_type) else 'nil'), ] for name, value, typ in extra_args: user_args.append((name, typ)) transport_args.append((name, value)) with self.block_func( func='{}{}'.format(fmt_route_func(route), func_suffix), args=fmt_func_args_declaration(user_args), return_type='{} *'.format(task_type_name)): self.emit('DBRoute *route = {}.{};'.format( fmt_route_obj_class(namespace.name), fmt_route_var(namespace.name, route))) if is_union_type(route.arg_data_type): self.emit('{} *arg = {};'.format( fmt_class_prefix(route.arg_data_type), fmt_var(route.arg_data_type.name))) elif not is_void_type(route.arg_data_type): init_call = fmt_func_call( caller=fmt_alloc_call( caller=fmt_class_prefix(route.arg_data_type)), callee=self._cstor_name_from_fields_names(route_args), args=fmt_func_args([(f[0], f[0]) for f in route_args])) self.emit('{} *arg = {};'.format( fmt_class_prefix(route.arg_data_type), init_call)) request_call = fmt_func_call( caller='self.client', callee='request{}'.format( fmt_camel_upper(route.attrs.get('style'))), args=fmt_func_args(transport_args)) self.emit('return {};'.format(request_call)) self.emit()
def _generate_route_m(self, route, namespace, route_args, extra_args, task_type_name, func_suffix): """Generates route method implementation for the given route.""" user_args = list(route_args) transport_args = [ ('route', 'route'), ('arg', 'arg' if not is_void_type(route.arg_data_type) else 'nil'), ] for name, value, typ in extra_args: user_args.append((name, typ)) transport_args.append((name, value)) with self.block_func( func='{}{}'.format(fmt_var(route.name), func_suffix), args=fmt_func_args_declaration(user_args), return_type='{} *'.format(task_type_name)): self.emit('DBRoute *route = {}.{};'.format( fmt_route_obj_class(namespace.name), fmt_route_var(namespace.name, route.name))) if is_union_type(route.arg_data_type): self.emit('{} *arg = {};'.format( fmt_class_prefix(route.arg_data_type), fmt_var(route.arg_data_type.name))) elif not is_void_type(route.arg_data_type): init_call = fmt_func_call( caller=fmt_alloc_call( caller=fmt_class_prefix(route.arg_data_type)), callee=self._cstor_name_from_fields_names(route_args), args=fmt_func_args([(f[0], f[0]) for f in route_args])) self.emit('{} *arg = {};'.format( fmt_class_prefix(route.arg_data_type), init_call)) request_call = fmt_func_call( caller='self.client', callee='request{}'.format( fmt_camel_upper(route.attrs.get('style'))), args=fmt_func_args(transport_args)) self.emit('return {};'.format(request_call)) self.emit()
def generate(self, api): for namespace in api.namespaces.values(): self.namespace_to_has_routes[namespace] = False if namespace.routes: for route in namespace.routes: if self._should_generate_route(route): self.namespace_to_has_routes[namespace] = True break for namespace in api.namespaces.values(): for data_type in namespace.linearize_data_types(): self.obj_name_to_namespace[data_type.name] = fmt_class_prefix( data_type) for namespace in api.namespaces.values(): if namespace.routes and self.namespace_to_has_routes[namespace]: import_classes = [ fmt_routes_class(namespace.name, self.args.auth_type), fmt_route_obj_class(namespace.name), '{}Protocol'.format(self.args.transport_client_name), 'DBStoneBase', 'DBRequestErrors', ] with self.output_to_relative_path('Routes/{}.m'.format( fmt_routes_class(namespace.name, self.args.auth_type))): self.emit_raw(stone_warning) imports_classes_m = import_classes + \ self._get_imports_m( self._get_namespace_route_imports(namespace), []) self._generate_imports_m(imports_classes_m) self._generate_routes_m(namespace) with self.output_to_relative_path('Routes/{}.h'.format( fmt_routes_class(namespace.name, self.args.auth_type))): self.emit_raw(base_file_comment) self.emit('#import <Foundation/Foundation.h>') self.emit() self.emit(fmt_import('DBTasks')) self.emit() import_classes_h = [ 'DBNilObject', ] import_classes_h = (import_classes_h + self._get_imports_h( self._get_namespace_route_imports( namespace, include_route_args=False, include_route_deep_args=True))) self._generate_imports_h(import_classes_h) self.emit( '@protocol {};'.format( self.args.transport_client_name), ) self.emit() self._generate_routes_h(namespace) with self.output_to_relative_path( 'Client/{}.m'.format(self.args.module_name)): self._generate_client_m(api) with self.output_to_relative_path( 'Client/{}.h'.format(self.args.module_name)): self._generate_client_h(api)
def generate(self, api): for namespace in api.namespaces.values(): self.namespace_to_has_routes[namespace] = False if namespace.routes: for route in namespace.routes: if route.attrs.get( 'auth') == self.args.auth_type or route.attrs.get( 'auth') == 'noauth' and self.args.auth_type == 'user': self.namespace_to_has_routes[namespace] = True break for namespace in api.namespaces.values(): for data_type in namespace.linearize_data_types(): self.obj_name_to_namespace[data_type.name] = fmt_class_prefix( data_type) for namespace in api.namespaces.values(): if namespace.routes and self.namespace_to_has_routes[namespace]: import_classes = [ fmt_routes_class(namespace.name, self.args.auth_type), fmt_route_obj_class(namespace.name), '{}Protocol'.format(self.args.transport_client_name), 'DBStoneBase', 'DBRequestErrors', ] with self.output_to_relative_path('Routes/{}.m'.format( fmt_routes_class(namespace.name, self.args.auth_type))): self.emit_raw(stone_warning) imports_classes_m = import_classes + \ self._get_imports_m( self._get_namespace_route_imports(namespace), []) self._generate_imports_m(imports_classes_m) self._generate_routes_m(namespace) with self.output_to_relative_path('Routes/{}.h'.format( fmt_routes_class(namespace.name, self.args.auth_type))): self.emit_raw(base_file_comment) self.emit('#import <Foundation/Foundation.h>') self.emit() self.emit(fmt_import('DBTasks')) self.emit() import_classes_h = [ 'DBNilObject', ] import_classes_h = (import_classes_h + self._get_imports_h( self._get_namespace_route_imports( namespace, include_route_args=False, include_route_deep_args=True))) self._generate_imports_h(import_classes_h) self.emit( '@protocol {};'.format( self.args.transport_client_name), ) self.emit() self._generate_routes_h(namespace) with self.output_to_relative_path( 'Client/{}.m'.format(self.args.module_name)): self._generate_client_m(api) with self.output_to_relative_path( 'Client/{}.h'.format(self.args.module_name)): self._generate_client_h(api)