Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
b111aa01
Commit
b111aa01
authored
Aug 26, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ZeroconfAvahi: fix coding style
parent
773d24eb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
74 deletions
+87
-74
ZeroconfAvahi.cxx
src/zeroconf/ZeroconfAvahi.cxx
+87
-74
No files found.
src/zeroconf/ZeroconfAvahi.cxx
View file @
b111aa01
...
@@ -38,20 +38,23 @@
...
@@ -38,20 +38,23 @@
static
constexpr
Domain
avahi_domain
(
"avahi"
);
static
constexpr
Domain
avahi_domain
(
"avahi"
);
static
char
*
avahi
N
ame
;
static
char
*
avahi
_n
ame
;
static
MyAvahiPoll
*
avahi_poll
;
static
MyAvahiPoll
*
avahi_poll
;
static
AvahiClient
*
avahi
C
lient
;
static
AvahiClient
*
avahi
_c
lient
;
static
AvahiEntryGroup
*
avahi
G
roup
;
static
AvahiEntryGroup
*
avahi
_g
roup
;
static
void
avahiRegisterService
(
AvahiClient
*
c
);
static
void
AvahiRegisterService
(
AvahiClient
*
c
);
/* Callback when the EntryGroup changes state */
/**
static
void
avahiGroupCallback
(
AvahiEntryGroup
*
g
,
* Callback when the EntryGroup changes state.
AvahiEntryGroupState
state
,
*/
gcc_unused
void
*
userdata
)
static
void
AvahiGroupCallback
(
AvahiEntryGroup
*
g
,
AvahiEntryGroupState
state
,
gcc_unused
void
*
userdata
)
{
{
char
*
n
;
assert
(
g
!=
nullptr
);
assert
(
g
);
FormatDebug
(
avahi_domain
,
FormatDebug
(
avahi_domain
,
"Service group changed to state %d"
,
state
);
"Service group changed to state %d"
,
state
);
...
@@ -61,53 +64,58 @@ static void avahiGroupCallback(AvahiEntryGroup * g,
...
@@ -61,53 +64,58 @@ static void avahiGroupCallback(AvahiEntryGroup * g,
/* The entry group has been established successfully */
/* The entry group has been established successfully */
FormatDefault
(
avahi_domain
,
FormatDefault
(
avahi_domain
,
"Service '%s' successfully established."
,
"Service '%s' successfully established."
,
avahi
N
ame
);
avahi
_n
ame
);
break
;
break
;
case
AVAHI_ENTRY_GROUP_COLLISION
:
case
AVAHI_ENTRY_GROUP_COLLISION
:
/* A service name collision happened. Let's pick a new name */
/* A service name collision happened. Let's pick a new name */
n
=
avahi_alternative_service_name
(
avahiName
);
{
avahi_free
(
avahiName
);
char
*
n
=
avahi_alternative_service_name
(
avahi_name
);
avahiName
=
n
;
avahi_free
(
avahi_name
);
avahi_name
=
n
;
}
FormatDefault
(
avahi_domain
,
FormatDefault
(
avahi_domain
,
"Service name collision, renaming service to '%s'"
,
"Service name collision, renaming service to '%s'"
,
avahi
N
ame
);
avahi
_n
ame
);
/* And recreate the services */
/* And recreate the services */
a
vahiRegisterService
(
avahi_entry_group_get_client
(
g
));
A
vahiRegisterService
(
avahi_entry_group_get_client
(
g
));
break
;
break
;
case
AVAHI_ENTRY_GROUP_FAILURE
:
case
AVAHI_ENTRY_GROUP_FAILURE
:
FormatError
(
avahi_domain
,
FormatError
(
avahi_domain
,
"Entry group failure: %s"
,
"Entry group failure: %s"
,
avahi_strerror
(
avahi_client_errno
avahi_strerror
(
avahi_client_errno
(
avahi_entry_group_get_client
(
g
))));
(
avahi_entry_group_get_client
(
g
))));
/* Some kind of failure happened while we were
/* Some kind of failure happened while we were
registering our services */
registering our services */
break
;
break
;
case
AVAHI_ENTRY_GROUP_UNCOMMITED
:
case
AVAHI_ENTRY_GROUP_UNCOMMITED
:
LogDebug
(
avahi_domain
,
"Service group is UNCOMMITED"
);
LogDebug
(
avahi_domain
,
"Service group is UNCOMMITED"
);
break
;
break
;
case
AVAHI_ENTRY_GROUP_REGISTERING
:
case
AVAHI_ENTRY_GROUP_REGISTERING
:
LogDebug
(
avahi_domain
,
"Service group is REGISTERING"
);
LogDebug
(
avahi_domain
,
"Service group is REGISTERING"
);
}
}
}
}
/* Registers a new service with avahi */
/**
static
void
avahiRegisterService
(
AvahiClient
*
c
)
* Registers a new service with avahi.
*/
static
void
AvahiRegisterService
(
AvahiClient
*
c
)
{
{
FormatDebug
(
avahi_domain
,
"Registering service %s/%s"
,
assert
(
c
!=
nullptr
);
SERVICE_TYPE
,
avahiName
);
int
ret
;
FormatDebug
(
avahi_domain
,
"Registering service %s/%s"
,
assert
(
c
);
SERVICE_TYPE
,
avahi_name
);
/* If this is the first time we're called,
/* If this is the first time we're called,
* let's create a new entry group */
* let's create a new entry group */
if
(
!
avahi
G
roup
)
{
if
(
!
avahi
_g
roup
)
{
avahi
Group
=
avahi_entry_group_new
(
c
,
a
vahiGroupCallback
,
nullptr
);
avahi
_group
=
avahi_entry_group_new
(
c
,
A
vahiGroupCallback
,
nullptr
);
if
(
!
avahi
G
roup
)
{
if
(
!
avahi
_g
roup
)
{
FormatError
(
avahi_domain
,
FormatError
(
avahi_domain
,
"Failed to create avahi EntryGroup: %s"
,
"Failed to create avahi EntryGroup: %s"
,
avahi_strerror
(
avahi_client_errno
(
c
)));
avahi_strerror
(
avahi_client_errno
(
c
)));
...
@@ -119,44 +127,48 @@ static void avahiRegisterService(AvahiClient * c)
...
@@ -119,44 +127,48 @@ static void avahiRegisterService(AvahiClient * c)
/* TODO: This currently binds to ALL interfaces.
/* TODO: This currently binds to ALL interfaces.
* We could maybe add a service per actual bound interface,
* We could maybe add a service per actual bound interface,
* if that's better. */
* if that's better. */
ret
=
avahi_entry_group_add_service
(
avahiGroup
,
int
result
=
avahi_entry_group_add_service
(
avahi_group
,
AVAHI_IF_UNSPEC
,
AVAHI_PROTO_UNSPEC
,
AVAHI_IF_UNSPEC
,
AvahiPublishFlags
(
0
),
AVAHI_PROTO_UNSPEC
,
avahiName
,
SERVICE_TYPE
,
nullptr
,
AvahiPublishFlags
(
0
),
nullptr
,
listen_port
,
nullptr
);
avahi_name
,
SERVICE_TYPE
,
if
(
ret
<
0
)
{
nullptr
,
nullptr
,
listen_port
,
nullptr
);
if
(
result
<
0
)
{
FormatError
(
avahi_domain
,
"Failed to add service %s: %s"
,
FormatError
(
avahi_domain
,
"Failed to add service %s: %s"
,
SERVICE_TYPE
,
avahi_strerror
(
ret
));
SERVICE_TYPE
,
avahi_strerror
(
re
sul
t
));
return
;
return
;
}
}
/* Tell the server to register the service group */
/* Tell the server to register the service group */
re
t
=
avahi_entry_group_commit
(
avahiG
roup
);
re
sult
=
avahi_entry_group_commit
(
avahi_g
roup
);
if
(
ret
<
0
)
{
if
(
re
sul
t
<
0
)
{
FormatError
(
avahi_domain
,
"Failed to commit service group: %s"
,
FormatError
(
avahi_domain
,
"Failed to commit service group: %s"
,
avahi_strerror
(
ret
));
avahi_strerror
(
re
sul
t
));
return
;
return
;
}
}
}
}
/* Callback when avahi changes state */
/* Callback when avahi changes state */
static
void
avahiClientCallback
(
AvahiClient
*
c
,
AvahiClientState
state
,
static
void
gcc_unused
void
*
userdata
)
MyAvahiClientCallback
(
AvahiClient
*
c
,
AvahiClientState
state
,
gcc_unused
void
*
userdata
)
{
{
int
reason
;
assert
(
c
!=
nullptr
);
assert
(
c
);
/* Called whenever the client or server state changes */
/* Called whenever the client or server state changes */
FormatDebug
(
avahi_domain
,
"Client changed to state %d"
,
state
);
FormatDebug
(
avahi_domain
,
"Client changed to state %d"
,
state
);
switch
(
state
)
{
switch
(
state
)
{
int
reason
;
case
AVAHI_CLIENT_S_RUNNING
:
case
AVAHI_CLIENT_S_RUNNING
:
LogDebug
(
avahi_domain
,
"Client is RUNNING"
);
LogDebug
(
avahi_domain
,
"Client is RUNNING"
);
/* The server has startup successfully and registered its host
/* The server has startup successfully and registered its host
* name on the network, so it's time to create our services */
* name on the network, so it's time to create our services */
if
(
!
avahiGroup
)
if
(
avahi_group
==
nullptr
)
a
vahiRegisterService
(
c
);
A
vahiRegisterService
(
c
);
break
;
break
;
case
AVAHI_CLIENT_FAILURE
:
case
AVAHI_CLIENT_FAILURE
:
...
@@ -164,38 +176,39 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state,
...
@@ -164,38 +176,39 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state,
if
(
reason
==
AVAHI_ERR_DISCONNECTED
)
{
if
(
reason
==
AVAHI_ERR_DISCONNECTED
)
{
LogDefault
(
avahi_domain
,
LogDefault
(
avahi_domain
,
"Client Disconnected, will reconnect shortly"
);
"Client Disconnected, will reconnect shortly"
);
if
(
avahi
Group
)
{
if
(
avahi
_group
!=
nullptr
)
{
avahi_entry_group_free
(
avahi
G
roup
);
avahi_entry_group_free
(
avahi
_g
roup
);
avahi
G
roup
=
nullptr
;
avahi
_g
roup
=
nullptr
;
}
}
if
(
avahiClient
)
avahi_client_free
(
avahiClient
);
if
(
avahi_client
!=
nullptr
)
avahiClient
=
avahi_client_free
(
avahi_client
);
avahi_client
=
avahi_client_new
(
avahi_poll
,
avahi_client_new
(
avahi_poll
,
AVAHI_CLIENT_NO_FAIL
,
AVAHI_CLIENT_NO_FAIL
,
a
vahiClientCallback
,
nullptr
,
MyA
vahiClientCallback
,
nullptr
,
&
reason
);
&
reason
);
if
(
!
avahiClient
)
{
if
(
avahi_client
==
nullptr
)
FormatWarning
(
avahi_domain
,
FormatWarning
(
avahi_domain
,
"Could not reconnect: %s"
,
"Could not reconnect: %s"
,
avahi_strerror
(
reason
));
avahi_strerror
(
reason
));
}
}
else
{
}
else
{
FormatWarning
(
avahi_domain
,
FormatWarning
(
avahi_domain
,
"Client failure: %s (terminal)"
,
"Client failure: %s (terminal)"
,
avahi_strerror
(
reason
));
avahi_strerror
(
reason
));
}
}
break
;
break
;
case
AVAHI_CLIENT_S_COLLISION
:
case
AVAHI_CLIENT_S_COLLISION
:
LogDebug
(
avahi_domain
,
"Client is COLLISION"
);
LogDebug
(
avahi_domain
,
"Client is COLLISION"
);
/* Let's drop our registered services. When the server
is back
/* Let's drop our registered services. When the server
* in AVAHI_SERVER_RUNNING state we will register them
is back in AVAHI_SERVER_RUNNING state we will
*
again with the new host name. */
register them
again with the new host name. */
if
(
avahi
Group
)
{
if
(
avahi
_group
!=
nullptr
)
{
LogDebug
(
avahi_domain
,
"Resetting group"
);
LogDebug
(
avahi_domain
,
"Resetting group"
);
avahi_entry_group_reset
(
avahi
G
roup
);
avahi_entry_group_reset
(
avahi
_g
roup
);
}
}
break
;
break
;
...
@@ -208,9 +221,9 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state,
...
@@ -208,9 +221,9 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state,
* for our own records to register until the host name is
* for our own records to register until the host name is
* properly esatblished. */
* properly esatblished. */
if
(
avahi
Group
)
{
if
(
avahi
_group
!=
nullptr
)
{
LogDebug
(
avahi_domain
,
"Resetting group"
);
LogDebug
(
avahi_domain
,
"Resetting group"
);
avahi_entry_group_reset
(
avahi
G
roup
);
avahi_entry_group_reset
(
avahi
_g
roup
);
}
}
break
;
break
;
...
@@ -229,15 +242,15 @@ AvahiInit(EventLoop &loop, const char *serviceName)
...
@@ -229,15 +242,15 @@ AvahiInit(EventLoop &loop, const char *serviceName)
if
(
!
avahi_is_valid_service_name
(
serviceName
))
if
(
!
avahi_is_valid_service_name
(
serviceName
))
FormatFatalError
(
"Invalid zeroconf_name
\"
%s
\"
"
,
serviceName
);
FormatFatalError
(
"Invalid zeroconf_name
\"
%s
\"
"
,
serviceName
);
avahi
N
ame
=
avahi_strdup
(
serviceName
);
avahi
_n
ame
=
avahi_strdup
(
serviceName
);
avahi_poll
=
new
MyAvahiPoll
(
loop
);
avahi_poll
=
new
MyAvahiPoll
(
loop
);
int
error
;
int
error
;
avahi
C
lient
=
avahi_client_new
(
avahi_poll
,
AVAHI_CLIENT_NO_FAIL
,
avahi
_c
lient
=
avahi_client_new
(
avahi_poll
,
AVAHI_CLIENT_NO_FAIL
,
avahiClientCallback
,
nullptr
,
&
error
);
MyAvahiClientCallback
,
nullptr
,
&
error
);
if
(
!
avahiClient
)
{
if
(
avahi_client
==
nullptr
)
{
FormatError
(
avahi_domain
,
"Failed to create client: %s"
,
FormatError
(
avahi_domain
,
"Failed to create client: %s"
,
avahi_strerror
(
error
));
avahi_strerror
(
error
));
AvahiDeinit
();
AvahiDeinit
();
...
@@ -245,25 +258,25 @@ AvahiInit(EventLoop &loop, const char *serviceName)
...
@@ -245,25 +258,25 @@ AvahiInit(EventLoop &loop, const char *serviceName)
}
}
void
void
AvahiDeinit
(
void
)
AvahiDeinit
()
{
{
LogDebug
(
avahi_domain
,
"Shutting down interface"
);
LogDebug
(
avahi_domain
,
"Shutting down interface"
);
if
(
avahi
Group
)
{
if
(
avahi
_group
!=
nullptr
)
{
avahi_entry_group_free
(
avahi
G
roup
);
avahi_entry_group_free
(
avahi
_g
roup
);
avahi
G
roup
=
nullptr
;
avahi
_g
roup
=
nullptr
;
}
}
if
(
avahi
Client
)
{
if
(
avahi
_client
!=
nullptr
)
{
avahi_client_free
(
avahi
C
lient
);
avahi_client_free
(
avahi
_c
lient
);
avahi
C
lient
=
nullptr
;
avahi
_c
lient
=
nullptr
;
}
}
delete
avahi_poll
;
delete
avahi_poll
;
avahi_poll
=
nullptr
;
avahi_poll
=
nullptr
;
avahi_free
(
avahi
N
ame
);
avahi_free
(
avahi
_n
ame
);
avahi
N
ame
=
nullptr
;
avahi
_n
ame
=
nullptr
;
dbus_shutdown
();
dbus_shutdown
();
}
}
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