Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
b0342586
Commit
b0342586
authored
Feb 08, 2011
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
D-Bus inhibit: fix leaks and simplify
parent
7ff88a0c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
78 deletions
+44
-78
modules/misc/inhibit.c
modules/misc/inhibit.c
+44
-78
No files found.
modules/misc/inhibit.c
View file @
b0342586
...
...
@@ -52,8 +52,7 @@
static
int
Activate
(
vlc_object_t
*
);
static
void
Deactivate
(
vlc_object_t
*
);
static
int
Inhibit
(
intf_thread_t
*
p_intf
);
static
int
UnInhibit
(
intf_thread_t
*
p_intf
);
static
void
UnInhibit
(
intf_thread_t
*
p_intf
);
static
int
InputChange
(
vlc_object_t
*
,
const
char
*
,
vlc_value_t
,
vlc_value_t
,
void
*
);
...
...
@@ -138,67 +137,47 @@ static void Deactivate( vlc_object_t *p_this )
*
* returns false if Out of memory, else true
*****************************************************************************/
static
int
Inhibit
(
intf_thread_t
*
p_intf
)
static
void
Inhibit
(
intf_thread_t
*
p_intf
)
{
DBusConnection
*
p_conn
;
DBusMessage
*
p_msg
;
DBusMessageIter
args
;
DBusMessage
*
p_reply
;
dbus_uint32_t
i_cookie
;
intf_sys_t
*
p_sys
=
p_intf
->
p_sys
;
p_conn
=
p_intf
->
p_sys
->
p_conn
;
DBusMessage
*
msg
=
dbus_message_new_method_call
(
PM_SERVICE
,
PM_PATH
,
PM_INTERFACE
,
"Inhibit"
);
if
(
unlikely
(
msg
==
NULL
)
)
return
;
p_msg
=
dbus_message_new_method_call
(
PM_SERVICE
,
PM_PATH
,
PM_INTERFACE
,
"Inhibit"
);
if
(
!
p_msg
)
return
false
;
const
char
*
app
=
PACKAGE
;
const
char
*
reason
=
_
(
"Playing some media."
);
dbus_message_iter_init_append
(
p_msg
,
&
args
)
;
p_sys
->
i_cookie
=
0
;
char
*
psz_app
=
strdup
(
PACKAGE
);
if
(
!
psz_app
||
!
dbus_message_iter_append_basic
(
&
args
,
DBUS_TYPE_STRING
,
&
psz_app
)
)
if
(
!
dbus_message_append_args
(
msg
,
DBUS_TYPE_STRING
,
&
app
,
DBUS_TYPE_STRING
,
&
reason
,
DBUS_TYPE_INVALID
)
)
{
free
(
psz_app
);
dbus_message_unref
(
p_msg
);
return
false
;
dbus_message_unref
(
msg
);
return
;
}
free
(
psz_app
);
char
*
psz_inhibit_reason
=
strdup
(
_
(
"Playing some media."
)
);
if
(
!
psz_inhibit_reason
)
{
dbus_message_unref
(
p_msg
);
return
false
;
}
if
(
!
dbus_message_iter_append_basic
(
&
args
,
DBUS_TYPE_STRING
,
&
psz_inhibit_reason
)
)
{
free
(
psz_inhibit_reason
);
dbus_message_unref
(
p_msg
);
return
false
;
}
free
(
psz_inhibit_reason
);
p_reply
=
dbus_connection_send_with_reply_and_block
(
p_conn
,
p_msg
,
50
,
NULL
);
/* blocks 50ms maximum */
dbus_message_unref
(
p_msg
);
if
(
p_reply
==
NULL
)
{
/* g-p-m is not active, or too slow. Better luck next time? */
return
true
;
}
/* blocks 50ms maximum */
DBusMessage
*
reply
;
reply
=
dbus_connection_send_with_reply_and_block
(
p_sys
->
p_conn
,
msg
,
50
,
NULL
);
dbus_message_unref
(
msg
);
if
(
reply
==
NULL
)
/* g-p-m is not active, or too slow. Better luck next time? */
return
;
/* extract the cookie from the reply */
if
(
dbus_message_get_args
(
p_reply
,
NULL
,
DBUS_TYPE_UINT32
,
&
i_cookie
,
DBUS_TYPE_INVALID
)
==
FALSE
)
{
return
false
;
}
dbus_uint32_t
i_cookie
;
if
(
dbus_message_get_args
(
reply
,
NULL
,
DBUS_TYPE_UINT32
,
&
i_cookie
,
DBUS_TYPE_INVALID
)
)
p_sys
->
i_cookie
=
i_cookie
;
/* Save the cookie */
p_intf
->
p_sys
->
i_cookie
=
i_cookie
;
return
true
;
dbus_message_unref
(
reply
);
}
/*****************************************************************************
...
...
@@ -206,37 +185,24 @@ static int Inhibit( intf_thread_t *p_intf )
*
* returns false if Out of memory, else true
*****************************************************************************/
static
int
UnInhibit
(
intf_thread_t
*
p_intf
)
static
void
UnInhibit
(
intf_thread_t
*
p_intf
)
{
DBusConnection
*
p_conn
;
DBusMessage
*
p_msg
;
DBusMessageIter
args
;
dbus_uint32_t
i_cookie
;
p_conn
=
p_intf
->
p_sys
->
p_conn
;
p_msg
=
dbus_message_new_method_call
(
PM_SERVICE
,
PM_PATH
,
PM_INTERFACE
,
"UnInhibit"
);
if
(
!
p_msg
)
return
false
;
intf_sys_t
*
p_sys
=
p_intf
->
p_sys
;
dbus_message_iter_init_append
(
p_msg
,
&
args
);
DBusMessage
*
msg
=
dbus_message_new_method_call
(
PM_SERVICE
,
PM_PATH
,
PM_INTERFACE
,
"UnInhibit"
);
if
(
unlikely
(
msg
==
NULL
)
)
return
;
i_cookie
=
p_intf
->
p_sys
->
i_cookie
;
if
(
!
dbus_message_iter_append_basic
(
&
args
,
DBUS_TYPE_UINT32
,
&
i_cookie
)
)
dbus_uint32_t
i_cookie
=
p_sys
->
i_cookie
;
if
(
dbus_message_append_args
(
msg
,
DBUS_TYPE_UINT32
,
&
i_cookie
,
DBUS_TYPE_INVALID
)
&&
dbus_connection_send
(
p_sys
->
p_conn
,
msg
,
NULL
)
)
{
dbus_
message_unref
(
p_msg
);
return
false
;
dbus_
connection_flush
(
p_sys
->
p_conn
);
p_sys
->
i_cookie
=
0
;
}
if
(
!
dbus_connection_send
(
p_conn
,
p_msg
,
NULL
)
)
return
false
;
dbus_connection_flush
(
p_conn
);
dbus_message_unref
(
p_msg
);
p_intf
->
p_sys
->
i_cookie
=
0
;
return
true
;
dbus_message_unref
(
msg
);
}
...
...
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