Aynchronous class design question

A

Angus Comber

Hello

This question is relevant to any asynchronous environment whereby a process
may take any length of time to complete.

Anyway, I am developing a C++ wave (in and out) wrapper class. I have for
example a function to play a file. But problem for user of this class is
that if for example, they wanted to play wavfile1 followed by wavfile2 how
do they do it.

When the user calls playfile function it returns immediately. So how do
they know when to call the next function - or to call play file again.

Do I have a notification callback or event which calls their app to tell
them the file has finished?

Do I make the function synchronous, ie only return from the function when
the file has finished playing?

Or some other option?

Your thoughts will be much appreciated.

Angus Comber
(e-mail address removed)
 
K

Kanenas

Hello

This question is relevant to any asynchronous environment whereby a process
may take any length of time to complete.

Anyway, I am developing a C++ wave (in and out) wrapper class. I have for
example a function to play a file. But problem for user of this class is
that if for example, they wanted to play wavfile1 followed by wavfile2 how
do they do it.

When the user calls playfile function it returns immediately. So how do
they know when to call the next function - or to call play file again.

Do I have a notification callback or event which calls their app to tell
them the file has finished?

Do I make the function synchronous, ie only return from the function when
the file has finished playing?

Or some other option?
I do have some suggestions, but your issue is off topic. Try
comp.programming.threads to find the concurrency experts.

Any of the above will work. The 'playfile' method could also return
the thread or process ID, and the client can then join/wait on it.
You could also create an audio queue class (called e.g. AudioQueue)
which hides the details of how it's done. The audio queue can itself
work concurrently and support all manner of actions (pause, stop,
forward, rewind, insert & remove files, &c.). Making 'playfile'
synchronous or use of a join/wait call will reduce the power of
concurrency, so the best option is probably to have 'playfile' send a
notification upon finish and wrap the details in the audio queue.

Kanenas
 
A

Angus Comber

Thanks for your help. But not quite sure why it is off-topic.

Note my top posting!!! Yes some people like it!

Angus
 
R

Risto Lankinen

Hi!

Agreed! I really wish top posting was a more common habit.

I often read the news using a mobile phone. The operator
charges per byte which means that top-posted messages are
much cheaper to read than messages where an entire quoted
original has to be fetched before the new content is in view.

But yeah, I guess that it will never be the norm, since the 'net
etiquette is [and, I guess, should be!] designed for the lowest
common denominator of all readers. Concluding from how
much there is complaining against top posting, there must be
a large number of people lacking the mental capacity needed
to reverse the order of two serially communicated ideas.

I don't have this incapacity so I really can't say how difficult it
is to live with it, but what I can say is that every little thing probably
counts, and so, to reach as much as possible of any given audience
it might be better to stick with bottom posting.

- Risto -
 
L

Lionel B

[...]

Concluding from how
much there is complaining against top posting, there must be
a large number of people lacking the mental capacity needed
to reverse the order of two serially communicated ideas.

And if there're more than two ideas (like, y'know, in normal human conversation...)? How then do I know at a glance
which of your top-posted responses refers to which segment of a (possibly lengthy, multi-person) post?
I don't have this incapacity so I really can't say how difficult it
is to live with it,

I find top-posting difficult to live with, as it destroys the interleaved, sequential nature of natural conversation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top