/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
/****** member functions of Class1 ******/
Class1::Class1() {
  void *fptr;
  fptr = dlsym(g_sample_dlhandle, "Class1_Class1_chdl");
  if(fptr == NULL)  {
     printf("Error: %s(): dlsym(): %s\n", __class_func__, dlerror());
     return;
  }
  dlrunfun(fptr, NULL, NULL);
}

Class1::~Class1() {
  void *fptr;
  fptr = dlsym(g_sample_dlhandle, "Class1_dClass1_chdl");
  if(fptr == NULL)  {
     printf("Error: %s(): dlsym(): %s\n", __class_func__, dlerror());
     return;
  }
  dlrunfun(fptr, NULL, NULL, this);
}

int Class1::memfun1(int i) {
  void *fptr;
  int retval;
  fptr = dlsym(g_sample_dlhandle, "Class1_memfun1_chdl");
  if(fptr == NULL)  {
     printf("Error: %s(): dlsym(): %s\n", __class_func__, dlerror());
     return -1;
  }
  dlrunfun(fptr, &retval, memfun1, this, i);
  return retval;
}

/****** member functions of Class2 ******/
Class2::Class2() {
  void *fptr;

  fptr = dlsym(g_sample_dlhandle, "Class2_Class2_chdl");
  if(fptr == NULL)  {
     printf("Error: %s(): dlsym(): %s\n", __class_func__, dlerror());
     return;
  }
  dlrunfun(fptr, NULL, NULL);
}

Class2::~Class2() {
  void *fptr;
  fptr = dlsym(g_sample_dlhandle, "Class2_dClass2_chdl");
  if(fptr == NULL)  {
     printf("Error: %s(): dlsym(): %s\n", __class_func__, dlerror());
     return;
  }
  dlrunfun(fptr, NULL, NULL, this);
}

Class1 Class2::memfun1() {
  void *fptr;
  Class1 *retval;

  fptr = dlsym(g_sample_dlhandle, "Class2_memfun1_chdl");
  if(fptr == NULL)  {
     printf("Error: %s(): dlsym(): %s\n", __class_func__, dlerror());
     exit -1;
  }
  retval = (Class1 *)malloc(sizeof(Class1));

  dlrunfun(fptr, NULL, NULL, retval, this);
  return *retval;
}

int Class2::memfun2(Class1 c) {
  void *fptr;
  int retval;

  fptr = dlsym(g_sample_dlhandle, "Class2_memfun2_chdl");
  if(fptr == NULL)  {
     printf("Error: %s(): dlsym(): %s\n", __class_func__, dlerror());
     return NULL;
  }

  dlrunfun(fptr, &retval, NULL, this, &c);
  return retval;
}
