From patchwork Tue Jul 5 11:45:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 944552 X-Patchwork-Delegate: jikos@jikos.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p65BjfU5002557 for ; Tue, 5 Jul 2011 11:45:42 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756098Ab1GELpl (ORCPT ); Tue, 5 Jul 2011 07:45:41 -0400 Received: from mail-fx0-f52.google.com ([209.85.161.52]:37593 "EHLO mail-fx0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755888Ab1GELpl (ORCPT ); Tue, 5 Jul 2011 07:45:41 -0400 Received: by mail-fx0-f52.google.com with SMTP id 18so6110868fxd.11 for ; Tue, 05 Jul 2011 04:45:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=1U2yscZGU09Ek3FmRbW0VbS6clKCOXHM0y4dzwfpoT0=; b=T9hxac+yB3RoTALgwibBTFmTHEn3ZfZ+t54xEJe7dgQU1mC+k7oDrkbnUA2N05eJ2q VoPKG1k2wrfUoTiyyssXaf8aXxghXeFols4ceSWeyg8Kxw6tJKmUYPmOkb6ALWquUzYj 5WwSNofgvHX5Skbz9o3hd3jR7I4swOy6IGi50= Received: by 10.223.13.198 with SMTP id d6mr11065303faa.119.1309866340545; Tue, 05 Jul 2011 04:45:40 -0700 (PDT) Received: from localhost.localdomain (u-084-c056.eap.uni-tuebingen.de [134.2.84.56]) by mx.google.com with ESMTPS id r10sm5238461fah.2.2011.07.05.04.45.39 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 05 Jul 2011 04:45:39 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: jkosina@suse.cz, padovan@profusion.mobi, David Herrmann Subject: [PATCH 08/12] HID: wiimote: Add wiimote event handler Date: Tue, 5 Jul 2011 13:45:15 +0200 Message-Id: <1309866319-12899-8-git-send-email-dh.herrmann@googlemail.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1309866319-12899-1-git-send-email-dh.herrmann@googlemail.com> References: <1309866319-12899-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 (demeter2.kernel.org [140.211.167.43]); Tue, 05 Jul 2011 11:45:43 +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 bfc5049..c86ae92 100644 --- a/drivers/hid/hid-wiimote.c +++ b/drivers/hid/hid-wiimote.c @@ -130,10 +130,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; @@ -143,6 +155,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; }