Esempio n. 1
0
/* Caution! singelton. */
static iOTrace _inst ( tracelevel level, const char* file, Boolean toStdErr) {
  if( traceInst == NULL ) {
    iOTrace     trace = allocIDMem( sizeof( struct OTrace ), RocsTraceID );
    iOTraceData data  = allocIDMem( sizeof( struct OTraceData ), RocsTraceID );

    MemOp.basecpy( trace, &TraceOp, 0, sizeof( struct OTrace ), data );

    data->mux      = MutexOp.inst( NULL, True );
    data->ebcdic   = EbcdicOp.inst( CODEPAGE_1252, NULL );
    data->level    = level;
    data->toStdErr = toStdErr;
    data->dumpsize = TRC_DUMPSIZE;
    data->appID    = StrOp.dupID( "..", RocsTraceID );
    data->filesize = TRC_FILESIZE;
    data->nrfiles  = TRC_NRFILES;

    traceInst = trace;

    instCnt++;

    if( file != NULL )
      _setFilename( trace, file );

    mainThreadId = ThreadOp.id();
    return trace;
  }
  else
    return traceInst;
}
Esempio n. 2
0
static iOMutex _inst( const char* name, Boolean create ) {
  iOMutex     mutex = allocIDMem( sizeof( struct OMutex ), RocsMutexID );
  iOMutexData data  = allocIDMem( sizeof( struct OMutexData ), RocsMutexID );

  Boolean ok = False;

  MemOp.basecpy( mutex, &MutexOp, 0, sizeof( struct OMutex ), data );

  data->name = StrOp.dupID( name, RocsMutexID );
  if( data->name == NULL ) {
    data->name = StrOp.fmtID( RocsMutexID, "MUX%08X", data );
  }

  if( create )
    ok = rocs_mutex_create( data );
  else
    ok = rocs_mutex_open( data );

  if( !ok ) {
    /* error */
    fprintf( stderr, "Error Mutex: %s rc=%d", data->name, data->rc);
    __del( mutex );
    return NULL;
  }

  instCnt++;

  return mutex;
}
Esempio n. 3
0
static iOList _inst(void) {
  iOList     list = allocIDMem( sizeof( struct OList ), RocsListID );
  iOListData data = allocIDMem( sizeof( struct OListData ), RocsListID );

  MemOp.basecpy( list, &ListOp, 0, sizeof( struct OList ), data );

  data->objList     = allocIDMem( sizeof( obj ) * LIST_MINSIZE, RocsListID );
  data->allocsize   = LIST_MINSIZE;

  instCnt++;

  return list;
}
Esempio n. 4
0
static iOQueue _inst( int size ) {
  iOQueue     queue = allocIDMem( sizeof( struct OQueue ), RocsQueueID );
  iOQueueData data  = allocIDMem( sizeof( struct OQueueData ), RocsQueueID );

  MemOp.basecpy( queue, &QueueOp, 0, sizeof( struct OQueue ), data );

  data->mux = MutexOp.inst( NULL, True );
  data->evt = EventOp.inst( NULL, True );
  EventOp.reset( data->evt );
  data->size = size;

  instCnt++;

  return queue;
}
Esempio n. 5
0
static void _sort( iOList inst, comparator comp ) {
  if( inst != NULL ) {
    iOListData data = Data(inst);
    int size = ListOp.size( inst );
    int i = 0;
    int moved = 0;
    void** objlist;
    
    if( size < 2 )
      return;
    
    /* init index: */  
    objlist = allocIDMem( size * sizeof(void*), RocsListID );
    for( i = 0; i < size; i++ ) {
      objlist[i] = (void*)ListOp.get( inst, i );
    }
  
    qsort( (void *)objlist, (size_t)size, sizeof(void*), (qsort_compar)comp );
    
    /* copy objects in the new list */
    ListOp.clear( inst );
    for( i = 0; i < size; i++ )
      ListOp.add( inst, objlist[i] ); 
    
    /* cleanup index */
    freeIDMem( objlist, RocsListID );
  }
  else {
    TraceOp.trc( name, TRCLEVEL_WARNING, __LINE__, 9999, "inst == NULL" );
  }
}
Esempio n. 6
0
int rocs_scanDir(const char *dirname, const char* extension, iDirEntry** namelist)
{
  struct _finddata_t c_file;
  long hFile;
  int found = 0;
  int done = 0;

  char* search = StrOp.fmt( "%s%c*%s", dirname, SystemOp.getFileSeparator(), extension!=NULL?extension:".*" );

  hFile = _findfirst( search, &c_file );
  StrOp.free( search );

  if( hFile == -1L )
    return found;

  do {
    if( namelist != NULL ) {
      iDirEntry dir = allocIDMem( sizeof( struct DirEntry ), RocsDirID );
      *namelist = reallocMem( *namelist, (found+1)*sizeof(iDirEntry) );
      dir->name = StrOp.dupID( c_file.name, RocsDirID );
      dir->mtime = c_file.time_write;
      (*namelist)[found] = dir;
    }
    found++;

    done = _findnext( hFile,  &c_file );
  }
  while( !done );

  _findclose(hFile);

  return found;
}
Esempio n. 7
0
static iOFile _inst( const char* path, int openflag ) {
  iOFile     file = allocIDMem( sizeof( struct OFile ), RocsFileID );
  iOFileData data = allocIDMem( sizeof( struct OFileData ), RocsFileID );


  MemOp.basecpy( file, &FileOp, 0, sizeof( struct OFile ), data );

  data->openflag = openflag;
  data->path     = StrOp.dupID( path, RocsFileID );
  instCnt++;

  if( !__openFile(data) ) {
    file->base.del( file );
    file = NULL;
  }

  return file;
}
Esempio n. 8
0
static iOThread _inst( const char* tname, thread_run run, void* parm ) {
  iOThread     thread = allocIDMem( sizeof( struct OThread ), RocsThreadID );
  iOThreadData data   = allocIDMem( sizeof( struct OThreadData ), RocsThreadID );

  MemOp.basecpy( thread, &ThreadOp, 0, sizeof( struct OThread ), data );

  data->queue = QueueOp.inst( 1000 );
  data->parm  = parm;

  if( tname == NULL )
    data->tname = StrOp.fmtID( RocsThreadID, "tid0x%08X", thread );
  else
    data->tname = StrOp.dupID( tname, RocsThreadID );

  data->run = run;

  instCnt++;
  __addThread( thread );

  return thread;
}
Esempio n. 9
0
/* ------------------------------------------------------------
 * StrTokOp.inst()
 */
