Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
senf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wiback
senf
Commits
b3de910d
Commit
b3de910d
authored
18 years ago
by
sbund
Browse files
Options
Downloads
Patches
Plain Diff
Support arbitrary file-handle-equivalent arguments to Scheduler::add and remove
parent
b544dd64
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Scheduler/Scheduler.ct
+39
-0
39 additions, 0 deletions
Scheduler/Scheduler.ct
Scheduler/Scheduler.cti
+55
-0
55 additions, 0 deletions
Scheduler/Scheduler.cti
Scheduler/Scheduler.hh
+17
-3
17 additions, 3 deletions
Scheduler/Scheduler.hh
Scheduler/Scheduler.test.cc
+22
-3
22 additions, 3 deletions
Scheduler/Scheduler.test.cc
with
133 additions
and
6 deletions
Scheduler/Scheduler.ct
0 → 100644
+
39
−
0
View file @
b3de910d
// $Id$
//
// Copyright (C) 2006
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
// Stefan Bund <stefan.bund@fokus.fraunhofer.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Definition of non-inline template functions
//#include "Scheduler.ih"
// Custom includes
#define prefix_
///////////////////////////////ct.p////////////////////////////////////////
///////////////////////////////ct.e////////////////////////////////////////
#undef prefix_
// Local Variables:
// mode: c++
// c-file-style: "satcom"
// End:
This diff is collapsed.
Click to expand it.
Scheduler/Scheduler.cti
0 → 100644
+
55
−
0
View file @
b3de910d
// $Id$
//
// Copyright (C) 2006
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
// Stefan Bund <stefan.bund@fokus.fraunhofer.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Definition of inline template functions
//#include "Scheduler.ih"
// Custom includes
#include <boost/bind.hpp>
#define prefix_ inline
///////////////////////////////cti.p///////////////////////////////////////
template <class Handle>
prefix_ void satcom::lib::Scheduler::add(Handle const & handle,
typename GenericCallback<Handle>::Callback const & cb,
EventId eventMask)
{
add(retrieve_filehandle(handle),boost::bind(cb,handle,_2),eventMask);
}
template <class Handle>
prefix_ void satcom::lib::Scheduler::remove(Handle const & handle, EventId eventMask)
{
// retrieve_filehandle is found via ADL
remove(retrieve_filehandle(handle),eventMask);
}
///////////////////////////////cti.e///////////////////////////////////////
#undef prefix_
// Local Variables:
// mode: c++
// c-file-style: "satcom"
// End:
This diff is collapsed.
Click to expand it.
Scheduler/Scheduler.hh
+
17
−
3
View file @
b3de910d
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
#include
<map>
#include
<map>
#include
<boost/function.hpp>
#include
<boost/function.hpp>
#include
<boost/utility.hpp>
#include
<boost/utility.hpp>
#include
<boost/call_traits.hpp>
//#include "scheduler.mpp"
//#include "scheduler.mpp"
///////////////////////////////hh.p////////////////////////////////////////
///////////////////////////////hh.p////////////////////////////////////////
...
@@ -52,7 +53,13 @@ namespace lib {
...
@@ -52,7 +53,13 @@ namespace lib {
enum
EventId
{
EV_NONE
=
0
,
enum
EventId
{
EV_NONE
=
0
,
EV_READ
=
1
,
EV_PRIO
=
2
,
EV_WRITE
=
4
,
EV_HUP
=
8
,
EV_ERR
=
16
,
EV_READ
=
1
,
EV_PRIO
=
2
,
EV_WRITE
=
4
,
EV_HUP
=
8
,
EV_ERR
=
16
,
EV_ALL
=
31
};
EV_ALL
=
31
};
typedef
boost
::
function
<
void
(
int
fd
,
EventId
event
)
>
Callback
;
template
<
class
Handle
>
struct
GenericCallback
{
typedef
boost
::
function
<
void
(
typename
boost
::
call_traits
<
Handle
>::
param_type
,
EventId
)
>
Callback
;
};
typedef
GenericCallback
<
int
>::
Callback
Callback
;
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///\name Structors and default members
///\name Structors and default members
...
@@ -72,6 +79,13 @@ namespace lib {
...
@@ -72,6 +79,13 @@ namespace lib {
void
add
(
int
fd
,
Callback
const
&
cb
,
EventId
eventMask
=
EV_ALL
);
void
add
(
int
fd
,
Callback
const
&
cb
,
EventId
eventMask
=
EV_ALL
);
void
remove
(
int
fd
,
EventId
eventMask
=
EV_ALL
);
void
remove
(
int
fd
,
EventId
eventMask
=
EV_ALL
);
template
<
class
Handle
>
void
add
(
Handle
const
&
handle
,
typename
GenericCallback
<
Handle
>::
Callback
const
&
cb
,
EventId
eventMask
=
EV_ALL
);
template
<
class
Handle
>
void
remove
(
Handle
const
&
handle
,
EventId
eventMask
=
EV_ALL
);
void
process
();
void
process
();
void
terminate
();
void
terminate
();
...
@@ -103,8 +117,8 @@ namespace lib {
...
@@ -103,8 +117,8 @@ namespace lib {
///////////////////////////////hh.e////////////////////////////////////////
///////////////////////////////hh.e////////////////////////////////////////
#include
"Scheduler.cci"
#include
"Scheduler.cci"
//
#include "Scheduler.ct"
#include
"Scheduler.ct"
//
#include "Scheduler.cti"
#include
"Scheduler.cti"
#endif
#endif
...
...
This diff is collapsed.
Click to expand it.
Scheduler/Scheduler.test.cc
+
22
−
3
View file @
b3de910d
...
@@ -163,7 +163,25 @@ namespace {
...
@@ -163,7 +163,25 @@ namespace {
}
}
Scheduler
::
instance
().
terminate
();
Scheduler
::
instance
().
terminate
();
}
}
struct
HandleWrapper
{
HandleWrapper
(
int
fd
,
std
::
string
const
&
tag
)
:
fd_
(
fd
),
tag_
(
tag
)
{}
int
fd_
;
std
::
string
tag_
;
};
int
retrieve_filehandle
(
HandleWrapper
const
&
handle
)
{
return
handle
.
fd_
;
}
void
handleCallback
(
HandleWrapper
const
&
handle
,
Scheduler
::
EventId
event
)
{
if
(
handle
.
tag_
!=
"TheTag"
)
return
;
callback
(
handle
.
fd_
,
event
);
}
}
}
BOOST_AUTO_UNIT_TEST
(
scheduler
)
BOOST_AUTO_UNIT_TEST
(
scheduler
)
...
@@ -198,14 +216,15 @@ BOOST_AUTO_UNIT_TEST(scheduler)
...
@@ -198,14 +216,15 @@ BOOST_AUTO_UNIT_TEST(scheduler)
buffer
[
size
]
=
0
;
buffer
[
size
]
=
0
;
BOOST_CHECK_EQUAL
(
buffer
,
"READ"
);
BOOST_CHECK_EQUAL
(
buffer
,
"READ"
);
BOOST_CHECK_NO_THROW
(
Scheduler
::
instance
().
add
(
sock
,
&
callback
,
Scheduler
::
EV_WRITE
)
);
HandleWrapper
handle
(
sock
,
"TheTag"
);
BOOST_CHECK_NO_THROW
(
Scheduler
::
instance
().
add
(
handle
,
&
handleCallback
,
Scheduler
::
EV_WRITE
)
);
strcpy
(
buffer
,
"WRITE"
);
strcpy
(
buffer
,
"WRITE"
);
size
=
5
;
size
=
5
;
event
=
Scheduler
::
EV_NONE
;
event
=
Scheduler
::
EV_NONE
;
BOOST_CHECK_NO_THROW
(
Scheduler
::
instance
().
process
()
);
BOOST_CHECK_NO_THROW
(
Scheduler
::
instance
().
process
()
);
BOOST_CHECK_EQUAL
(
event
,
Scheduler
::
EV_WRITE
);
BOOST_CHECK_EQUAL
(
event
,
Scheduler
::
EV_WRITE
);
BOOST_CHECK_NO_THROW
(
Scheduler
::
instance
().
remove
(
sock
,
Scheduler
::
EV_WRITE
)
);
BOOST_CHECK_NO_THROW
(
Scheduler
::
instance
().
remove
(
handle
,
Scheduler
::
EV_WRITE
)
);
event
=
Scheduler
::
EV_NONE
;
event
=
Scheduler
::
EV_NONE
;
BOOST_CHECK_NO_THROW
(
Scheduler
::
instance
().
process
()
);
BOOST_CHECK_NO_THROW
(
Scheduler
::
instance
().
process
()
);
BOOST_CHECK_EQUAL
(
event
,
Scheduler
::
EV_READ
);
BOOST_CHECK_EQUAL
(
event
,
Scheduler
::
EV_READ
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment