blob: 9ae4304a737049a82ea9ad54134bd8ff6cb1dbb8 [file] [log] [blame]
Paul Stewart75897df2011-04-27 09:05:53 -07001// Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SHILL_EVENT_
6#define SHILL_EVENT_
7
8#include <vector>
9
Chris Masone0e1d1042011-05-09 18:07:03 -070010#include <base/basictypes.h>
11#include <base/callback.h>
12#include <base/message_loop.h>
13#include <base/ref_counted.h>
14#include <base/scoped_ptr.h>
15
16namespace base {
17class MessageLoopProxy;
18} // namespace base
19class Task;
20
Paul Stewart75897df2011-04-27 09:05:53 -070021namespace shill {
22
Paul Stewarta43d9232011-05-10 11:40:22 -070023struct InputData {
24 unsigned char *buf;
25 size_t len;
26};
27
28class IOInputHandler {
29 public:
30 IOInputHandler() {}
31 virtual ~IOInputHandler() {}
32};
33
Paul Stewart75897df2011-04-27 09:05:53 -070034// This is the main event dispatcher. It contains a central instance, and
35// is the entity responsible for dispatching events out of all queues to
36// their listeners during the idle loop.
37class EventDispatcher {
38 public:
Chris Masone0e1d1042011-05-09 18:07:03 -070039 EventDispatcher();
40 virtual ~EventDispatcher();
41 void DispatchForever();
42
43 // These are thin wrappers around calls of the same name in
44 // <base/message_loop_proxy.h>
45 bool PostTask(Task* task);
46 bool PostDelayedTask(Task* task, int64 delay_ms);
47
48 IOInputHandler *CreateInputHandler(int fd,
49 Callback1<InputData*>::Type *callback);
Paul Stewart75897df2011-04-27 09:05:53 -070050 private:
Chris Masone0e1d1042011-05-09 18:07:03 -070051 scoped_ptr<MessageLoop> dont_use_directly_;
52 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
Paul Stewart75897df2011-04-27 09:05:53 -070053};
54
55} // namespace shill
56
57#endif // SHILL_EVENT_