Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KL0Kl-0002u8-8c for mharc-grub-devel@gnu.org; Mon, 21 Jul 2008 14:42:07 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KL0Kk-0002u3-F7 for grub-devel@gnu.org; Mon, 21 Jul 2008 14:42:06 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KL0Ki-0002tr-Ov for grub-devel@gnu.org; Mon, 21 Jul 2008 14:42:05 -0400 Received: from [199.232.76.173] (port=45535 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KL0Ki-0002to-H4 for grub-devel@gnu.org; Mon, 21 Jul 2008 14:42:04 -0400 Received: from ti-out-0910.google.com ([209.85.142.191]:33943) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KL0Kh-0006Rg-3C for grub-devel@gnu.org; Mon, 21 Jul 2008 14:42:03 -0400 Received: by ti-out-0910.google.com with SMTP id u5so802390tia.10 for ; Mon, 21 Jul 2008 11:42:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=gC7IHgv70n3DfrPQbFKMnoVMDEMyEFCW1bXPwwKNT9M=; b=Yt69QVe2ngrj8/Rp30xCcUuzdW+X6CdtknQcqSKhHy7vQRz0Vw1kuhBVJwmkjomIOi +/HyivjLea4aD9trdP2EaT13fTjoc1XcSjFK2lq2Kwk+z5AWghMxMqhqIJrPUhY6osWF NW3zFkXplVGvw506P4MMQL0N2XufhxbdLW/j8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=SCmbn6ZT6CiM9Oxo9HFMe3XMzdcqnH8WvMlakP8HSEYaoZBW/aiHIDuQKaPmJ4A+Bz gdVZFTDXxGtOAYZ0me/JpRi6AtSndR35oQ8kJnhq9VQqkTf5xVvzXfe8tFCuwl5z099p hWVLNPi4t1/yUKiEZ4EjahyO7acs9w1T/mdCI= Received: by 10.110.28.15 with SMTP id b15mr4057284tib.26.1216665721205; Mon, 21 Jul 2008 11:42:01 -0700 (PDT) Received: by 10.110.16.5 with HTTP; Mon, 21 Jul 2008 11:42:01 -0700 (PDT) Message-ID: Date: Tue, 22 Jul 2008 02:42:01 +0800 From: Bean To: "The development of GRUB 2" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <873am4ias5.fsf@xs4all.nl> <87mykbgnbm.fsf@xs4all.nl> X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) Subject: Re: Idea: elimination of the normal mode (revised version) X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Jul 2008 18:42:06 -0000 On Tue, Jul 22, 2008 at 2:03 AM, Bean wrote: > Your idea seems fine, but there is a slightly efficiency issue. For > example, when we need to call a function in the handler, we need to > acquire it using name. We need to do this in every call, as the > handler could be changed next time. > > My suggestion is to use function pointer instead of name, for example, > > grub_handler_register (&grub_handler_input_head, my_handler); > > Then we can always use grub_handler_input_head->getkey() to read a key. > > The drawback is that we need to define grub_handler_**_head as global variable. > Hi, Ok, I come up with a mixed solution. We can still register handler using string, like this: grub_handler_register ("input", my_input_handler); We don't need grub_handler_add. Whenever it sees a new string, grub_handler_register would create a item in the handler table. To get the handler, we use: grub_get_handler ("input", &local_input_handler_head); The handler is managed as linked list, the head always points to current selection, so we can use local_input_handler_head to call the handler function. To reduce unnecessary grub_get_handler calls, we export important handler head as global variable, for example, we can use the following in grub_main: grub_get_handler ("input", &grub_input_handler_head); grub_get_handler ("output", &grub_output_handler_head); ... Other modules can use grub_input_handler_head directly to access input handlers, but for custom handler such as "foo", they need to use grub_get_handler to get the handler pointer. -- Bean