Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
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-2-2
Commits
d14f8d43
Commit
d14f8d43
authored
Feb 23, 2009
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simpler and safer event callbacks handling
parent
c68490b3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
36 deletions
+14
-36
bindings/cil/src/marshal.cs
bindings/cil/src/marshal.cs
+14
-36
No files found.
bindings/cil/src/marshal.cs
View file @
d14f8d43
...
...
@@ -139,30 +139,12 @@ namespace VideoLAN.LibVLC
*/
public
abstract
class
EventingObject
:
BaseObject
{
/**
* @brief Managed to unmanaged event handler mapping
* @ingroup Internals
*
* The CLR cannot do reference counting for unmanaged callbacks.
* We keep track of handled events here instead.
*/
private
class
Event
{
public
EventCallback
managed
;
public
IntPtr
unmanaged
;
public
Event
(
EventCallback
managed
,
IntPtr
unmanaged
)
{
this
.
managed
=
managed
;
this
.
unmanaged
=
unmanaged
;
}
};
private
Dictionary
<
EventType
,
Event
>
events
;
private
Dictionary
<
Delegate
,
IntPtr
>
events
;
/**< references to our unmanaged function pointers */
internal
EventingObject
()
:
base
()
{
events
=
new
Dictionary
<
EventType
,
Event
>
();
events
=
new
Dictionary
<
Delegate
,
IntPtr
>
();
}
/**
...
...
@@ -187,19 +169,20 @@ namespace VideoLAN.LibVLC
* @param callback callback to invoke when the event occurs
*
* @note
* For simplicity, we
only allow one handler per
type.
*
Multicasting can be implemented higher up with managed code
.
* For simplicity, we
require distinct callbacks for each event
type.
*
This is hardly an issue since most events have different formats
.
*/
internal
void
Attach
(
EventType
type
,
EventCallback
callback
)
internal
void
Attach
(
EventType
type
,
Delegate
callback
)
{
EventManagerHandle
manager
;
IntPtr
cb
=
Marshal
.
GetFunctionPointerForDelegate
(
callback
);
Event
ev
=
new
Event
(
callback
,
cb
);
bool
unref
=
false
;
if
(
events
.
ContainsKey
(
type
))
throw
new
ArgumentException
(
"Duplicate event"
);
/* If things go wrong, we will leak the callback thunk... until
* this object is destroyed anyway. If we added the thunk _after_
* the critical section, the native code could try to jump to a
* non-existent address, which is much worse. */
events
.
Add
(
callback
,
cb
);
try
{
handle
.
DangerousAddRef
(
ref
unref
);
...
...
@@ -212,19 +195,19 @@ namespace VideoLAN.LibVLC
handle
.
DangerousRelease
();
}
Raise
();
events
.
Add
(
type
,
ev
);
}
private
void
Detach
(
EventType
type
,
IntPtr
callback
)
internal
void
Detach
(
EventType
type
,
Delegate
callback
)
{
EventManagerHandle
manager
;
IntPtr
cb
=
events
[
callback
];
bool
unref
=
false
;
try
{
handle
.
DangerousAddRef
(
ref
unref
);
manager
=
GetManager
();
LibVLC
.
EventDetach
(
manager
,
type
,
c
allback
,
IntPtr
.
Zero
,
ex
);
LibVLC
.
EventDetach
(
manager
,
type
,
c
b
,
IntPtr
.
Zero
,
ex
);
}
finally
{
...
...
@@ -232,12 +215,7 @@ namespace VideoLAN.LibVLC
handle
.
DangerousRelease
();
}
Raise
();
events
.
Remove
(
type
);
}
internal
void
Detach
(
EventType
type
)
{
Detach
(
type
,
events
[
type
].
unmanaged
);
events
.
Remove
(
callback
);
}
};
};
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