Exemple #1
0
DAL::DataSet* SQLite::ExecuteQuery(const char* SqlStatement)
{
	SQLite::SQLiteDataSet* returnValue = new SQLite::SQLiteDataSet();

	Logger::GetInstance().Debug("SQLite::ExecuteQuery", SqlStatement);

	try
	{
		char* error = NULL;
		if (sqlite3_exec(this->database, SqlStatement, SQLite::ExecuteCallback, returnValue, &error) != SQLITE_OK)
		{
			std::string errorMsg = "SQLite::ExecuteQuery FATAL: Could not execute " + std::string(SqlStatement) + " : " + std::string(error);

			sqlite3_free(error);

			throw WarningException("SQLite::ExecuteQuery", errorMsg, HERE);
		}
	}
	catch (WarningException& e)
	{
		throw WarningException(e, HERE);
	}
	catch (std::exception &e)
	{
		throw FatalException("DAL::ExecuteQuery", e.what(), HERE);
	}
	catch (...)
	{
		throw FatalException("DAL::ExecuteQuery", "Unspecified exception while executing an sql query.", HERE);
	}

	return returnValue;
}
Exemple #2
0
//-----------------------------------------------------------------------------
// Square()
// Constructor
// ClusterType type - the type to be used to define the cluster
// Square *squares[9] - An array of nine squares to define the cluster
Cluster::Cluster(ClusterType type, Square *squares[9])
{
    int k = 0;
    for (k = 0; k < 9; k++)
        references[k] = 0; //tracks what numbers are used
    //------------------------------------------------
    // Check to see if **squares are null
    //------------------------------------------------
    if (!squares)
    {
        throw FatalException("Cluster::Cluster() null pointer in parameter");
    }

    cluster_type = type;
    //------------------------------------------------
    // Initialize the squares using the provided array
    //------------------------------------------------
    for (k = 0; k < 9; k++)
    {
        if (!squares[k])
        {
           throw FatalException("Cluster::Cluster() null pointer in parameter");
        }
        cluster_group[k] = squares[k];

    }
    for (k = 0; k < 9; k++)
        cluster_group[k]->addCluster(this);
    referenceCount++;
}
void ZipFile::Work_AfterReadFile(uv_work_t* req) {
    HandleScope scope;

    closure_t *closure = static_cast<closure_t *>(req->data);

    TryCatch try_catch;

    if (closure->error) {
        Local<Value> argv[1] = { Exception::Error(String::New(closure->error_name.c_str())) };
        closure->cb->Call(Context::GetCurrent()->Global(), 1, argv);
    } else {
        node::Buffer *retbuf = Buffer::New(reinterpret_cast<char *>(&closure->data[0]), closure->data.size());
        Local<Value> argv[2] = { Local<Value>::New(Null()), Local<Value>::New(retbuf->handle_) };
        closure->cb->Call(Context::GetCurrent()->Global(), 2, argv);
    }

    if (try_catch.HasCaught()) {
        FatalException(try_catch);
    }

    closure->zf->Unref();
    uv_unref(uv_default_loop());
    closure->cb.Dispose();
    delete closure;
}
Exemple #4
0
/**
 * @details This is set by `FromFileAsync` to run after `FromFileWork` has
 * finished.  It is passed the response generated by the latter and runs in the
 * same thread as the former. It creates a `Map` instance and returns it
 * to the caller via the callback they originally specified.
 *
 * @param req The asynchronous libuv request.
 */
