Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
f34a468a
Commit
f34a468a
authored
May 25, 2010
by
Martin Sustrik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
coding style fixed in zmqd
parent
7773fddd
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
107 deletions
+103
-107
zmqd.cpp
zmqd/zmqd.cpp
+103
-107
No files found.
zmqd/zmqd.cpp
View file @
f34a468a
...
...
@@ -24,22 +24,22 @@
#include "../include/zmq.hpp"
#include "../foreign/xmlParser/xmlParser.cpp"
namespace
{
class
device_cfg_t
{
class
device_cfg_t
{
enum
endpoint_direction
{
connect
,
bind
};
typedef
std
::
pair
<
endpoint_direction
,
std
::
string
>
sock_details_t
;
typedef
std
::
pair
<
endpoint_direction
,
std
::
string
>
sock_details_t
;
typedef
std
::
vector
<
sock_details_t
>
vsock_dets_t
;
typedef
std
::
vector
<
sock_details_t
>
vsock_dets_t
;
public
:
public
:
explicit
device_cfg_t
(
int
type
)
:
device_type
(
type
)
,
context
(
0
)
,
in_socket
(
0
),
out_socket
(
0
)
explicit
device_cfg_t
(
int
type
)
:
device_type
(
type
),
context
(
0
),
in_socket
(
0
),
out_socket
(
0
)
{
}
...
...
@@ -49,71 +49,69 @@ namespace {
delete
in_socket
;
}
bool
init
(
XMLNode
&
device
)
bool
init
(
XMLNode
&
device
)
{
XMLNode
in_node
=
device
.
getChildNode
(
"in"
);
if
(
in_node
.
isEmpty
())
{
fprintf
(
stderr
,
"'in' node is missing in the configuration file
\n
"
);
fprintf
(
stderr
,
"'in' node is missing in the configuration file
\n
"
);
return
false
;
}
XMLNode
out_node
=
device
.
getChildNode
(
"out"
);
if
(
out_node
.
isEmpty
())
{
fprintf
(
stderr
,
"'out' node is missing in the configuration file
\n
"
);
fprintf
(
stderr
,
"'out' node is missing in the configuration file
\n
"
);
return
false
;
}
if
(
!
process_node
(
in_node
,
true
,
device_cfg_t
::
bind
))
if
(
!
process_node
(
in_node
,
true
,
device_cfg_t
::
bind
))
return
false
;
if
(
!
process_node
(
in_node
,
true
,
device_cfg_t
::
connect
))
if
(
!
process_node
(
in_node
,
true
,
device_cfg_t
::
connect
))
return
false
;
if
(
!
process_node
(
out_node
,
false
,
device_cfg_t
::
bind
))
if
(
!
process_node
(
out_node
,
false
,
device_cfg_t
::
bind
))
return
false
;
if
(
!
process_node
(
out_node
,
false
,
device_cfg_t
::
connect
))
if
(
!
process_node
(
out_node
,
false
,
device_cfg_t
::
connect
))
return
false
;
return
true
;
}
void
set_context
(
zmq
::
context_t
*
context_
)
void
set_context
(
zmq
::
context_t
*
context_
)
{
context
=
context_
;
}
zmq
::
context_t
*
get_context
()
const
zmq
::
context_t
*
get_context
()
const
{
return
context
;
}
virtual
bool
make_sockets
()
=
0
;
virtual
bool
make_sockets
()
=
0
;
bool
set_up_connections
()
bool
set_up_connections
()
{
for
(
vsock_dets_t
::
const_iterator
i
=
in
.
begin
()
;
i
!=
in
.
end
();
for
(
vsock_dets_t
::
const_iterator
i
=
in
.
begin
();
i
!=
in
.
end
();
++
i
)
{
switch
(
i
->
first
)
{
case
device_cfg_t
:
:
connect
:
in_socket
->
connect
(
i
->
second
.
c_str
());
case
device_cfg_t
:
:
connect
:
in_socket
->
connect
(
i
->
second
.
c_str
());
break
;
case
device_cfg_t
:
:
bind
:
in_socket
->
bind
(
i
->
second
.
c_str
());
case
device_cfg_t
:
:
bind
:
in_socket
->
bind
(
i
->
second
.
c_str
());
}
}
for
(
vsock_dets_t
::
const_iterator
i
=
out
.
begin
()
;
i
!=
out
.
end
();
for
(
vsock_dets_t
::
const_iterator
i
=
out
.
begin
();
i
!=
out
.
end
();
++
i
)
{
switch
(
i
->
first
)
{
case
device_cfg_t
:
:
connect
:
out_socket
->
connect
(
i
->
second
.
c_str
());
case
device_cfg_t
:
:
connect
:
out_socket
->
connect
(
i
->
second
.
c_str
());
break
;
case
device_cfg_t
:
:
bind
:
out_socket
->
bind
(
i
->
second
.
c_str
());
case
device_cfg_t
:
:
bind
:
out_socket
->
bind
(
i
->
second
.
c_str
());
}
}
...
...
@@ -126,25 +124,24 @@ namespace {
}
protected
:
protected
:
bool
make_sockets
(
int
in_type
,
int
out_type
)
bool
make_sockets
(
int
in_type
,
int
out_type
)
{
in_socket
=
new
(
std
::
nothrow
)
zmq
::
socket_t
(
*
context
,
in_type
);
in_socket
=
new
(
std
::
nothrow
)
zmq
::
socket_t
(
*
context
,
in_type
);
if
(
!
in_socket
)
return
false
;
out_socket
=
new
(
std
::
nothrow
)
zmq
::
socket_t
(
*
context
,
out_type
);
out_socket
=
new
(
std
::
nothrow
)
zmq
::
socket_t
(
*
context
,
out_type
);
if
(
!
out_socket
)
{
return
false
;
}
return
true
;
}
int
process_node
(
XMLNode
&
target_
,
bool
in_
,
int
process_node
(
XMLNode
&
target_
,
bool
in_
,
device_cfg_t
::
endpoint_direction
ept_
)
{
const
char
*
name
=
const
char
*
name
=
(
ept_
==
device_cfg_t
::
connect
)
?
"connect"
:
"bind"
;
int
n
=
0
;
while
(
true
)
{
...
...
@@ -159,9 +156,9 @@ namespace {
}
if
(
in_
)
in
.
push_back
(
sock_details_t
(
ept_
,
addr
));
in
.
push_back
(
sock_details_t
(
ept_
,
addr
));
else
out
.
push_back
(
sock_details_t
(
ept_
,
addr
));
out
.
push_back
(
sock_details_t
(
ept_
,
addr
));
n
++
;
}
...
...
@@ -170,63 +167,74 @@ namespace {
}
protected
:
protected
:
int
device_type
;
zmq
::
context_t
*
context
;
zmq
::
context_t
*
context
;
vsock_dets_t
in
;
vsock_dets_t
out
;
zmq
::
socket_t
*
in_socket
;
zmq
::
socket_t
*
out_socket
;
zmq
::
socket_t
*
in_socket
;
zmq
::
socket_t
*
out_socket
;
private
:
device_cfg_t
(
device_cfg_t
const
&
);
void
operator
=
(
device_cfg_t
const
&
);
};
private
:
void
operator
=
(
device_cfg_t
const
&
);
device_cfg_t
(
device_cfg_t
const
&
);
};
class
queue_device_cfg_t
:
public
device_cfg_t
{
public
:
queue_device_cfg_t
()
:
device_cfg_t
(
ZMQ_QUEUE
)
{
}
virtual
bool
make_sockets
()
{
return
device_cfg_t
::
make_sockets
(
ZMQ_XREP
,
ZMQ_XREQ
);
}
};
class
streamer_device_cfg_t
:
public
device_cfg_t
{
public
:
streamer_device_cfg_t
()
:
device_cfg_t
(
ZMQ_STREAMER
)
{
}
class
queue_device_cfg_t
:
public
device_cfg_t
virtual
bool
make_sockets
()
{
public
:
queue_device_cfg_t
()
:
device_cfg_t
(
ZMQ_QUEUE
)
{}
virtual
bool
make_sockets
(){
return
device_cfg_t
::
make_sockets
(
ZMQ_XREP
,
ZMQ_XREQ
);
return
device_cfg_t
::
make_sockets
(
ZMQ_UPSTREAM
,
ZMQ_DOWNSTREAM
);
}
};
};
class
forwarder_device_cfg_t
:
public
device_cfg_t
{
public
:
class
streamer_device_cfg_t
:
public
device_cfg_t
forwarder_device_cfg_t
()
:
device_cfg_t
(
ZMQ_FORWARDER
)
{
public
:
streamer_device_cfg_t
()
:
device_cfg_t
(
ZMQ_STREAMER
)
{}
virtual
bool
make_sockets
()
{
return
device_cfg_t
::
make_sockets
(
ZMQ_UPSTREAM
,
ZMQ_DOWNSTREAM
);
}
};
class
forwarder_device_cfg_t
:
public
device_cfg_t
virtual
bool
make_sockets
()
{
public
:
forwarder_device_cfg_t
()
:
device_cfg_t
(
ZMQ_FORWARDER
)
{}
virtual
bool
make_sockets
()
{
if
(
!
device_cfg_t
::
make_sockets
(
ZMQ_SUB
,
ZMQ_PUB
)
)
{
if
(
!
device_cfg_t
::
make_sockets
(
ZMQ_SUB
,
ZMQ_PUB
)
)
{
return
false
;
}
in_socket
->
setsockopt
(
ZMQ_SUBSCRIBE
,
""
,
0
);
return
true
;
}
};
};
device_cfg_t
*
make_device_config
(
XMLNode
&
device
)
{
device_cfg_t
*
make_device_config
(
XMLNode
&
device
)
{
const
char
*
dev_type
=
device
.
getAttribute
(
"type"
);
if
(
!
dev_type
)
{
...
...
@@ -248,33 +256,32 @@ namespace {
"should be named 'forwarder', 'streamer' or 'queue'
\n
"
);
return
NULL
;
}
}
extern
"C"
void
*
worker_function
(
void
*
arg
)
{
extern
"C"
void
*
worker_function
(
void
*
arg
)
{
if
(
!
arg
)
{
fprintf
(
stderr
,
"arg is null, returning
\n
"
);
return
0
;
}
std
::
auto_ptr
<
device_cfg_t
>
cfg
(
(
device_cfg_t
*
)
arg
);
std
::
auto_ptr
<
device_cfg_t
>
cfg
((
device_cfg_t
*
)
arg
);
zmq
::
context_t
*
ctx
=
cfg
->
get_context
();
zmq
::
context_t
*
ctx
=
cfg
->
get_context
();
if
(
!
ctx
)
{
fprintf
(
stderr
,
"no context, returning
\n
"
);
return
0
;
}
if
(
!
cfg
->
make_sockets
())
{
if
(
!
cfg
->
make_sockets
())
{
fprintf
(
stderr
,
"failed to make sockets, returning
\n
"
);
return
0
;
}
if
(
!
cfg
->
set_up_connections
())
{
if
(
!
cfg
->
set_up_connections
())
{
fprintf
(
stderr
,
"failed to set up connections, returning
\n
"
);
return
0
;
}
...
...
@@ -282,13 +289,8 @@ namespace {
cfg
->
run
();
return
0
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
!=
2
)
{
...
...
@@ -309,8 +311,7 @@ int main (int argc, char *argv [])
return
1
;
}
std
::
vector
<
device_cfg_t
*>
vdev
;
std
::
vector
<
device_cfg_t
*>
vdev
;
while
(
true
)
{
...
...
@@ -319,49 +320,44 @@ int main (int argc, char *argv [])
if
(
device
.
isEmpty
())
break
;
device_cfg_t
*
dev
=
make_device_config
(
device
);
device_cfg_t
*
dev
=
make_device_config
(
device
);
if
(
!
dev
)
{
fprintf
(
stderr
,
"failed to create device config
\n
"
);
return
1
;
}
if
(
!
dev
->
init
(
device
)
)
{
if
(
!
dev
->
init
(
device
))
{
fprintf
(
stderr
,
"error with initialising device configuration
\n
"
);
delete
dev
;
return
1
;
}
vdev
.
push_back
(
dev
);
vdev
.
push_back
(
dev
);
}
std
::
vector
<
device_cfg_t
*>::
size_type
num_devices
=
vdev
.
size
();
std
::
vector
<
device_cfg_t
*>::
size_type
num_devices
=
vdev
.
size
();
if
(
num_devices
==
0
)
{
if
(
num_devices
==
0
)
{
fprintf
(
stderr
,
"no devices in the config file
\n
"
);
return
1
;
}
zmq
::
context_t
ctx
(
num_devices
,
1
);
zmq
::
context_t
ctx
(
num_devices
,
1
);
for
(
unsigned
int
i
=
0
;
i
<
num_devices
;
++
i
)
{
vdev
[
i
]
->
set_context
(
&
ctx
);
vdev
[
i
]
->
set_context
(
&
ctx
);
if
(
i
)
{
pthread_t
worker
;
int
rc
=
pthread_create
(
&
worker
,
NULL
,
&
worker_function
,
(
void
*
)
vdev
[
i
]);
(
void
*
)
vdev
[
i
]);
assert
(
rc
==
0
);
}
}
worker_function
((
void
*
)
vdev
[
0
]);
worker_function
((
void
*
)
vdev
[
0
]);
return
0
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment