C++ instead ANSI C


#1

Hi All!

Who tried to coding application on c++?

i know that i can use simple C but it very inconveniently for big and serious applications i think.

I tried compiling the cpp application and it successfully compiled and running on module.
But after that i’ve noticed that many ADL and Basic API functions are not adapted for C++,
for exampe Timer:

class A
{
void setTimer();
static void timerCallBack(u8 ID);

 void ProcessTimer();

 int x,y,z;

}

void
A::setTimer()
{
adl_tmrSubscribe(TRUE /Cycle/, 10 /MSec/, ADL_TMR_TYPE_100MS, (adl_tmrHandler_t) A::timerCallBack)
}

void
A::timerCallBack(u8 ID)
{
ProcessTimer(); //ERROR

x = 10;  //ERROR
y = x*z; //ERROR
//we can't do nothing because timerCallBack is STATIC function we haven't pointer for A class;

}

But i’ve made own framework for many functions to additions of additional parameter, etc.

class A
{
void setTimer();
static void timerCallBack(u8 ID, void *User);

 void ProcessTimer();

}

void
A::setTimer()
{
adl_tmrSubscribe(TRUE /Cycle/, 10 /MSec/, ADL_TMR_TYPE_100MS, (adl_tmrHandler_t) A::timerCallBack, this)
}

void
A::timerCallBack(u8 ID, void User)
{
A
pApp = static_cast<A*>(User);

    pApp->ProcessTimer();
    
    pApp->x = 10;
    PApp->y = pApp->x*pApp->z;

  [b]  //works successfully[/b]

}

Maybe i make double work and there are other ways to workaround with C++?
or Wavecom have OpenAT version for C++?

it’s not a problem to make C++ framework with full feature ADL API, but it takes many time for me.

Thanx


#2

[b]Hi,

How did you managed to compile and link the cpp code?
what kind of toolchain and IDE do you use, and how did you configured it to link with ADL libs?

10x
Ido

By the way, I think a different design would solve your problem without modifing the framework,
keeping it easier to maintain with new versions. My suggested solution is as follows:[/b]

class Timer
{
public:
Timer();
virtual ~Timer();

public:
typedef enum
{
Disabled,
Enabled
} TimerState;

int				set( bool cyclic, int timeout, int resulution );
int				cancel();

protected:
virtual void callback();

private:
static void timerCallback( int id ) {}

private:
typedef map<int,Timer*> Container;
typedef pair<int,Timer*> Pair;

TimerState			state;
adl_tmr_t*			pHandle;
static Mutex		mux;
static Container	cont;

};

Timer::Timer() : state( 0 ), pHandle( NULL )
{
}

Timer::~Timer()
{
}

int
Timer::set( bool cyclic, int timeout, int resulution )
{
if( this->state != Timer::Disabled )
return -1;
Timer::mux.lock();
this->pHandle = adl_tmrSubscribe( cyclic,
timeout,
resulution,
Timer::timerCallback );
if( this->pHandle )
{
Timer::cont.insert( Pair( pHandle->TimerId, this ) );
this->state = Timer::Enabled;
}
Timer::mux.unlock();
return (int)( this->pHandle );
}

int
Timer::cancel()
{
if( this->state != Timer::Enabled )
return -1;
adl_tmrSubscribe( this->pHanlde,
Timer::timerCallback,
this->pHandle->TimerType );
this->state = Timer::Disabled;
Timer::mux.lock();
Container::iterator it;
it = Timer::cont.find( this->pHandle->TimerId );
Timer::cont.erase( it );
Timer::mux.unlock();
return 0;
}

void
Timer::timerCallback( int id )
{
Timer::mux.lock();
Container::iterator it;
it = Timer::cont.find( id );
Timer* pTimer = it->second;
if( !pTimer->pHandle->bCyclic )
{
Timer::cont.erase( it );
pTimer->state = Timer::Disabled;
}
Timer::mux.unlock();
pTimer->callback();
}


#3

in new versions OpenAT SDK not need make changes for Timer because u can use adl_tmrSubscribeEx() because u can sent ‘this’ pointer via “void * Context” parameter.

Managed code via VS2005 and compile it as well as all of you via wavecom toolkit (SGT e.t.c.), i only make changes in makefiles for C++ compiler (i use ADS1.2).

NOTE: for RVDS i see in make files targets for cpp code.


#4

Hi,
Can you describe ,in details, how to setup VS2005 IDE for creating OpenAT applications with C++ language.
thank you in advance,
Regards


#5

IF you’re starting from scratch, wouldn’t it be more profitable to start with M2M Studio?


#6

I do starting from the scratch. Over eight years of development C++ applications in VS IDE’s it is more comfortable for me. Anyway if you have any suggestion about M2M studio I 'll be very appreciated for any help