static iOStrTok _inst( const char* str, char sep ) {
  iOStrTok     obj  = allocIDMem( sizeof( struct OStrTok     ), RocsStrTokID );
  iOStrTokData data = allocIDMem( sizeof( struct OStrTokData ), RocsStrTokID );

  /* OAttrData */
  data->sep = sep;

  if( str != NULL && StrOp.len(str) > 0 )
    data->str = StrOp.dupID( str, RocsStrTokID );
  
  data->nextToken = data->str;

  /* OBase operations */
  MemOp.basecpy( obj, &StrTokOp, 0, sizeof( struct OStrTok ), data );

  instCnt++;

  __countTokens( obj );
  
  return obj;
}
Esempio n. 10
0
/*
 ***** __Private functions.
 */
DIR * opendir( char *pchfile )
{
  DIR * p = NULL;

  p = (DIR *)allocIDMem( sizeof(DIR), RocsDirID );
  if(p)
  {
     strcpy( p->Dirent.d_name, pchfile );
     strcat( p->Dirent.d_name, "\\*.*" );
     p->openflag = 0;
  }
  return p;
}
Esempio n. 11
0
/** Get a message by key. */
static const char* _getMenu( struct ORes* inst ,const char* key, Boolean useAccel ) {
  iOResData data = Data(inst);
  if( data->msgMap != NULL ) {
    iONode msg = (iONode)MapOp.get( data->msgMap, key );
    if( msg != NULL ) {
      const char* shortcutkey = NodeOp.getStr( msg, "key", NULL );
      iONode lang = NodeOp.findNode( msg, data->language );
      if( lang == NULL )
        lang = NodeOp.findNode( msg, "all" );
      if( lang == NULL )
        lang = NodeOp.findNode( msg, "en" );
      if( lang != NULL ) {
        Boolean dialog = NodeOp.getBool( msg, "dialog", False );
        int accel = useAccel ? NodeOp.getInt( lang, "accel", -1 ) : -1;
        const char* txt = NodeOp.getStr( lang, "alttxt", NULL );
        const char* menu = NodeOp.getStr( lang, "menu", NULL );
        if( txt == NULL || StrOp.len(txt) == 0 )
          txt = NodeOp.getStr( lang, "txt", key );
        if( menu == NULL ) {
          char* menustr = StrOp.fmt( "%s%s%s%s", txt, dialog?"...":"", shortcutkey!=NULL?"\t":"", shortcutkey!=NULL?shortcutkey:"" );
          if( accel != -1 ) {
            int strlen = StrOp.len( menustr );
            char* amenustr = allocIDMem( strlen + 2, RocsStrID );
            int i = 0;
            int idx = 0;
            for( i = 0; i < strlen; i++ ) {
              if( i == accel ) {
                amenustr[idx] = '&';
                idx++;
              }
              amenustr[idx] = menustr[i];
              idx++;
              amenustr[idx] = '\0';
            }
            StrOp.free( menustr );
            menustr = amenustr;
          }
          NodeOp.setStr( lang, "menu", menustr );
          StrOp.free( menustr );
          return NodeOp.getStr( lang, "menu", NULL );
        }
        else
          return menu;
      }
    }
  }
  TraceOp.trc( name, TRCLEVEL_WARNING, __LINE__, 9999, "Resource [%s_%s] not found.", data->language, key );
  return key;
}
Esempio n. 12
0
static Boolean _cp( const char* src, const char* dst ) {
  Boolean     ok = False;
  int buffersize = 1024 * 1024;
  byte*   buffer = NULL;

  /* Correct file separators. */
  _convertPath2OSType( src );
  _convertPath2OSType( dst );

  /* Allocate buffer for copy. */
  buffer = allocIDMem( buffersize, RocsFileID );

  if( buffer != NULL && FileOp.exist( src ) ) {
    iOFile srcFile = FileOp.inst( src, OPEN_READONLY );
    iOFile dstFile = FileOp.inst( dst, OPEN_WRITE );
    if( srcFile != NULL && dstFile != NULL ) {
      long    readed = 0;
      long   written = 0;
      long     fsize = FileOp.size( srcFile );
      long readtotal = 0;

      do {
        long toread = buffersize;

        if( readtotal + buffersize > fsize )
          toread = fsize - readtotal;

        ok = FileOp.read( srcFile, (char*)buffer, toread );
        readed = FileOp.getReaded( srcFile );
        readtotal += readed;

        if( ok && readed > 0 ) {
          ok = FileOp.write( dstFile, (char*)buffer, readed );
          written += FileOp.getWritten( dstFile );
        }

      } while( ok && fsize > written );

    }
    FileOp.base.del( srcFile );
    FileOp.base.del( dstFile );

  }

  freeIDMem( buffer, RocsFileID );

  return ok;
}
Esempio n. 13
0
/* initializes the windows socket implementation */
Boolean rocs_socket_init( iOSocketData o ) {
#ifdef __ROCS_SOCKET__
    WSADATA         WsaData;

    if( o->hostaddr == NULL ) {
        o->hostaddr = allocIDMem( sizeof( struct in_addr ), RocsSocketID );
    }

    /* Init WinSocks 1.1 */
    if( WSAStartup(0x0101, &WsaData) == SOCKET_ERROR )
    {
        o->rc = WSAGetLastError();
        TraceOp.trc( name, TRCLEVEL_EXCEPTION, __LINE__, 9999, "WSAStartup() failed: %d", WSAGetLastError());
        return False;
    }
    TraceOp.trc( name, TRCLEVEL_DEBUG, __LINE__, 9999, "WinSocks initialized." );
#endif
    return True;
}
Esempio n. 14
0
static qMsg __newQMsg( obj po, q_prio prio ) {
  qMsg m = allocIDMem( sizeof( struct SqMsg ), RocsQueueID );
  m->o = po;
  m->prio = prio;
  return m;
}