home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
pwr16.zip
/
POWER.DOC
< prev
next >
Wrap
Text File
|
1994-11-07
|
11KB
|
277 lines
PowerThreads V1.00
Copyright 1994, Greg Ratajik.
CompuServe : 74555,542
Internet : 74555.542@compuserve.com
Voice : (305)/340-7985
OS/2 ShareWare BBS : (703)/385-4325
(CompuServe is where I provide
primary support)
You may use this code in your programs under the
following conditions:
o That you keep the information banners/copyright notices intact
in the source code.
o If you sell a product that uses this, I ask that
you put my name and contact info in it, and what
you got out of it. (This doesn't need to be in a
about box, but it would be nice at the end of the
credits of the .INF file, or DOC's.) If that's not
possible, oh well, it can't hurt to ask!
You may distribute it freely, as long as this documention is included
with it.
Beyond that, go for it! You're free to hack this up
in any way that you need. I'm not asking for any return
on this code, except (maybe?) to provide a quick and
easy way for fellow OS/2 developers to thread their
programs. If you make improvements, please get post it
to either CompuServe or the OS2 Shareware BBS.
---------------------------------------------------
| Special Thanks to Ron Finlayson, for part of the |
| initial concept work on this. It really helps to |
| have someone to brain storm with! :) |
---------------------------------------------------
*****************************************************************
*DISCLAIMER OF WARRANTIES. The following code is *
*sample code created by Greg Ratajik. The code is provided *
*"AS IS", without warranty of any kind. Greg Ratatjik shall not*
*be liable for any damages arising out of your use of the sample*
*code. *
*****************************************************************
I've heavily documented the code, so that's the best place to go
for information, BUT, if you don't want to do that, I've included
this little write up for basic information.
---------------------------------------------------------------------------
I. Description
This module has two main functions in it, PowerCall and
PowerHABCall. Both of them let an application call a
function, while processing a PM message, without locking
up PM. The function calls can be treated like a normal
function that runs consecutively to other function calls
(instead of posting messages back to the parent, or
having a worker thread processing requests)
The basic flow of this program is:
PowerHABCall():
Get PM Message
|
\|/
Start Thread --------------
| |
| |
\|/ \|/
Process Queue Call Function
| |
| |
\|/ \|/
Return <---------- Notify Function Done
|
|
\|/
Continue Processing
Message
=======================================================
PowerCall():
Get PM Message
|
\|/
Start Thread --------------
| |
| |
\|/ \|/
Start DLG Call Function
(Will process messages) |
| |
| |
\|/ \|/
Return <---------- Post Message To DLG
|
|
\|/
Continue Processing
Message
PowerHABCall is the most straight forward way, but you
have to pass the HAB. PowerCall is a little more
complex, but if you want to display something to the user
while the thread is running (i.e. do a timer, and animate
the pointer while the thread is running...) or if you
don't want to worry about getting the HAB, use
it.
II. Limitations
While this works very well, it should be noted that
starting and stopping a thread has a fair amount of
overhead. If you are going to be making many of these
calls, I suggest starting a worker thread, as your
program will perform much better.
III. Uses
This threading technique has two primary uses:
o An easy way to thread an existing program, without
changing the architecture of that program.
o A quick and easy way to add threads in new PM programs,
for "one-time" function calls (very much like the example.)
IV. To add to your program...
1. Choose which function to use. If you've got a lot of functions
to convert, or you want to do some special displays to the user,
you might want to use PowerCall. Otherwise, use PowerHABCall, as
there is less overhead.
2. The example only uses one parm to the function that gets called.
(ProcessTest) If you want to use more, you need to add a parm
to PowerCall and PowerHABCall, add the code to copy that parm
to the correct field in the structure THREAD_CALL_INFO, and
modify the functions CallFunction and CallHABFunction to use the
parms. While this a little bit of work, I've documented the code
heavily, so it shouldn't be to bad. If you have trouble doing this,
feel free to get in touch with me. I'll help as much as I can
(time allowing) See Section IV "Enhancements" for thoughts on how
to get rid of this type of modification all together.
NOTE: If you don't want to modify the structures/code, you CAN
just use globals for everything.
3. Change the code to call your function to PowerCall/PowerHABCall.
For example, if you had:
GetDate(&pdaInfo, &key1, "Test");
You would now have:
PowerCall(GetDate, &pdaInfo, &key1, "Test");
IV. Enhancements.
I originally was going to make a DLL out of these two calls, and
sell the library. The main reason that I didn't was the amount
of code it would take to make this thing 100% generic. While
I've got some ideas of how to do this, I just don't have the time
right now to implement them. The best way (from what I can see)
to make this generic would be to use varargs, and somehow
generically copy the args off of the stack in PowerCall (without
knowing sizes), moving them to the comm structure, and then
copying back onto the stack in CallFunction().
If you want to try and do this, go for it. BUT, if you do,
PLEASE send me a copy! I would love to get away from modifying
this code for each Function I want to call. (It's not tooooo bad...
but it's still to much more, and it adds a fair amount of code if
you've got more than one function to call.)
V. Return Values.
So far, I've used globals to handle return values (Yeah, it's lame,
but it works.) If you want to pass return values, you can use
the comm structure to communicate the information around. If you
have trouble doing it, let me know, and I (for a price! :) might
be able to give you an example.
IV. Other shareware/PD programs to look for:
(OS/2 Programs I've written over the years)
o EasyPlay - MM/PM program to play AVI, WAV, VOC, FLI, and
any other file types MM/PM uses. Features
the ability to scan an entire drive for
files, and play all lists files. Makes use of
threads for ALL file searching/playing (including
PowerThreads!)
o NetChat - This program allows many users to have Chat
sessions over the LAN. It allows each user to set
up Conference groups and security levels. Each
Conference can have as many users as you want
Chatting. This is similar to CompuServer's CB, or
a BBS's multi-node chat area. (This program is free
when you use QuikWare to register EasyPlay
o NetMail - Improved net massaging (i.e. "Blue Boxes")
This program gives you better control of
system level LAN messages. You can enter message
subjects, set priority levels, and type in longer
messages.
NetMail allows each user to set up their own
message groups, along with global message groups.
Each user can choose which groups to receive
messages from, and what groups to send messages to.
NetMail also let's you choose whether to get
the message in the traditional VIO BlueBox (but
better looking!), a PM Message Box, or to display
no message but to retrieve it at a latter time.
This program makes Net Massaging easier to
use, and less annoying to the recipients.
o DeleteDir - A simple full-screen program to delete a
directory and all files/directories that are children to
it.
o ChkPath - Will check the path's you set in your
config.sys, and let you know if you've got problems.
o Pwh - Path'ed Where. Will search a path for a file. PWH
will tell you every place it hit's the file. Very useful
for checking what version of a program you using.
o MDD - Multiple make directory. MDD will create a
multiple directories (i.e. if you wanted to make
C:\GREG\PROGRAM\SOURCE20\MDD\RELEASE, MDD could do it in
one shot.)
o WHO - Will display information about all users of a
LAN/Domain.
o QWHO - Displays all user ID's currently on a LAN/Domain.
o Vtree - Visual directory tree.
o EDCNFG - PM based program that will verify everything's
okay in your config.sys, keep track/retro changes into
multiple config's, and edit/setup a config.sys
o HPMLib - Library tracking system
o HPMCook - Cooking software
o HPMDiet - Dieting software
o JOGGER - OS/2 Program for runners.
o DosText - Change the message a OS/2 program gives when
running it from DOS.
Program Utilities/Toolkits:
o AniButtn - Two-state animated pushbuttons that you can
easily replace any pushbutton with.
o VidButtn - Just like AniButtn, but will full-frame
animation. (The ones in EasyPlay works exactly like a
pushbutton, but have up to 17 frames of animation!)
o DynoHelp - Dynamic Help toolkit (late '94, '95)
o Pops - Dynamic Pop-up menu toolkit (late '94, '95)