void Map::FromFileAfter(uv_work_t *req) {
  HandleScope scope;

  MapfileBaton *baton = static_cast<MapfileBaton*>(req->data);
  Handle<Value> argv[2];

  if (baton->error) {
    argv[0] = baton->error->toV8Error();
    argv[1] = Undefined();
    delete baton->error;        // we've finished with it
  } else {
    Local<Value> mapObj = External::New(baton->map);
    Persistent<Object> map = Persistent<Object>(map_template->GetFunction()->NewInstance(1, &mapObj));

    argv[0] = Undefined();
    argv[1] = scope.Close(map);
  }

  // pass the results to the user specified callback function
  TryCatch try_catch;
  baton->callback->Call(Context::GetCurrent()->Global(), 2, argv);
  if (try_catch.HasCaught()) {
    FatalException(try_catch);
  }

  // clean up
  baton->callback.Dispose();
  delete baton;
  return;
}
Exemple #5
0
void Image::EIO_AfterComposite(uv_work_t* req)
{
    HandleScope scope;

    composite_image_baton_t *closure = static_cast<composite_image_baton_t *>(req->data);

    TryCatch try_catch;

    if (closure->error) {
        Local<Value> argv[1] = { Exception::Error(String::New(closure->error_name.c_str())) };
        closure->cb->Call(Context::GetCurrent()->Global(), 1, argv);
    } else {
        Local<Value> argv[2] = { Local<Value>::New(Null()), Local<Value>::New(closure->im1->handle_) };
        closure->cb->Call(Context::GetCurrent()->Global(), 2, argv);
    }

    if (try_catch.HasCaught()) {
        FatalException(try_catch);
    }

    closure->im1->Unref();
    closure->im2->Unref();
    closure->cb.Dispose();
    delete closure;
}
void MSMap::DrawMapAfter(uv_work_t *req) {
  HandleScope scope;
  // drawmap_baton *drawmap_req =(drawmap_baton *)req->data;
  drawmap_baton *baton = static_cast<drawmap_baton *>(req->data);
  baton->map->Unref();

  TryCatch try_catch;

  Local<Value> argv[2];
  if (baton->data != NULL) {
    Buffer * buffer = Buffer::New(baton->data, baton->size, FreeImageBuffer, NULL);

    argv[0] = Local<Value>::New(Null());
    argv[1] = Local<Value>::New(buffer->handle_);
  } else {
    Local<Value> _arg_ = External::New(baton->error);

    // argv[0] = Local<Value>::New(ErrorObj::constructor_template->GetFunction()->NewInstance(1, &_arg_));
    errorObj * err = msGetErrorObj();
    argv[0] = Local<Value>::New(MSError::New(err));
    argv[1] = Local<Value>::New(Null());
  }


  baton->cb->Call(Context::GetCurrent()->Global(), 2, argv);

  if (try_catch.HasCaught()) {
    FatalException(try_catch);
  }

  baton->cb.Dispose();
  delete baton;
  return;
}
Exemple #7
0
int Zipper::EIO_AfterAddFile(eio_req *req)
{
    HandleScope scope;

    closure_t *closure = static_cast<closure_t *>(req->data);
    ev_unref(EV_DEFAULT_UC);

    TryCatch try_catch;
  
    if (closure->error) {
        Local<Value> argv[1] = { Exception::Error(String::New(closure->error_name.c_str())) };
        closure->cb->Call(Context::GetCurrent()->Global(), 1, argv);
    } else {
        Local<Value> argv[1] = { Local<Value>::New(Null()) };
        closure->cb->Call(Context::GetCurrent()->Global(), 1, argv);
    }

    if (try_catch.HasCaught()) {
      FatalException(try_catch);
      //try_catch.ReThrow();
    }
    
    closure->zf->Unref();
    closure->cb.Dispose();
    delete closure;
    return 0;
}
void ImageView::EIO_AfterEncode(uv_work_t* req)
{
    HandleScope scope;

    encode_image_baton_t *closure = static_cast<encode_image_baton_t *>(req->data);

    TryCatch try_catch;

    if (closure->error) {
        Local<Value> argv[1] = { Exception::Error(String::New(closure->error_name.c_str())) };
        closure->cb->Call(Context::GetCurrent()->Global(), 1, argv);
    } else {
        #if NODE_VERSION_AT_LEAST(0,3,0)
        node::Buffer *retbuf = Buffer::New((char*)closure->result.data(),closure->result.size());
        #else
        node::Buffer *retbuf = Buffer::New(closure->result.size());
        memcpy(retbuf->data(), closure->result.data(), closure->result.size());
        #endif
        Local<Value> argv[2] = { Local<Value>::New(Null()), Local<Value>::New(retbuf->handle_) };
        closure->cb->Call(Context::GetCurrent()->Global(), 2, argv);
    }

    if (try_catch.HasCaught()) {
      FatalException(try_catch);
    }

    //uv_unref(uv_default_loop());
    closure->im->Unref();
    closure->cb.Dispose();
    delete closure;
}
Exemple #9
0
void SQLite::Open(std::string Location)
{
	if (sqlite3_open(Location.c_str(), &this->database))
	{
		std::string errorMsg = "Database::Database FATAL: Could not create database: " + std::string(sqlite3_errmsg(this->database));
		throw FatalException("SQLite::Open", errorMsg, HERE);
	}
	this->ExecuteNonQuery("PRAGMA foreign_keys = ON");
}
void Grid::EIO_AfterEncode(uv_work_t* req)
{
    HandleScope scope;

    encode_grid_baton_t *closure = static_cast<encode_grid_baton_t *>(req->data);

    TryCatch try_catch;

    if (closure->error) {
        Local<Value> argv[1] = { Exception::Error(String::New(closure->error_name.c_str())) };
        closure->cb->Call(Context::GetCurrent()->Global(), 1, argv);
    } else {

        // convert key order to proper javascript array
        Local<Array> keys_a = Array::New(closure->key_order.size());
        std::vector<std::string>::iterator it;
        unsigned int i;
        for (it = closure->key_order.begin(), i = 0; it < closure->key_order.end(); ++it, ++i)
        {
            keys_a->Set(i, String::New((*it).c_str()));
        }

        mapnik::grid const& grid_type = *closure->g->get();
        // gather feature data
        Local<Object> feature_data = Object::New();
        if (closure->add_features) {
            node_mapnik::write_features<mapnik::grid>(grid_type,
                                                      feature_data,
                                                      closure->key_order);
        }

        // Create the return hash.
        Local<Object> json = Object::New();
        Local<Array> grid_array = Array::New(closure->lines.size());
        unsigned array_size = static_cast<unsigned int>(grid_type.width()/closure->resolution);
        for (unsigned j=0;j<closure->lines.size();++j)
        {
            grid_array->Set(j,String::New(&closure->lines[j],array_size));
        }
        json->Set(String::NewSymbol("grid"), grid_array);
        json->Set(String::NewSymbol("keys"), keys_a);
        json->Set(String::NewSymbol("data"), feature_data);

        Local<Value> argv[2] = { Local<Value>::New(Null()), Local<Value>::New(json) };
        closure->cb->Call(Context::GetCurrent()->Global(), 2, argv);
    }

    if (try_catch.HasCaught()) {
        FatalException(try_catch);
    }

    uv_unref(uv_default_loop());
    closure->g->Unref();
    closure->cb.Dispose();
    delete closure;
}
void PlayerComponent::setQtQuickWindow(QQuickWindow* window)
{
  PlayerQuickItem* video = window->findChild<PlayerQuickItem*>("video");
  if (!video)
    throw FatalException(tr("Failed to load video element."));

  mpv_set_option_string(m_mpv, "vo", "opengl-cb");

  video->initMpv(this);
}
Exemple #12
0
//-----------------------------------------------------------------------------
// getSquare()
// returns the square at the specified index
Square* Cluster::getSquare(int index)
{
	if(index<0 || index>8)
	{
		string s = "Cluster::getSquare() index out of bounds ";
		s+=index;
		throw FatalException(s);
	}
	return cluster_group[index];
}
Exemple #13
0
//-----------------------------------------------------------------------------
// isReferenced()
// returns true if the cluster references the specified value
bool Cluster::isReferenced(int n)
{
	// I use a fatal exception because
	// this method should never be called
	// outside the scope of Marking a value
	if(n<1 || n>9)
		throw FatalException("Cluster::isReferenced() illegal reference");
	if(references[n-1]>0)
		return true;
	return false;
}
// Initialise decryption using the specified object
CK_RV C_DecryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hObject)
{
	try
	{
		return SoftHSM::i()->C_DecryptInit(hSession, pMechanism, hObject);
	}
	catch (...)
	{
		FatalException();
	}

	return CKR_FUNCTION_FAILED;
}
// Feed data to the running decryption operation in a session
CK_RV C_DecryptUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pEncryptedData, CK_ULONG ulEncryptedDataLen, CK_BYTE_PTR pData, CK_ULONG_PTR pDataLen)
{
	try
	{
		return SoftHSM::i()->C_DecryptUpdate(hSession, pEncryptedData, ulEncryptedDataLen, pData, pDataLen);
	}
	catch (...)
	{
		FatalException();
	}

	return CKR_FUNCTION_FAILED;
}
// Initialise digesting using the specified mechanism in the specified session
CK_RV C_DigestInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism)
{
	try
	{
		return SoftHSM::i()->C_DigestInit(hSession, pMechanism);
	}
	catch (...)
	{
		FatalException();
	}

	return CKR_FUNCTION_FAILED;
}
// Update a running digest operation by digesting a secret key with the specified handle
CK_RV C_DigestKey(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject)
{
	try
	{
		return SoftHSM::i()->C_DigestKey(hSession, hObject);
	}
	catch (...)
	{
		FatalException();
	}

	return CKR_FUNCTION_FAILED;
}
// Finalise the digest operation in the specified session and return the digest
CK_RV C_DigestFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pDigest, CK_ULONG_PTR pulDigestLen)
{
	try
	{
		return SoftHSM::i()->C_DigestFinal(hSession, pDigest, pulDigestLen);
	}
	catch (...)
	{
		FatalException();
	}

	return CKR_FUNCTION_FAILED;
}
// Initialise a verification operation the allows recovery of the signed data from the signature
CK_RV C_VerifyRecoverInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey)
{
	try
	{
		return SoftHSM::i()->C_VerifyRecoverInit(hSession, pMechanism, hKey);
	}
	catch (...)
	{
		FatalException();
	}

	return CKR_FUNCTION_FAILED;
}
// Initialise object search in the specified session using the specified attribute template as search parameters
CK_RV C_FindObjectsInit(CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount)
{
	try
	{
		return SoftHSM::i()->C_FindObjectsInit(hSession, pTemplate, ulCount);
	}
	catch (...)
	{
		FatalException();
	}

	return CKR_FUNCTION_FAILED;
}
void PlayerQuickItem::initMpv(PlayerComponent* player)
{
  m_mpv = player->getMpvHandle();

  m_mpvGL = (mpv_opengl_cb_context *)mpv_get_sub_api(m_mpv, MPV_SUB_API_OPENGL_CB);
  if (!m_mpvGL)
    throw FatalException(tr("OpenGL not enabled in libmpv."));

  mpv_opengl_cb_set_update_callback(m_mpvGL, on_update, (void *)this);

  connect(player, &PlayerComponent::windowVisible, this, &QQuickItem::setVisible);
  window()->update();
}
Exemple #22
0
SndThr::SndThr(EmulApp *parent)
    : QThread(parent), pleaseStop(false), trigDone(false), sndDone(false), app(parent), sndShm(0)
{
        RTOS::ShmStatus shmStatus;
        // do sound shm stuff..
        sndShm = reinterpret_cast<SndShm *>(RTOS::shmAttach(SND_SHM_NAME, SND_SHM_SIZE, &shmStatus, true));
        if (!sndShm) {
            throw FatalException(QString("Cannot create shm to ") + SND_SHM_NAME + " reason was: " + RTOS::statusString(shmStatus));
        }
        memset(sndShm, 0, SND_SHM_SIZE);
        sndShm->fifo_in[0] = sndShm->fifo_out[0] = -1;
        sndShm->magic = SND_SHM_MAGIC;
        *const_cast<unsigned *>(&sndShm->num_cards) = 1;
        unsigned minor;
        if (RTOS::createFifo(minor, SND_FIFO_SZ) == RTOS::INVALID_FIFO) 
            throw FatalException(QString("Cannot create out fifo for SndShm"));
        sndShm->fifo_out[0] = minor;
        if (RTOS::createFifo(minor, SND_FIFO_SZ) == RTOS::INVALID_FIFO) 
            throw FatalException(QString("Cannot create in fifo for SndShm"));
        sndShm->fifo_in[0] = minor;
        Debug() << "Sound Shm FIFOs -  In: " << sndShm->fifo_in[0] << "  Out: " << sndShm->fifo_out[0];
}
// Change or set the value of the specified attributes on the specified object
CK_RV C_SetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount)
{
	try
	{
		return SoftHSM::i()->C_SetAttributeValue(hSession, hObject, pTemplate, ulCount);
	}
	catch (...)
	{
		FatalException();
	}

	return CKR_FUNCTION_FAILED;
}
// Update a running multi-part decryption and verification operation
CK_RV C_DecryptVerifyUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pEncryptedPart, CK_ULONG ulEncryptedPartLen, CK_BYTE_PTR pPart, CK_ULONG_PTR pulPartLen)
{
	try
	{
		return SoftHSM::i()->C_DecryptVerifyUpdate(hSession, pEncryptedPart, ulEncryptedPartLen, pPart, pulPartLen);
	}
	catch (...)
	{
		FatalException();
	}

	return CKR_FUNCTION_FAILED;
}
// Perform a single part verification operation and recover the signed data
CK_RV C_VerifyRecover(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature, CK_ULONG ulSignatureLen, CK_BYTE_PTR pData, CK_ULONG_PTR pulDataLen)
{
	try
	{
		return SoftHSM::i()->C_VerifyRecover(hSession, pSignature, ulSignatureLen, pData, pulDataLen);
	}
	catch (...)
	{
		FatalException();
	}

	return CKR_FUNCTION_FAILED;
}
// Finish searching for objects
CK_RV C_FindObjectsFinal(CK_SESSION_HANDLE hSession)
{
	try
	{
		return SoftHSM::i()->C_FindObjectsFinal(hSession);
	}
	catch (...)
	{
		FatalException();
	}

	return CKR_FUNCTION_FAILED;
}
// Continue the search for objects in the specified session
CK_RV C_FindObjects(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE_PTR phObject, CK_ULONG ulMaxObjectCount, CK_ULONG_PTR pulObjectCount)
{
	try
	{
		return SoftHSM::i()->C_FindObjects(hSession, phObject, ulMaxObjectCount, pulObjectCount);
	}
	catch (...)
	{
		FatalException();
	}

	return CKR_FUNCTION_FAILED;
}
// Update a running signing operation with additional data
CK_RV C_SignUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, CK_ULONG ulPartLen)
{
	try
	{
		return SoftHSM::i()->C_SignUpdate(hSession, pPart, ulPartLen);
	}
	catch (...)
	{
		FatalException();
	}

	return CKR_FUNCTION_FAILED;
}
// Generate a secret key using the specified mechanism
CK_RV C_GenerateKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, CK_OBJECT_HANDLE_PTR phKey)
{
	try
	{
		return SoftHSM::i()->C_GenerateKey(hSession, pMechanism, pTemplate, ulCount, phKey);
	}
	catch (...)
	{
		FatalException();
	}

	return CKR_FUNCTION_FAILED;
}
// Finalise a running signing operation and return the signature
CK_RV C_SignFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen)
{
	try
	{
		return SoftHSM::i()->C_SignFinal(hSession, pSignature, pulSignatureLen);
	}
	catch (...)
	{
		FatalException();
	}

	return CKR_FUNCTION_FAILED;
}