473,765 Members | 1,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Queue of function calls

Hello,

I need implementation advice:
I am writing a program that should call some API functions in a
specific order. The APIs are for another application, not Windows
APIs. The order and type of the calls is determined at runtime. There
are a couple of hundred of those APIs that can be called, and they all
take different parameters. What I need is somehow queue the calls with
their parameters and then dequeue and execute them one by one... Now I
really have no idea on how to acomplish anything like this. Could
someone please advice me? I can provide more details if needed.

Please reply to the group.

Thank you!
Jul 22 '05 #1
6 6075
"Richard Berg" <bi***@mail.com > wrote...
I need implementation advice:
I am writing a program that should call some API functions in a
specific order. The APIs are for another application, not Windows
APIs. The order and type of the calls is determined at runtime. There
are a couple of hundred of those APIs that can be called, and they all
take different parameters. What I need is somehow queue the calls with
their parameters and then dequeue and execute them one by one... Now I
really have no idea on how to acomplish anything like this. Could
someone please advice me? I can provide more details if needed.


Wrap the queuing part and dequeuing into some kind of interpreter
of strings -- basically a mechanism that would read a given string
and extract the name of the function to call and values of the args
for that function. Then it would call it. If the function throws
or returns an error, you'll need some mechanism to account for that.

To create a queue, the user would call your "queue stuffer" with
a string, something like

Queue.add("myfu nction_1, 123, 3.14, 'a'");
Queue.add("myfu nction_2, \"string\", 42"); // need to use \"

then

Queue.execute() ;

which would go through the strings and execute them one by one.
You can add "syntax" checking to the 'add' method.

Honestly, I don't see any language issue here. Perhaps you should
try comp.programmin g for more advice on interpreters.

Victor
Jul 22 '05 #2

"Samuele Armondi" <sa************ ****@hotmail.co m> wrote in message
news:3f******** @mk-nntp-1.news.uk.world online.com...
"Richard Berg" <bi***@mail.com > wrote in message
news:ff******** *************** ***@posting.goo gle.com...
Hello,

I need implementation advice:
I am writing a program that should call some API functions in a
specific order. The APIs are for another application, not Windows
APIs. The order and type of the calls is determined at runtime. There
are a couple of hundred of those APIs that can be called, and they all
take different parameters. What I need is somehow queue the calls with
their parameters and then dequeue and execute them one by one... Now I
really have no idea on how to acomplish anything like this. Could
someone please advice me? I can provide more details if needed.

Please reply to the group.

Thank you!
I'm not sure if this is the best solution or indeed what you are asking

for, but here goes... create an Argument base class, and derive all your argument classes from it. using polymorphism, you will be able to treat all these
arguments the same, even thought they will be of different types (provided
of course you pass them around by pointer or reference).
Now create an class to hold the arguments (say, ArgumentContain er). This
class will hold the number of arguments and an array of _pointers_ to these arguments (otherwise polymorphism goes through the window). Then wrap your
api functions so that they take your ArgumentContain er as an argument, and
store them in a map, like this:
typedef bool (*ApiPointer)(A rgumentContaine r)
std::map <std::string, ApiPointer> FunctionMap;
where the string is the function name. now you can use a std::queue <string> or std::deque<stri ng> to queue these calls up and then look them up by name in the map.
I hope it makes sense!
HTH,
S. Armondi

BTW, I have got some code that does something like what I set out above if
you want to take a look
S
Jul 22 '05 #3
"Samuele Armondi" <sa************ ****@hotmail.co m> wrote in message news:<3f******* *@mk-nntp-1.news.uk.world online.com>...
"Samuele Armondi" <sa************ ****@hotmail.co m> wrote in message
news:3f******** @mk-nntp-1.news.uk.world online.com...
"Richard Berg" <bi***@mail.com > wrote in message
news:ff******** *************** ***@posting.goo gle.com...
Hello,

I need implementation advice:
I am writing a program that should call some API functions in a
specific order. The APIs are for another application, not Windows
APIs. The order and type of the calls is determined at runtime. There
are a couple of hundred of those APIs that can be called, and they all
take different parameters. What I need is somehow queue the calls with
their parameters and then dequeue and execute them one by one... Now I
really have no idea on how to acomplish anything like this. Could
someone please advice me? I can provide more details if needed.

Please reply to the group.

Thank you!


I'm not sure if this is the best solution or indeed what you are asking

for,
but here goes... create an Argument base class, and derive all your

