Easy Simple Network Library  0.3.7
WorkManager.h
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of "esnetwork" library.
4 It is licensed under the terms of the BSD license.
5 For the latest info, see http://esnetwork.sourceforge.net
6 
7 Copyright (c) 2012-2013 Lin Jia Jun (Joe Lam)
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 
13 1. Redistributions of source code must retain the above copyright notice, this
14  list of conditions and the following disclaimer.
15 2. Redistributions in binary form must reproduce the above copyright notice,
16  this list of conditions and the following disclaimer in the documentation
17  and/or other materials provided with the distribution.
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 -----------------------------------------------------------------------------
30 */
31 
32 #ifndef _ESN_WORKMANAGER_H_
33 #define _ESN_WORKMANAGER_H_
34 
35 #include "Work.h"
36 #include "Buffer.h"
37 #include "BufferManager.h"
38 
39 namespace esnlib
40 {
41 
44 {
45 
46 public:
47 
48  WorkManager(){}
49  virtual ~WorkManager(){}
50 
54  virtual int Stop() = 0;
55 
59  virtual int Abort() = 0;
60 
64  virtual int GetState() = 0;
65 
69  virtual int GetWorkerCount() = 0;
70 
74  virtual int GetTaskCount() = 0;
75 
81  virtual int AddWorkTask(WorkPtr work, BufferPtr workdata) = 0;
82 
86  virtual void SetBufferManager(BufferManagerPtr manager) = 0;
87 
93  virtual int PutWork(int key, WorkPtr work) = 0;
94 
99  virtual WorkPtr GetWork(int key) = 0;
100 
106  virtual int PutWork(const std::string& key, WorkPtr work) = 0;
107 
112  virtual WorkPtr GetWork(const std::string& key) = 0;
113 
114 };
115 
116 typedef boost::shared_ptr<WorkManager> WorkManagerPtr;
117 
122 WorkManagerPtr CreateWorkManager(int minworkercount = 0, int maxworkercount = 0, int workstack = 0);
129 
132 }
133 
134 #endif // WORKMANAGER_H
135 
Work Manager class (interface), it will work like a thread pool.
Definition: WorkManager.h:43
virtual int AddWorkTask(WorkPtr work, BufferPtr workdata)=0
virtual int Stop()=0
WorkManagerPtr CreateWorkManager(int minworkercount=0, int maxworkercount=0, int workstack=0)
virtual WorkPtr GetWork(int key)=0
virtual int GetWorkerCount()=0
virtual void SetBufferManager(BufferManagerPtr manager)=0
virtual int GetTaskCount()=0
virtual int PutWork(int key, WorkPtr work)=0
Definition: Buffer.h:37
virtual int GetState()=0
virtual int Abort()=0