Hi all,

I have a Problem with C++ Member Functions and Pointers to this Member 
Functions so that they fit into a Function with take a normal Function.
I guess i'm a Newbie, otherwise i should have already solved it, i think. ;)

I want to use IPC Stuff from Ecore. But before you can make use of ecore_ipc 
you must initialize it, as far as i can see.
I atached 4 Files, where i build a little Scenario:
1. Example.cpp // The Main Program
2. Testclass.hpp
3. Testclass.cpp
4. Makefile // Perhaps you must adjust some of the Variables

I commented the important Points in the Code again.

So i must first call 
ecore_ipc_init() // Testclass Line 68
and
must supply 3 Functions to ecore for handling Events
1. A Function that is called, when a new IPC Server is added
2. A Function that is called, when a IPC Server is deleted
3. A Function that is called, when some Message is sent

Namely:
ecore_event_handler_add( ECORE_IPC_EVENT_SERVER_ADD, ipc_server_add, NULL );
ecore_event_handler_add( ECORE_IPC_EVENT_SERVER_DEL, ipc_server_del, NULL );
ecore_event_handler_add( ECORE_IPC_EVENT_SERVER_DATA, ipc_server_data, NULL );

"ipc_server_add", "ipc_server_del" and "ipc_server_data" are the functions that 
are available outside the Class Testclass

The Example Program as it is compiles and i can start it, the ecore_pic_init() 
succeds the 3 Functions get "registered" but this 3 submitted Functions are 
standing outside my Testclass,
but my Target is to have they inside my Testclass.

That's my Problem, i didn't get the Clue to give these MemberFunctions to these 
3 Functions:
ecore_event_handler_add( ECORE_IPC_EVENT_SERVER_ADD, ipc_server_add, NULL );
ecore_event_handler_add( ECORE_IPC_EVENT_SERVER_DEL, ipc_server_del, NULL );
ecore_event_handler_add( ECORE_IPC_EVENT_SERVER_DATA, ipc_server_data, NULL );

I tried Things like that, but that didn't helped me:
ecore_event_handler_add( ECORE_IPC_EVENT_SERVER_DEL, boost::bind( 
boost::type<int>(), &Testclass::ipc_server_add ), NULL );
ecore_event_handler_add( ECORE_IPC_EVENT_SERVER_DEL, boost::bind( 
boost::type<int>(), &Testclass::ipc_server_add, _1, _2, _3 ), NULL );

So i want to ask to the Mailinglist in Hope somebody knows how to do this Task 
in the right Way. ;)

Thanks for your help and Greets to all,
        Christian
#include "Testclass.hpp"

#include <iostream>

using namespace std;

int
main( int argc, char *argv[] ) {

  cout << "Creating an Instance of the Testclass \n";
  Testclass * testclass = new Testclass();

  if ( !testclass->Init() ) {
    cout << "Initialization of ecore_ipc failed.\n";
  } else {
    cout << "Initialization of ecore_ipc succeded.\n";
  }

  cout << "Delete the Instance of the Testclass\n";
  delete testclass;
  return 0;
}

Attachment: Makefile
Description: Binary data

#include "Testclass.hpp"

#include <iostream>

// Boost
#include <boost/format.hpp>
using boost::format;

using namespace std;

/**
 * ipc_server_add - when we connect to the ipc daemon
 * @data -
 * @type - 
 * @event - the Ecore_Ipc_Event_Server_Add that triggered us
 */
int
ipc_server_add( void *data, int type, void *event ) {
  Ecore_Ipc_Event_Server_Add * e;

  e = ( Ecore_Ipc_Event_Server_Add * ) event;
  cout << format( "Server add \n" );
  return 1;
}

/**
 * ipc_server_del - when we disconnect from the ipc daemon
 * @data -
 * @type - 
 * @event - the Ecore_Ipc_Event_Server_Del that triggered us
 */
int
ipc_server_del( void *data, int type, void *event ) {
  Ecore_Ipc_Event_Server_Del * e;

  e = ( Ecore_Ipc_Event_Server_Del * ) event;
  cout << format( "Server del \n" );
  return 1;
}

/**
 * ipc_server_data - 
 * @data -
 * @type - 
 * @event - the Ecore_Ipc_Event_Server_Data that triggered us
 */
int
ipc_server_data( void *data, int type, void *event ) {
  Ecore_Ipc_Event_Server_Data * e;

  e = ( Ecore_Ipc_Event_Server_Data * ) event;
  cout << format( "Server sent [%i] [%i] (%i) \"%s\\n" ) % e->major % e->minor % e->size % e->data;
  return 1;
}

Testclass::Testclass()
    : server( NULL ) {}
Testclass::~Testclass() {

  if ( server != NULL ) {
    // ecore_ipc_server_del( server );
  }
}

bool
Testclass::Init() {

  if ( ecore_ipc_init() < 1 ) {
    return 0;
  }


  // Create a IPC Server
  server = ecore_ipc_server_add( ECORE_IPC_LOCAL_USER, "Testclass IPC Server", 0, NULL );
  if ( server == NULL ) {
    cout << "Creating new IPC server failed\n";
    return 0;
  }

  // Here is my Problem, i didn't get a valid Pointer to one of my Memberfunctions
  // My Tries looks like these:
  //   ecore_event_handler_add( ECORE_IPC_EVENT_SERVER_DEL, boost::bind( boost::type<int>(), &Testclass::ipc_server_add ), NULL );
  //   ecore_event_handler_add( ECORE_IPC_EVENT_SERVER_DEL, boost::bind( boost::type<int>(), &Testclass::ipc_server_add, _1, _2, _3 ), NULL );

  ecore_event_handler_add( ECORE_IPC_EVENT_SERVER_ADD, ipc_server_add, NULL );
  ecore_event_handler_add( ECORE_IPC_EVENT_SERVER_DEL, ipc_server_del, NULL );
  ecore_event_handler_add( ECORE_IPC_EVENT_SERVER_DATA, ipc_server_data, NULL );

  char buf[ 512 ];
  char *msg = "Hello World";
  int major = 10;

  snprintf( buf, 512, "%s", msg );
  ecore_ipc_server_send( server, major, 6, 0, 0, 0, buf, strlen( buf ) + 1 );
  memset( buf, 0, sizeof( buf ) );


  return 1;
}
#ifndef __TESTCLASS_HPP__
#define __TESTCLASS_HPP__

#include <Ecore.h>
#include <Ecore_Ipc.h>

class Testclass {

public:
  Testclass();
  ~Testclass();

  bool Init();

  bool Server_Add();

  // I would like to have these 3 Functions inside the Testclass, and the refering 3 Functions at Testclass.cpp (Lines 11-54) away,
	// but i don't know how to do this.
  // I tried it with the Help of boost::bind but i didn't get something working out of it

  // int ipc_server_add( void *data, int type, void *event );
  // int ipc_server_del( void *data, int type, void *event );
  // int ipc_server_data( void *data, int type, void *event )

private:
  Ecore_Ipc_Server *server;
};

#endif // __TESTCLASS_HPP__

Reply via email to