By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,665 Members | 1,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,665 IT Pros & Developers. It's quick & easy.

c++ event sink

P: n/a
I have a function that will download XML from internet and load XML
data into database.

The function will take 5 - 20 minutes to finish.

I heard I should use event sink (event listener) when function is
finished the task, then it will notify the caller.

So I am planning to create a seperate thread to do the long XML
loading function by using - _beginthreadex()

But how to create a notification / event sink / event listener in C++?

any library can easily just a library function call?

or any sample source code on the internet?

Thanks
Jun 27 '08 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Sam
Eric Kaplan writes:
I heard I should use event sink (event listener) when function is
finished the task, then it will notify the caller.

So I am planning to create a seperate thread to do the long XML
loading function by using - _beginthreadex()

But how to create a notification / event sink / event listener in C++?
There's no such thing as a "notification", an "event sink", or an "event
listener", in the C++ programming language.

You must be referring to objects, or APIs, that are particular to whatever
operating system you are using.

You have a better chance of finding a helpful answer to your question if you
ask, instead, on a different newsgroup that's specific to whatever operating
system or library that you are using.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBIATtex9p3GYHlUOIRAjhcAJ94mbaefTJI9hrDvjxnDf DcWxizYgCfYAfy
tb/KKifAaN9arrDj/hA0FHo=
=kw0k
-----END PGP SIGNATURE-----

Jun 27 '08 #2

P: n/a
* Eric Kaplan:
I have a function that will download XML from internet and load XML
data into database.

The function will take 5 - 20 minutes to finish.

I heard I should use event sink (event listener) when function is
finished the task, then it will notify the caller.

So I am planning to create a seperate thread to do the long XML
loading function by using - _beginthreadex()
Why not a separate process?

Perhaps the user wants to terminate the UI part, but wants the download to complete.

But how to create a notification / event sink / event listener in C++?
If you have a GUI then you (probably) already have such functionality.

But anyway take a look at e.g. Boost slots.

any library can easily just a library function call?
Huh.

or any sample source code on the internet?
Extremely much. Go look. :-)
Cheers, & hth.,

- Alf
Jun 27 '08 #3

P: n/a

that's a very good point, how to start a seperate process from the
code?

and how can I notify the caller when the process is finished?
>
Why not a separate process?
Jun 27 '08 #4

P: n/a
* Eric Kaplan:
that's a very good point, how to start a seperate process from the
code?
In standard C++ and C all you have is the 'system' function, which is not
adequate for your purposes.

Essentially the question is therefore environment-specific, with best answers in
an environment-specific group.

The FAQ lists a few such groups.

and how can I notify the caller when the process is finished?
Again, system-specific. E.g., in Windows, which is what I know best, you can
use mailslots (which are essentially datagrams camouflaged via file
abstraction), pipes, any waitable global object, socket programming, real files,
higher level COM object, message queues, window messages, and more, it's like
they say just your fantasy that sets the limits, but it's all off-topic here in
clc++, sorry!
Cheers, & hth.,

- Alf
Jun 27 '08 #5

P: n/a

"Eric Kaplan" <to*********@yahoo.comwrote in message
>I have a function that will download XML from internet and load XML
data into database.

The function will take 5 - 20 minutes to finish.

I heard I should use event sink (event listener) when function is
finished the task, then it will notify the caller.

So I am planning to create a seperate thread to do the long XML
loading function by using - _beginthreadex()
There is no concept of thread or process as far as the C++ language is
concerned. People would scream your question as OT here :-). You should try
your platform specific newsgroup.
But how to create a notification / event sink / event listener in C++?

any library can easily just a library function call?

or any sample source code on the internet?
Search engines are your friend.
--
http://techytalk.googlepages.com
Jun 27 '08 #6

P: n/a

"Stefan Ram" <ra*@zedat.fu-berlin.dewrote in message
"sk_usenet" <sometechyguy at gmail dot comwrites:
>>There is no concept of thread or process as far as the C++
language is concerned.

»When an exception is thrown, control is transferred to
the nearest handler with a matching type (15.3); "nearest"
means the handler for which the compound-statement,
ctor-initializer, or function-body following the try
keyword was most recently entered by the thread of control
and not yet exited.« ¯¯¯¯¯¯

ISO/IEC 14882:2003(E), 15.1p2

»If a function is registered with atexit (see <cstdlib>,
18.3) then following the call to exit, any objects with
static storage duration initialized prior to the
registration of that function shall not be destroyed until
the registered function is called from the termination
process and has completed.«
¯¯¯¯¯¯¯
ISO/IEC 14882:2003(E), 3.6.3p3
Ok, pedantically speaking Standard does recognize something of a thread, and
something of a process. But the bottom line is that OP's question was
off-topic.
Jun 27 '08 #7

P: n/a

P: n/a
Thanks your hint!

but i think it may not be a good idea to use such big library for a
small task.

Does using call back function a good idea in here? (loading XML to
DB, after finish, notify the main / primary thread)


>Read http://libsigc.sourceforge.net/
Jun 27 '08 #9

P: n/a
On Apr 13, 4:39 am, Eric Kaplan <tobycraf...@yahoo.comwrote:
Thanks your hint!

but i think it may not be a good idea to use such big library for a
small task.

Does using call back function a good idea in here? (loading XML to
DB, after finish, notify the main / primary thread)
Readhttp://libsigc.sourceforge.net/
I believe you can also use the boost::bind library (http://
http://www.boost.org/doc/libs/1_35_0...bind/bind.html) to create the sort
of callbacks you would be interested in.

You might also want to take a look at the
dlib::member_function_pointer object which is similar but may be
easier to use depending on what you are trying to accomplish. See,
http://dclib.sourceforge.net/other.h...nction_pointer and
http://dclib.sourceforge.net/member_...er_ex.cpp.html

-Davis
Jun 27 '08 #10

This discussion thread is closed

Replies have been disabled for this discussion.