/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
/****** member functions of Class1 ******/
Class1::Class1(){
  void *fptr;

  if(g_sample_dlhandle == NULL || g_sample_dlcount == 0) {
    g_sample_dlhandle = dlopen("libsampclass.dl", RTLD_LAZY);
    if(g_sample_dlhandle == NULL) {
       printf("Error: %s(): dlopen(): %s\n", __class_func__, dlerror());
       return;
    }
  }
  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);
  g_sample_dlcount++; // to increase count of instance
  return;
}

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);
  g_sample_dlcount--; // to decrease count of instance

  if(g_sample_dlcount <= 0 && g_sample_dlhandle != NULL) {
    if(dlclose(g_sample_dlhandle)!=0)
       printf("Error: %s(): dlclose(): %s\n", __class_func__, dlerror());
  }
  return;
}
