LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-03-2007, 02:48 AM   #1
altella
Member
 
Registered: Dec 2005
Posts: 84

Rep: Reputation: 16
translating C software from Win to Linux


Hello,

At work I need to translate some software writted in C code from Windows to Linux.
This software uses some functions of the windows API, and I donīt know how to translate them to Linux. These are my main problems:
- Timers support: At the moment I am using "SetTimer()" to stablish events after some time has passed. How could I do it with Linux?
- Thread support. I think this will not issue problems. It is well explained in "Advanced Linux programming" book.

I would be very grateful if you could help me with the timers problem.

Best regards,
 
Old 07-03-2007, 05:02 AM   #2
nc3b
Member
 
Registered: Aug 2005
Posts: 330

Rep: Reputation: 32
Hello. Here's what my drunken neuron has come up with a long time ago.

First declare a structure to gold parameters.

PHP Code:
struct param
{
    
int(*user_function)(int);
    
int pass_int;
    
int interval;
}; 
Then declare an all-purpose function, which will call your functions.

PHP Code:
void * function(void_parameter)
{
    
param parameter=(param*)_parameter;
    if(
parameter->user_function)
    {
        for(;;)
        {
            (
parameter->user_function)(parameter->pass_int);
            
sleep(parameter->interval);
        }
    }

Declare some dumb class

PHP Code:
class timer
{
    
param parameter;
    
pthread_t thread_id;
public:
    
    
timer(int _interval,int(*_function)(int),int _pass_int)
    {
        
parameter.interval=_interval;
        
parameter.user_function=_function;
        
parameter.pass_int;
        
pthread_create(&thread_id,NULL,&function,&parameter);
    }
}; 
Two "user" functions
PHP Code:
int function_to_run(int a)
{
    
cout<<"bla"<<endl;
}

int function_to_run2(int a)
{
    
cout<<"fdgdfg"<<endl;

Cross your fingers..

PHP Code:
int main(int argcchar** argv)
{
    
timer *tm2=new timer(2,&function_to_run2,43);
    
timer *tm=new timer(1,&function_to_run,47);

    while(
true);
    return 
0;

Of course, I have done no error testing, and as you can see, I am really not using the int parameter to the functions, nor am I using the functions return values.. (ugh.. the values they should return ).

Anyways, I am sure there's lots and lots of timer classes on the net.
 
Old 07-04-2007, 06:19 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Looks like C code to me ?
 
Old 07-04-2007, 07:08 AM   #4
nc3b
Member
 
Registered: Aug 2005
Posts: 330

Rep: Reputation: 32
What I wrote is not C code (look, there's that dumb class). I know the guy asked for C code, but I believe it's easy to quickly turn it into C code.
 
Old 07-04-2007, 07:40 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
True, what I meant was not the actual code content, but the 'PHP Code:' comment before each (C++) code block. It looks weird (possibly confusing to a newbie).
 
Old 07-04-2007, 08:06 AM   #6
nc3b
Member
 
Registered: Aug 2005
Posts: 330

Rep: Reputation: 32
Smile

You are right, it has happened before , but I php code has syntax highlighting.. In the future, I will avoid using php code tags or I will clearly state which language is the code written in. Cheers.
 
Old 07-04-2007, 01:12 PM   #7
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
For time timer code I would investigate setitimer and getitimer.
 
Old 07-04-2007, 03:42 PM   #8
nc3b
Member
 
Registered: Aug 2005
Posts: 330

Rep: Reputation: 32
I agree jitshaw. I actually found an example here. This could prove useful for me too in the future.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Software on Linux equivalent to PaperPort on Win satimis Linux - Software 2 02-20-2006 12:20 AM
Looking for a Computer Aided Translating software for SUSE Linux 9.3 Wojtek Linux - Software 5 02-17-2006 04:10 AM
Running Win Software on Linux nicklinux Linux - Software 3 09-25-2003 04:19 PM
Which has more software available, Win., Linux BajaNick General 8 08-11-2003 12:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration