Exemplo n.º 1
0
StatisticsModel::StatisticsModel()
{
    _items[PROCESS_ALL] = StModelItem();
    _this = this;

    InitDatabase();
}
Exemplo n.º 2
0
MoonAppRecord *
MoonInstallerService::GetAppRecord (Deployment *deployment)
{
	const Uri *xap_uri = deployment->GetXapLocation ();
	const char *base_dir = GetBaseInstallDir ();
	const char *start, *inptr;
	MoonAppRecord *app;
	char *uid;
	
	if (!InitDatabase ())
		return NULL;
	
	if (IsRunningOutOfBrowser (deployment)) {
		// we'll need to get the uid used by this app, which can be
		// extracted from the local path.
		start = xap_uri->GetPath () + strlen (base_dir);
		if (*start == '/')
			start++;
		
		inptr = start;
		while (*inptr != '/')
			inptr++;
		
		uid = g_strndup (start, inptr - start);
		app = db->GetAppRecordByUid (uid);
		g_free (uid);
	} else {
		app = db->GetAppRecordByOrigin (xap_uri);
	}
	
	return app;
}
Exemplo n.º 3
0
LPBYTE CIGNTileDatabase::ReadTile(long northing, long easting, long * size)
{
	*size = 0;
	InitDatabase(northing, easting);
	if (m_hFile == INVALID_HANDLE_VALUE)
		return NULL;
	DWORD offset = m_fileheader.m_offsets[northing%100000/m_fileheader.m_scale*(100000/m_fileheader.m_scale)+easting%100000/m_fileheader.m_scale];
	if (offset == 0 || offset == 1)
		return NULL;				// either not loaded, or no tile
	SetFilePointer(m_hFile, offset, NULL, FILE_BEGIN);
	DWORD tile_length, nRead;
	ReadFile(m_hFile, &tile_length, sizeof(DWORD), &nRead, NULL);
	if (nRead != sizeof(DWORD)) {
		printf("Error reading length from %s. Easting=%d, northing=%d\n", m_filename, easting, northing);
		return NULL;
	}
	BYTE * buffer = (BYTE*)malloc(tile_length);
	if (buffer == NULL) {
		printf("Couldn't allocate %d bytes to read easting=%d, northing=%d of %s\n", tile_length, easting, northing, m_filename);
		return NULL;
	}
	ReadFile(m_hFile, buffer, tile_length, &nRead, NULL);
	if (nRead !=tile_length) {
		printf("Error reading data from %s. Easting=%d, northing=%d\n", m_filename, easting, northing);
		return NULL;
	}
	*size = tile_length;
	return buffer;
}
Exemplo n.º 4
0
MoonAppRecord *
MoonInstallerService::GetAppRecord (const char *uid)
{
	if (!InitDatabase ())
		return NULL;
	
	return db->GetAppRecordByUid (uid);
}
bool InitHandler() {
    RegisterHandler();
    if (!InitDatabase()) {
        return false;
    }

    return true;
}
Exemplo n.º 6
0
MoonAppRecord *
MoonInstallerService::CreateAppRecord (const Uri *origin)
{
	if (!InitDatabase ())
		return NULL;
	
	return db->CreateAppRecord (origin);
}
Exemplo n.º 7
0
void file_close(Widget w, void *data)
{
   MyProgram *me=data;
   int okay;
   char *new_file_name;

   if (me->project_saved == FALSE)
   {
      okay = GetYesNo("Model file not saved!!\n\nDo you want to save it now?");  
      if (okay)
      {
         if (strlen(me->save_file_name) == 0)
         {
            new_file_name = GetString("Enter file name to save as (file.mdl)\n", NULL);

            if ( (new_file_name != (char *) NULL) 
			&& (strlen(new_file_name) > 0) )
            {
               if (strlen(new_file_name) < FILE_STRING_LEN)
                  strcpy(me->save_file_name, new_file_name);
               else {
                  strncpy(me->save_file_name, new_file_name, FILE_STRING_LEN);
                  me->save_file_name[FILE_STRING_LEN - 1] = '\0';
               }
            }
            else
            {
               printf("saving cancelled\n");
               okay = FALSE;
            }
         }

         if (okay)
         {
            me->save_file = fopen(me->save_file_name, "w");
            if (me->save_file == (FILE *) NULL)
            {
               fprintf(stderr, "file_close: can't open '%s' as model file\n", me->save_file_name);
               exit(1);
            }

/*
            SaveModel(me);
*/

            me->project_saved = TRUE;

            fclose(me->save_file);
         }
      }
   }

   InitDatabase(me);
   UpdateDisplay(me);
   
   printf("files closed\n");
}
Exemplo n.º 8
0
void main(int argc, char **argv)
{
  MyProgram mydata;

  InitDatabase(&mydata);

  init_display(argc, argv, &mydata);  /* setup the display */

  MainLoop();                         /* go right into the main loop */
}
Exemplo n.º 9
0
BOOL CIGNTileDatabase::TileLoaded(long northing, long easting)
{
	InitDatabase(northing, easting);
	if (m_hFile == INVALID_HANDLE_VALUE)
		return FALSE;
	DWORD offset = m_fileheader.m_offsets[northing%100000/m_fileheader.m_scale*(100000/m_fileheader.m_scale)+easting%100000/m_fileheader.m_scale];
	if (offset == 0 || offset == 1)
		return FALSE;				// either not loaded, or no tile
	return TRUE;
}
/**
 * Initializes the databases and notifies any callers waiting on waitForInit.
 *
 * @param context the Context to use for opening the database
 * @param databaseFile Name of the file to be initialized.
 */