argument
classes from it. using polymorphism, you will be able to treat all these
arguments the same, even thought they will be of different types (provided
of course you pass them around by pointer or reference).
Now create an class to hold the arguments (say, ArgumentContain er). This
class will hold the number of arguments and an array of _pointers_ to

these
arguments (otherwise polymorphism goes through the window). Then wrap your
api functions so that they take your ArgumentContain er as an argument, and
store them in a map, like this:
typedef bool (*ApiPointer)(A rgumentContaine r)
std::map <std::string, ApiPointer> FunctionMap;
where the string is the function name. now you can use a std::queue

<string>
or std::deque<stri ng> to queue these calls up and then look them up by

name
in the map.
I hope it makes sense!
HTH,
S. Armondi

BTW, I have got some code that does something like what I set out above if
you want to take a look
S


Thanks for your reply. I was thinking along the same lines... What I
don't really understand is how to call the API function once I have
its name (as string) and a list of arguments (wrapped in classes). Of
course I could make a gigantic if-statement like:

if(strcmp(name, "DoSomethin g")) {
DoSomething();
}
else if(strcmp(name, "DoOther")) {
DoOther();
}

but this would be terribly ugly when I have hundreds of
possibilities.. .
Do you see what I mean?

Thanks!
Jul 22 '05 #4

Richard Berg wrote:
I am writing a program that should call some API functions in a
specific order. The APIs are for another application, not Windows
APIs. The order and type of the calls is determined at runtime. There
are a couple of hundred of those APIs that can be called, and they all
take different parameters. What I need is somehow queue the calls with
their parameters and then dequeue and execute them one by one...


Check out the functor object implementation( s) in Andrei Alexandrescu's
book "Modern C++ Design"; I'm suggesting here a "Command object"-based
implementation using templated functor objects, which you'll find at least
one example of in the book.

The drawback of that type-safe method is that you'll need to define one
functor class for each distinct function signature. Whether to define each
functor class once or e.g. via some template mechanism at each usage point
is one design decision you'll need to address. Probably a combination of
predefined functors + support for ad-hoc definitions would be best.

If you're actually going to use all those API-functions then the
"Command object" solution is probably not too much work in comparision with
other methods and in comparision with the client code.

Jul 22 '05 #5
On 6 Jan 2004 13:47:31 -0800, bi***@mail.com (Richard Berg) wrote:
Hello,

I need implementation advice:
I am writing a program that should call some API functions in a
specific order. The APIs are for another application, not Windows
APIs. The order and type of the calls is determined at runtime. There
are a couple of hundred of those APIs that can be called, and they all
take different parameters. What I need is somehow queue the calls with
their parameters and then dequeue and execute them one by one... Now I
really have no idea on how to acomplish anything like this. Could
someone please advice me? I can provide more details if needed.

Please reply to the group.


Download boost from www.boost.org. Then:

#include <boost/function.hpp>
#include <boost/bind.hpp>

typedef boost::function <void()> void_function_t ;

std::deque<void _function_t> queue;

void execute_queue()
{
for(std::deque< void_function_t >::iterator i = queue.begin(),
end = queue.end();
i != end;
++i)
{
(*i)();
}
queue.clear();
}

Then to add a call to the queue, just do:

queue.push_back (boost::bind(my apifunction, param1, param2, param3));

Tom

C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #6

"Richard Berg" <bi***@mail.com > wrote in message
news:ff******** *************** ***@posting.goo gle.com...
"Samuele Armondi" <sa************ ****@hotmail.co m> wrote in message news:3ffb36d7_2 @mk-nntp- Do you see what I mean? [SNIP] Thanks!


Ok, I'll go through how i did it...I didn't use polymorphism since I did not
need it, but the bare bones is here.

This is your abstract base class, from which all the argument types will
inherit.
class ArgBase
{
//whatever
}

This is the class that holds all the arguments for a function
class FunctionArgumen ts
{
private:
int NumArgs;
ArgBase *Args; //This could be a std::vector rather than an array
const ArgTypes operator [] (const int) const;
public:
FunctionArgumen ts();
FunctionArgumen ts(int);
FunctionArgumen ts(const FunctionArgumen ts&); // throws
MemCopyError
~FunctionArgume nts();
FunctionArgumen ts& operator = (const FunctionArgumen ts&); // Need to
be defined because the class allocates memory

const int GetNumArgs() const;
// all the functions to set/retrieve the argument values
};

typedef bool (*FunctionPoint er) (const FunctionArgumen ts&);

