~registry/scalestack/trunk

« back to all changes in this revision

Viewing changes to scalestack/event/libevent/service.h

  • Committer: Eric Day
  • Date: 2010-07-02 04:33:01 UTC
  • mfrom: (56.1.4)
  • Revision ID: git-v1:1084ed00d423bd6296f3362ba35e6781eca9233a
Merged style-updates branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Scale Stack
 
3
 *
 
4
 * Copyright (C) 2010 Eric Day (eday@oddments.org)
 
5
 * All rights reserved.
 
6
 *
 
7
 * Use and distribution licensed under the BSD license. See the
 
8
 * COPYING file in the root project directory for full text.
 
9
 */
 
10
 
 
11
/**
 
12
 * @file
 
13
 * @brief libevent Event Service Declarations
 
14
 */
 
15
 
 
16
#ifndef SCALESTACK_EVENT_LIBEVENT_SERVICE_H
 
17
#define SCALESTACK_EVENT_LIBEVENT_SERVICE_H
 
18
 
 
19
#include <vector>
 
20
 
 
21
#include <scalestack/common/macros.h>
 
22
#include <scalestack/event/service.h>
 
23
 
 
24
namespace scalestack
 
25
{
 
26
namespace event
 
27
{
 
28
 
 
29
class handler;
 
30
 
 
31
namespace libevent
 
32
{
 
33
 
 
34
class handler_provider;
 
35
class thread;
 
36
 
 
37
class SCALESTACK_API service: public event::service
 
38
{
 
39
public:
 
40
 
 
41
  /**
 
42
   * Add the number of threads specified in the "threads" option.
 
43
   *
 
44
   * @param[in] module Module that the service is associated with.
 
45
   */
 
46
  service(kernel::module& module);
 
47
 
 
48
  ~service();
 
49
 
 
50
  /**
 
51
   * Add a handler to one of the threads in the service pool.
 
52
   *
 
53
   * @param[in] handler Handler to add.
 
54
   * @param[in] handler_service_provider Handler service the handler
 
55
   *  belongs to.
 
56
   */
 
57
  void add_handler(event::handler* handler,
 
58
                   handler_service_provider& handler_service_provider);
 
59
 
 
60
  /**
 
61
   * Remove handler that was previously added in add_handler().
 
62
   *
 
63
   * @param[in] handler_provider Handler provider to remove.
 
64
   */
 
65
  void remove_handler(handler_provider* handler_provider);
 
66
 
 
67
private:
 
68
 
 
69
  /**
 
70
   * Don't allow copying of objects.
 
71
   */
 
72
  SCALESTACK_LOCAL
 
73
  service(const service&);
 
74
 
 
75
  /**
 
76
   * Don't allow assignment of objects.
 
77
   */
 
78
  SCALESTACK_LOCAL
 
79
  service& operator=(const service&);
 
80
 
 
81
  /**
 
82
   * Remove all threads that were created in the constructor.
 
83
   */
 
84
  void _remove_threads(void);
 
85
 
 
86
  /**
 
87
   * See event::service::_add_handler_service().
 
88
   */
 
89
  event::handler_service_provider& _add_handler_service(event::handler_service& handler_service);
 
90
 
 
91
  /**
 
92
   * See event::service::_remove_handler_service().
 
93
   */
 
94
  void _remove_handler_service(event::handler_service_provider& handler_service_provider);
 
95
 
 
96
  typedef std::vector<thread*> threads;
 
97
 
 
98
  size_t _current_thread;
 
99
  threads _threads;
 
100
};
 
101
 
 
102
} /* namespace libevent */
 
103
} /* namespace event */
 
104
} /* namespace scalestack */
 
105
 
 
106
#endif /* SCALESTACK_EVENT_LIBEVENT_SERVICE_H */