From patchwork Fri Jun 17 14:49:18 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 891832 X-Patchwork-Delegate: jikos@jikos.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5HEsZCj010597 for ; Fri, 17 Jun 2011 14:54:36 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932483Ab1FQOyc (ORCPT ); Fri, 17 Jun 2011 10:54:32 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:42274 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757946Ab1FQOuY (ORCPT ); Fri, 17 Jun 2011 10:50:24 -0400 Received: by fxm17 with SMTP id 17so1796189fxm.19 for ; Fri, 17 Jun 2011 07:50:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=Fxe9cxjhbWDvviv8wwlEhvwCiUnln+9W9X4c/jAk3F4=; b=n4f7hlZeY7W4azQgrtFV8Lh2bt6+wfWg+9CEnhmS9S8bhd0SK3cDC4/bRm1NW1Ltl6 TMzZ6hEmqFZJxZIbCIJq5BMzAxqM3YgdXGjmISRpjDJ7iC6AVr6pKAa3AuwL89CkkGFO vOaPa/b6GR5cBqNQKx/DoJ2Y5sbTNjjeK+OQI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=MRuoJxc967BuiyKtgIOJAE/WUEoBtk+MTgF7ZD38P1ItTJ4fC1Wirx8zqCeWhXiZ9e vB/nbZjXhFz5h7f7lA30CmtOHnqX1sDhB1wtXlDBVTepQhSupSjJBKf5tzAOmpBAlLkn uW8q7owMBLCeTN83m8xTfzyYCmw39zVI38HVs= Received: by 10.223.53.85 with SMTP id l21mr2644957fag.26.1308322223574; Fri, 17 Jun 2011 07:50:23 -0700 (PDT) Received: from localhost.localdomain (stgt-4d039afc.pool.mediaWays.net [77.3.154.252]) by mx.google.com with ESMTPS id o10sm1378710fah.31.2011.06.17.07.50.22 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 17 Jun 2011 07:50:22 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: padovan@profusion.mobi, jkosina@suse.cz, oliver@neukum.org, dh.herrmann@googlemail.com Subject: [PATCH 08/12 v2] HID: wiimote: Add wiimote event handler Date: Fri, 17 Jun 2011 16:49:18 +0200 Message-Id: <1308322162-13953-8-git-send-email-dh.herrmann@googlemail.com> X-Mailer: git-send-email 1.7.5.2 In-Reply-To: <1308322162-13953-1-git-send-email-dh.herrmann@googlemail.com> References: <1308322162-13953-1-git-send-email-dh.herrmann@googlemail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 17 Jun 2011 14:54:36 +0000 (UTC) Create array of all event handlers and call each handler when we receive the related event. Signed-off-by: David Herrmann --- drivers/hid/hid-wiimote.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c index c06fdc8..38e2cfe 100644 --- a/drivers/hid/hid-wiimote.c +++ b/drivers/hid/hid-wiimote.c @@ -143,10 +143,22 @@ static int wiimote_input_event(struct input_dev *dev, unsigned int type, return 0; } +struct wiiproto_handler { + __u8 id; + size_t size; + void (*func)(struct wiimote_data *wdata, const __u8 *payload); +}; + +static struct wiiproto_handler handlers[] = { + { .id = 0 } +}; + static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, u8 *raw_data, int size) { struct wiimote_data *wdata = hid_get_drvdata(hdev); + struct wiiproto_handler *h; + int i; if (!atomic_read(&wdata->ready)) return -EBUSY; @@ -155,6 +167,12 @@ static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, if (size < 1) return -EINVAL; + for (i = 0; handlers[i].id; ++i) { + h = &handlers[i]; + if (h->id == raw_data[0] && h->size < size) + h->func(wdata, &raw_data[1]); + } + return 0; }