void HttpAuthDatabase::InitOnBackgroundThread(
    /* [in] */ IContext* context,
    /* [in] */ String databaseFile)
{
    AutoLock lock(mInitializedLock);
    if (mInitialized) {
        return;
    }

    InitDatabase(context, databaseFile);

    // Thread done, notify.
    mInitialized = TRUE;
    mInitializedLock.NotifyAll();
}
Exemplo n.º 11
0
// The constructor does all heavy work, errors are returned as exceptions
Routine::Routine(Queue &queue, EventPointer event, const std::string &name,
                 const std::vector<std::string> &kernel_names, const Precision precision,
                 const std::vector<database::DatabaseEntry> &userDatabase,
                 std::initializer_list<const char *> source):
    precision_(precision),
    routine_name_(name),
    kernel_names_(kernel_names),
    queue_(queue),
    event_(event),
    context_(queue_.GetContext()),
    device_(queue_.GetDevice()),
    db_(kernel_names) {

  InitDatabase(device_, kernel_names, precision, userDatabase, db_);
  InitProgram(source);
}
Exemplo n.º 12
0
void
DOMStorageDBThread::ThreadFunc()
{
  nsresult rv = InitDatabase();

  MonitorAutoLock lockMonitor(mMonitor);

  if (NS_FAILED(rv)) {
    mStatus = rv;
    mStopIOThread = true;
    return;
  }

  while (MOZ_LIKELY(!mStopIOThread || mPreloads.Length() || mPendingTasks.HasTasks())) {
    if (MOZ_UNLIKELY(TimeUntilFlush() == 0)) {
      // Flush time is up or flush has been forced, do it now.
      UnscheduleFlush();
      if (mPendingTasks.Prepare()) {
        {
          MonitorAutoUnlock unlockMonitor(mMonitor);
          rv = mPendingTasks.Execute(this);
        }

        if (!mPendingTasks.Finalize(rv)) {
          mStatus = rv;
          NS_WARNING("localStorage DB access broken");
        }
      }
      NotifyFlushCompletion();
    } else if (MOZ_LIKELY(mPreloads.Length())) {
      nsAutoPtr<DBOperation> op(mPreloads[0]);
      mPreloads.RemoveElementAt(0);
      {
        MonitorAutoUnlock unlockMonitor(mMonitor);
        op->PerformAndFinalize(this);
      }

      if (op->Type() == DBOperation::opPreloadUrgent) {
        SetDefaultPriority(); // urgent preload unscheduled
      }
    } else if (MOZ_UNLIKELY(!mStopIOThread)) {
      lockMonitor.Wait(TimeUntilFlush());
    }
  } // thread loop

  mStatus = ShutdownDatabase();
}
Exemplo n.º 13
0
void CIGNTileDatabase::DeleteTile(long northing, long easting)
{
	InitDatabase(northing, easting);
	if (m_hFile == INVALID_HANDLE_VALUE)
		return;
	DWORD offset = northing%100000/m_fileheader.m_scale*(100000/m_fileheader.m_scale)+easting%100000/m_fileheader.m_scale;
	if (m_fileheader.m_offsets[offset]) {
		printf("Clearing item of easting=%d, northing=%d, %s\n", easting, northing, m_filename);
	}
	SetFilePointer(m_hFile, (char*)&m_fileheader.m_offsets[offset] - (char*)&m_fileheader, NULL, FILE_BEGIN);
	DWORD nWritten;
	long	fileOffset=0;
	WriteFile(m_hFile, &fileOffset, sizeof(long), &nWritten, NULL);
	m_fileheader.m_offsets[offset] = fileOffset;
	if (nWritten != sizeof(long)) {
		printf("Error writing offset to %s. Easting=%d, northing=%d\n", m_filename, easting, northing);
		return;
	}
}
Exemplo n.º 14
0
GameServer::GameServer(unsigned short usPort)
:m_evtStop(true, false), // manual-reset event
 m_evtStopped(true, false), // manual-reset event
 m_sessionManager(m_authManager, m_worldModel, m_ioService.Get()),
 m_networkManager(m_sessionManager, m_ioService.Get(), usPort),
 m_actionQueue(m_ioService.Get(), m_worldModel),
 m_worldRunner(m_worldModel),
 m_worldModel(m_sessionManager, m_actionQueue)
{
   InitDatabase();

   // add static account
   Account a;
   a.Username(_T("michi"));
   a.Password(_T("88D60A34770813E4B5FB7735DBDB1FF1FAEC2F3A6376926D6A72F8CD26BB2ADAE1DA8A41F6B3B019863738C7E9AE168CA1A79A52269619E65D9C234B395A08BC41A5776F0FA92095CFF4A1AAEC9955F274A1C76E547CB300434A12D3E1A0AEA4C37E4C67EC7369A7FF2D5FBACCF1AC4A1B3C3932607F661D2E1A4DB620612D00"));
   a.Salt(_T("26F3DF6AD81481E2761DB9EFE56E3BD8"));
   a.LogonAllowed(true);
   a.AccountId(42);

   m_authManager.AddAccount(a);
}
Exemplo n.º 15
0
BOOL CDlgTKManage::OnInitDialog()
{
	CAcUiDialog::OnInitDialog();

	// TODO:  在此添加额外的初始化
	m_TreeCtrl.ModifyStyle(0, TVS_HASBUTTONS | TVS_LINESATROOT | TVS_HASLINES);
	m_strParentPath = _T("F:\\SVN\\201406\\");
	m_TreeCtrl.SetParentPath(m_strParentPath);
	m_TreeCtrl.DisPlayTree(_T("ZWHG"), TRUE);
	HTREEITEM hRoot = m_TreeCtrl.GetRootItem();

	HTREEITEM hChild = m_TreeCtrl.GetChildItem(hRoot);
	m_TreeCtrl.Expand(hRoot, TVE_EXPAND);
	m_TreeCtrl.Expand(hChild, TVE_EXPAND);

	HTREEITEM hNextItem = m_TreeCtrl.GetChildItem(hChild);
	m_strFileName = m_TreeCtrl.GetFullPath(hNextItem) + _T(".dwg");
	InitDatabase();
	InitGraphList();
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}
Exemplo n.º 16
0
void CDlgTKManage::OnTvnSelchangedTypeName(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
	HTREEITEM hCurSel = m_TreeCtrl.GetSelectedItem();
	CString strGet = m_TreeCtrl.GetItemText(hCurSel);

	if (m_TreeCtrl.ItemHasChildren(hCurSel) && (!m_TreeCtrl.GetParentItem(hCurSel)))//父节点
	{

	}
	else if (m_TreeCtrl.ItemHasChildren(hCurSel) && m_TreeCtrl.GetParentItem(hCurSel))//所选为节点
	{
		
	}
	else if (!m_TreeCtrl.ItemHasChildren(hCurSel))
	{
		m_strFileName = m_TreeCtrl.GetFullPath(hCurSel) + _T(".dwg");
		InitDatabase();
		InitGraphList();
	}	
	*pResult = 0;
}
Exemplo n.º 17
0
void cmd_setup_system(Widget w, void *data)
{
  MyProgram *me=data;

  printf("setup particle system\n");

  InitDatabase(me);
  GenerateParticleSystem(me, 0);
  SetupAnimToRun(me);
  UpdateDisplay(me);

/*
  if (setsys(me))
     printf("  Cancelled\n");
  else
  {
     GenerateParticleSystem(me, 0);

     UpdateDisplay(me);
  }
*/

}
Exemplo n.º 18
0
void CIGNTileDatabase::WriteTile(long northing, long easting, LPBYTE data, long size)
{
	InitDatabase(northing, easting);
	if (m_hFile == INVALID_HANDLE_VALUE)
		return;
	DWORD offset = northing%100000/m_fileheader.m_scale*(100000/m_fileheader.m_scale)+easting%100000/m_fileheader.m_scale;
	if (m_fileheader.m_offsets[offset]) {
//		printf("Replacing data of easting=%d, northing=%d, %s\n", easting, northing, m_filename);
	}
	SetFilePointer(m_hFile, (char*)&m_fileheader.m_offsets[offset] - (char*)&m_fileheader, NULL, FILE_BEGIN);
	DWORD nWritten;
	long	fileOffset;
	if (size == 0)
		fileOffset = 1;
	else
		fileOffset = GetFileSize(m_hFile, NULL);
	WriteFile(m_hFile, &fileOffset, sizeof(long), &nWritten, NULL);
	m_fileheader.m_offsets[offset] = fileOffset;
	if (nWritten != sizeof(long)) {
		printf("Error writing offset to %s. Easting=%d, northing=%d\n", m_filename, easting, northing);
		return;
	}
	if (size == 0)
		return;
	SetFilePointer(m_hFile, fileOffset, NULL, FILE_BEGIN);
	WriteFile(m_hFile, &size, sizeof(long), &nWritten, NULL);
	if (nWritten != sizeof(long)) {
		printf("Error writing size to %s. Easting=%d, northing=%d\n", m_filename, easting, northing);
		return;
	}
	WriteFile(m_hFile, data, size, &nWritten, NULL);
	if (nWritten != size) {
		printf("Error writing tile to %s. Easting=%d, northing=%d\n", m_filename, easting, northing);
		return;
	}
}
Exemplo n.º 19
0
void
DOMStorageDBThread::ThreadFunc()
{
  nsresult rv = InitDatabase();

  MonitorAutoLock lockMonitor(mThreadObserver->GetMonitor());

  if (NS_FAILED(rv)) {
    mStatus = rv;
    mStopIOThread = true;
    return;
  }

  // Create an nsIThread for the current PRThread, so we can observe runnables
  // dispatched to it.
  nsCOMPtr<nsIThread> thread = NS_GetCurrentThread();
  nsCOMPtr<nsIThreadInternal> threadInternal = do_QueryInterface(thread);
  MOZ_ASSERT(threadInternal); // Should always succeed.
  threadInternal->SetObserver(mThreadObserver);

  while (MOZ_LIKELY(!mStopIOThread || mPreloads.Length() ||
                    mPendingTasks.HasTasks() ||
                    mThreadObserver->HasPendingEvents())) {
    // Process xpcom events first.
    while (MOZ_UNLIKELY(mThreadObserver->HasPendingEvents())) {
      mThreadObserver->ClearPendingEvents();
      MonitorAutoUnlock unlock(mThreadObserver->GetMonitor());
      bool processedEvent;
      do {
        rv = thread->ProcessNextEvent(false, &processedEvent);
      } while (NS_SUCCEEDED(rv) && processedEvent);
    }

    if (MOZ_UNLIKELY(TimeUntilFlush() == 0)) {
      // Flush time is up or flush has been forced, do it now.
      UnscheduleFlush();
      if (mPendingTasks.Prepare()) {
        {
          MonitorAutoUnlock unlockMonitor(mThreadObserver->GetMonitor());
          rv = mPendingTasks.Execute(this);
        }

        if (!mPendingTasks.Finalize(rv)) {
          mStatus = rv;
          NS_WARNING("localStorage DB access broken");
        }
      }
      NotifyFlushCompletion();
    } else if (MOZ_LIKELY(mPreloads.Length())) {
      nsAutoPtr<DBOperation> op(mPreloads[0]);
      mPreloads.RemoveElementAt(0);
      {
        MonitorAutoUnlock unlockMonitor(mThreadObserver->GetMonitor());
        op->PerformAndFinalize(this);
      }

      if (op->Type() == DBOperation::opPreloadUrgent) {
        SetDefaultPriority(); // urgent preload unscheduled
      }
    } else if (MOZ_UNLIKELY(!mStopIOThread)) {
      lockMonitor.Wait(TimeUntilFlush());
    }
  } // thread loop

  mStatus = ShutdownDatabase();

  if (threadInternal) {
    threadInternal->SetObserver(nullptr);
  }
}
Exemplo n.º 20
0
void next_frame(void *data, XtIntervalId *id)
{
  MyProgram *me=data;

  if (me->data.anim.enable_anim) 
  {
    
     printf("frame #%d:\n", me->data.anim.frame_count);
       
     switch(me->data.anim.mode)
     {
        case STOP_ANIM:
           ComputeNextFrame(me);
           me->data.anim.enable_anim = FALSE;
           break;

        case RUN_ANIM:
           ComputeNextFrame(me);
           AddTimeOut(me->data.anim.frame_interval, 
						((void *)next_frame), data);

           if (me->data.anim.forward 
		&& (me->data.anim.frame_count >= me->data.anim.num_frames))
           {
              me->data.anim.enable_anim = FALSE;

              printf("anim done\n");
           }

           if (!me->data.anim.forward && (me->data.anim.frame_count == 0))
           {
              me->data.anim.enable_anim = FALSE;

              printf("anim done\n");
           }
           break;

        case LOOP_ANIM:
           ComputeNextFrame(me);
           AddTimeOut(me->data.anim.frame_interval, 
						((void *)next_frame), data);

           if (me->data.anim.frame_count >= me->data.anim.num_frames)
           {

              printf("starting anim again...\n");
              
              InitDatabase(me);
              GenerateParticleSystem(me, 0);
              SetupAnimToRun(me);
              UpdateDisplay(me);
              
              me->data.anim.mode = LOOP_ANIM;
              me->data.anim.enable_anim = TRUE;
              me->data.anim.forward = TRUE;
              me->data.anim.frame_count = 0;

              AddTimeOut(me->data.anim.frame_interval, ((void *)next_frame), data);
           }
           break;

        case PING_ANIM:
           ComputeNextFrame(me);
           AddTimeOut(me->data.anim.frame_interval, 
						((void *)next_frame), data);

           if (me->data.anim.forward 
		&& (me->data.anim.frame_count >= me->data.anim.num_frames))
           {
              me->data.anim.forward = FALSE;
           }

           if (!me->data.anim.forward && (me->data.anim.frame_count == 0))
           {
              me->data.anim.forward = TRUE;
           }
           break;

        case STEP_ANIM:
           ComputeNextFrame(me);
           me->data.anim.enable_anim = FALSE;
           break;

        default:
           me->data.anim.enable_anim = FALSE;
           break;
     }
  }
}
Exemplo n.º 21
0
/*! \class TorcSQLiteDB
 *  \brief SQLite implementation of TorcDB
 *
 * All Sql specific code resides in TorcDB. TorcSQLiteDB applies SQLite specifics
 * when creating the database and upon first use after startup.
 *
 * \todo Check the exclusive lock handling. It's unclear whether this will lock out other threads.
 *
 * \sa TorcDB
*/
TorcSQLiteDB::TorcSQLiteDB(const QString &DatabaseName)
  : TorcDB(DatabaseName, "QSQLITE")
{
    InitDatabase();
}