This class holds the information about a function, such as its name, how
many arguments it takes, ecc. I used a string to represent the argument
sequence, for example a string "ii" meant that a function expected two
integer arguments, "fs" meant float and string, ecc...
class FunctionRecord
{
private:
std::string FunctionName;
std::string ArgumentSequenc e;
FunctionPointer Function; // Pointer to the actual function
int NumArgs;

bool CheckArgSequenc e(std::string&) ;
public:
FunctionRecord( std::string, std::string, int, FunctionPointer );
//throws InvalidArgSeque nce exception
FunctionRecord( );
//This function executes the API call. It inderects FunctionPointer
and passes all the arguments to the actual API call
bool Do(const FunctionArgumen ts&) const;
const std::string& GetArgSequence( ) const;
const std::string& GetFunctionName () const;
const int GetArgNum() const;
};

Then, you can hold everything in a map:
typedef std::map<std::s tring, FunctionRecord> FunctionMap;

I added most of the functions at compile time, but I did also make it
possible to add them at runtime. This code comes from the bare bones for an
in-game console I wrote for a friend, but it can very easily be adapted to
your needs.

Once you have the name of the function, you can look it up in the map and
call FunctionMap::se cond.Do(Argumen ts) to execute the call.
HTH!!
S. Armondi
Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1723
by: Dmitry Akselrod | last post by:
Hello Everyone, I have an almost well working Print Queue Monitoring software written. The software works quite well with typical Windows printing situations. However, there's a problem when a job is submitted to a print queue via LPD printing. I have a couple of server with Print Services for Unix installed (Windows 2000 SP4+). These servers are able to receive print jobs as Unix-type LPD print queue. Whenever a job is submitted...
7
4433
by: Shailesh Humbad | last post by:
I wrote a simple, but proprietary queue class that efficiently enqueues and dequeues arbitrary length byte arrays. I would like to replace it with an STL container if the performance overhead is not too high. Currently, I am thinking of replacing it like shown below, but it is not efficient due to repeated function calls to "push". Can anyone with more STL experience show a better way to use it, if there is one? // CUSTOM QUEUE //...
2
4656
by: Chuck | last post by:
I have not been able to find a good answer about the System.Collections.Queue.Synchronized() method and how it actually works or is to be used. If I create my Queue in the following manner: System.Collections.Queue myQueue = System.Collections.Queue.Synchronized(new System.Collections.Queue()); is it a Thread-Safe queue no matter where it is used? Or do I have to call
6
4997
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a PDF. It works fine so far....
9
2499
by: Brian Henry | last post by:
If i inherite a queue class into my class, and do an override of the enqueue member, how would i then go about actually doing an enqueue of an item? I am a little confused on this one... does over ride just add aditional code ontop of the current class or completely over ride it in vb? I am use to C++ this is the first inherited thing I've done in VB.NET... I'm a little unsure of diffrences, could someone explain this to me some? thanks!
13
2550
by: Jonathan Amsterdam | last post by:
I think there's a slight design flaw in the Queue class that makes it hard to avoid nested monitor deadlock. The problem is that the mutex used by the Queue is not easy to change. You can then easily get yourself into the following situation (nested monitor deadlock): Say we have a class that contains a Queue and some other things. The class's internals are protected by a mutex M. Initially the Queue is empty. The only access to the...
6
16717
by: les | last post by:
Here's a class which uses 2.0 generics to implement an inter-thread message queue in C#. Any number of threads can post and read from the queue simultaneously, and the message object can be any type. There's a test driver at the bottom which demonstrates usage. /*-----------------------------------------------------------------------------------------------------*/ using System; using System.Collections.Generic;
4
1118
by: | last post by:
I am trying to create a 'queue', or something like it. I am storing 1 to 6 integers in a list and need to move backwards and forwards in the list (like the back and forward arrows do in internet explorer, except these are numbers). I have tried a Stack, queue class, but can't seem to make them work right moving back forwards / backwards. This list of numbers will start with no numbers in it and grow to a max of 6 numbers, depending on how...
12
1412
by: Paul Rubin | last post by:
I'd like to suggest adding a new operation Queue.finish() This puts a special sentinel object on the queue. The sentinel travels through the queue like any other object, however, when q.get() encounters the sentinel, it raises StopIteration instead of returning the sentinel. It does not remove the sentinel from the queue, so further calls to q.get also raise StopIteration. That permits writing the typical "worker thread" as
0
9393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10153
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9946
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8830
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7371
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5272
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5413
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2800
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.