Exemple #1
0
// --------------------------------------------------
void WSAClientSocket::write(const void *p, int l)
{
	while (l)
	{
		int r = send(sockNum, (char *)p, l, 0);
		if (r == SOCKET_ERROR)
		{
			checkTimeout(false,true);	
		}
		else if (r == 0)
		{
			throw SockException("Closed on write");
		}
		else
		if (r > 0)
		{
			stats.add(Stats::BYTESOUT,r);
			if (host.localIP())
				stats.add(Stats::LOCALBYTESOUT,r);

			updateTotals(0,r);
			l -= r;
			p = (char *)p+r;
		}
	}
}
Exemple #2
0
// --------------------------------------------------
int WSAClientSocket::readUpto(void *p, int l)
{
	int bytesRead=0;
	while (l)
	{
		int r = recv(sockNum, (char *)p, l, 0);
		if (r == SOCKET_ERROR)
		{
			// non-blocking sockets always fall through to here
			checkTimeout(true,false);

		}else if (r == 0)
		{
			break;
		}else
		{
			stats.add(Stats::BYTESIN,r);
			if (host.localIP())
				stats.add(Stats::LOCALBYTESIN,r);
			updateTotals(r,0);
			bytesRead += r;
			l -= r;
			p = (char *)p+r;
		}
	}
	return bytesRead;
}
Exemple #3
0
// -------------------------------------
void FileStream::write(const void *ptr, int len)
{
	if (!file)
		return;
    fwrite(ptr,1,len,file);
	updateTotals(0, len);

}
Exemple #4
0
bool SessionModel::add(const Session& session)
{
	if (!session.isValid()) {
		return false;
	}

	// Find session position
	int pos = 0;
	for (pos = m_data.count(); pos > 0; --pos) {
		const Session& current = m_data.at(pos - 1);
		if (session.date() > current.date() || (session.date() == current.date() && session.stop() > current.stop())) {
			break;
		}
	}
	pos = std::max(pos, 0);

	// Prevent intersecting sessions
	if (pos > 0) {
		Session current = m_data.at(pos - 1);
		if (QDateTime(session.date(), session.start()) < QDateTime(current.date(), current.stop())) {
			return false;
		}
	}
	if (pos < m_data.count()) {
		Session current = m_data.at(pos);
		if (QDateTime(session.date(), session.stop()) > QDateTime(current.date(), current.start())) {
			return false;
		}
	}

	// Prevent adding to billed
	if (isBilled(pos)) {
		return false;
	}

	// Insert session
	if (!m_loaded) {
		m_data.insert(pos, session);
		return true;
	}
	beginInsertRows(QModelIndex(), pos, pos);
	m_data.insert(pos, session);
	endInsertRows();

	// Set billed status
	if (session.isBilled()) {
		setBilled(pos, true);
	}

	// Increase totals for sessions
	updateTotals();

	return true;
}
Exemple #5
0
// -------------------------------------
int FileStream::read(void *ptr, int len)
{
	if (!file)
		return 0;
	if (feof(file))
    	throw StreamException("End of file");

	int r = (int)fread(ptr,1,len,file);

	updateTotals(r, 0);
    return r;
}
Exemple #6
0
void SessionModel::endLoad()
{
	m_loaded = true;

	// Store billed status
	for (int pos = 0, count = m_data.count(); pos < count; ++pos) {
		const Session& session = m_data.at(pos);
		if (session.isBilled()) {
			m_billed.append(pos);
		}
	}

	// Find totals for sessions
	updateTotals();
}
Exemple #7
0
void SessionModel::setBilled(int pos, bool billed)
{
	Q_ASSERT(pos < m_data.count());

	if (!billed) {
		m_billed.removeAll(pos);
	} else {
		Q_ASSERT(!m_billed.contains(pos));
		m_billed.append(pos);
		qSort(m_billed);
	}
	m_data[pos].setBilled(billed);

	updateTotals();
}
Exemple #8
0
bool SessionModel::remove(int pos)
{
	if (pos >= m_data.count() || isBilled(pos)) {
		return false;
	}

	// Remove session
	beginRemoveRows(QModelIndex(), pos, pos);
	m_data.removeAt(pos);
	endRemoveRows();

	// Increase totals for sessions
	updateTotals();

	return true;
}
Exemple #9
0
// --------------------------------------------------
int UClientSocket::read(void *p, int l)
{
	int bytesRead=0;

	while (l)
	{
		if (rbDataSize >= l) {
			memcpy(p, &apReadBuf[rbPos], l);
			rbPos += l;
			rbDataSize -= l;
			return l;
		} else if (rbDataSize > 0) {
			memcpy(p, &apReadBuf[rbPos], rbDataSize);
			p = (char *) p + rbDataSize;
			l -= rbDataSize;

			bytesRead += rbDataSize;
		}

		rbPos = 0;
		rbDataSize = 0;
		//int r = recv(sockNum, (char *)p, l, 0);
		int r = recv(sockNum, apReadBuf, RBSIZE, 0);
		if (r == SOCKET_ERROR)
		{
			// non-blocking sockets always fall through to here
			checkTimeout(true,false);

		}else if (r == 0)
		{
			throw SockException("Closed on read");
		}else
		{
			stats.add(Stats::BYTESIN,r);
			if (host.localIP())
				stats.add(Stats::LOCALBYTESIN,r);
			updateTotals(r,0);
			//bytesRead += r;
			//l -= r;
			//p = (char *)p+r;

			rbDataSize += r;
		}
	}

	return bytesRead;
}
//-----------------------------------------------------------------------------
void
QGCCacheWorker::_updateTotals()
{
    QSqlQuery query(*_db);
    QString s;
    s = QString("SELECT COUNT(size), SUM(size) FROM Tiles");
    if(query.exec(s)) {
        if(query.next()) {
            _totalCount = query.value(0).toUInt();
            _totalSize  = query.value(1).toULongLong();
        }
    }
    s = QString("SELECT COUNT(size), SUM(size) FROM Tiles A INNER JOIN SetTiles B on A.tileID = B.tileID WHERE B.setID = %1").arg(_getDefaultTileSet());
    if(query.exec(s)) {
        if(query.next()) {
            _defaultCount = query.value(0).toUInt();
            _defaultSize  = query.value(1).toULongLong();
        }
    }
    emit updateTotals(_totalCount, _totalSize, _defaultCount, _defaultSize);
    _lastUpdate = time(0);
}
Exemple #11
0
// --------------------------------------------------
void UClientSocket::write(const void *p, int l)
{
	while (l)
	{
		int r = send(sockNum, (char *)p, l, MSG_DONTWAIT|MSG_NOSIGNAL);
		if (r == SOCKET_ERROR)
		{
			// non-blocking sockets always fall through to here
			checkTimeout(false,true);
		}else if (r == 0)
		{
			throw SockException("Closed on write");
		}else
		{
			stats.add(Stats::BYTESOUT,r);
			if (host.localIP())
				stats.add(Stats::LOCALBYTESOUT,r);
			updateTotals(0,r);
			l -= r;
			p = (char *)p+r;
		}
	}
}
//-----------------------------------------------------------------------------
void
QGCCacheWorker::_updateTotals()
{
    QSqlQuery query(*_db);
    QString s;
    s = QString("SELECT COUNT(size), SUM(size) FROM Tiles");
    qCDebug(QGCTileCacheLog) << "_updateTotals(): " << s;
    if(query.exec(s)) {
        if(query.next()) {
            _totalCount = query.value(0).toUInt();
            _totalSize  = query.value(1).toULongLong();
        }
    }
    s = QString("SELECT COUNT(size), SUM(size) FROM Tiles WHERE tileID IN (SELECT A.tileID FROM SetTiles A join SetTiles B on A.tileID = B.tileID WHERE B.setID = %1 GROUP by A.tileID HAVING COUNT(A.tileID) = 1)").arg(_getDefaultTileSet());
    qCDebug(QGCTileCacheLog) << "_updateTotals(): " << s;
    if(query.exec(s)) {
        if(query.next()) {
            _defaultCount = query.value(0).toUInt();
            _defaultSize  = query.value(1).toULongLong();
        }
    }
    emit updateTotals(_totalCount, _totalSize, _defaultCount, _defaultSize);
    _lastUpdate = time(0);
}
Exemple #13
0
Session::Session(const QDate& date, const QTime& start, const QTime& stop, const QString& task, bool billed) {
	d = new SessionData(date, start, stop, task, billed);
	updateTotals();
}
Exemple #14
0
// --------------------------------------------------
void UClientSocket::bufferingWrite(const void *p, int l)
{
	if (bufList.isNull() && p != NULL){
		while(l){
			int r = send(sockNum, (char *)p, l, 0);
			if (r == SOCKET_ERROR){
				int err = errno;
				if (err == EWOULDBLOCK){
					bufList.add(p, l);
//					LOG_DEBUG("normal add");
					break;
				} else {
					char str[32];
					sprintf(str,"%d",err);
					throw SockException(str);
				}
			} else if (r == 0) {
				throw SockException("Closed on write");
			} else if (r > 0){
				stats.add(Stats::BYTESOUT,r);
				if (host.localIP())
					stats.add(Stats::LOCALBYTESOUT,r);

				updateTotals(0,r);
				l -= r;
				p = (char *)p+r;
			}
		}
	} else {
//		LOG_DEBUG("***************BufferingWrite");
		if (p)
			bufList.add(p,l);

		bool flg = true;

		while(flg){
			SocketBuffer *tmp;
			tmp = bufList.getTop();

			if (tmp){
//				LOG_DEBUG("tmp->pos = %d, tmp->len = %d, %d", tmp->pos, tmp->len, tmp);
				while(tmp->pos < tmp->len){
					int r = send(sockNum, (char*)(tmp->buf + tmp->pos), tmp->len - tmp->pos, 0);
//					LOG_DEBUG("send = %d", r);
					if (r == SOCKET_ERROR){
						int err = errno;
						if (err == EWOULDBLOCK){
							flg = false;
							break;
						} else {
							bufList.clear();
							char str[32];
							sprintf(str,"%d",err);
							throw SockException(str);
						}
					} else if (r == 0){
						bufList.clear();
						throw SockException("Closed on write");
					} else if (r > 0){
						stats.add(Stats::BYTESOUT,r);
						if (host.localIP())
							stats.add(Stats::LOCALBYTESOUT,r);

						updateTotals(0,r);

						tmp->pos += r;
						if (tmp->pos >= tmp->len){
//							LOG_DEBUG("deleteTop");
							bufList.deleteTop();
							break;
						}
					}
				}
			} else {
				flg = false;
			}
		}
//		LOG_DEBUG("bufferingWrite end");
	}
}
Exemple #15
0
void Cashbox::summCommited(const QString &text)
{
    bool ok;
    int operation_id;

    int row = view.currentIndex().row();
    if(row<0)
        ok=false;
    else
    {
        QSqlRecord record = model.record(row);
        operation_id = record.value(1).toInt(&ok);
    };

    if(!ok)
    {
        QMessageBox mb;
        mb.setText(_T("Ошибка: не выбрана операция"));
        mb.exec();
        return;
    }


     QSqlDatabase db = QSqlDatabase::database();
     db.transaction();


     QSqlQuery query;
     QSettings *settings = data->getSettings();

     query.prepare(settings->value("cashbox/queries/get_section_id").toString());
     query.bindValue(":operation_id", operation_id);
     if(!query.exec()){
         db.rollback();
         qDebug()<<posInFile<<query.lastError().text()<<endl<<query.lastQuery()<<endl<<query.boundValues();
         return;
     }

     query.next();
     int section_id = query.value(0).toInt();

     query.prepare(settings->value("cashbox/queries/get_new_document_id").toString());
     if(!query.exec()){
         db.rollback();
         qDebug()<<posInFile<<query.lastError().text()<<endl<<query.lastQuery()<<endl<<query.boundValues();
         return;
     }

     query.next();
     int doc_id = query.value(0).toInt();

     query.prepare(settings->value("cashbox/queries/save_document").toString());
     //:id,:data,:section_id,:operation_id,:store,:user
     query.bindValue(":id", doc_id);
     query.bindValue(":data", QDate::currentDate());
     query.bindValue(":time", QTime::currentTime());
     query.bindValue(":section_id", section_id);
     query.bindValue(":operation_id", operation_id);
     query.bindValue(":summ", text.toDouble());
     query.bindValue(":store", data->getVariables()->value("current_base_id"));
     query.bindValue(":user", data->getVariables()->value("user_id"));

     if(!query.exec()){
         db.rollback();
         qDebug()<<posInFile<<query.lastError().text()<<endl<<query.lastQuery()<<endl<<query.boundValues();
         return;
     }

     db.commit();

     updateTotals();

}
Exemple #16
0
bool Cashbox::init(Datapipe *data, const QString &params)
{
    this->data      = data;
    this->params = params;

    QMap<QString, QVariant>* vars = data->getVariables();

    int button_width  = vars->value(_S("standart_button_width")).toInt();
    int button_height = vars->value(_S("standart_button_height")).toInt();
//    int                    button_margin = vars->value(_S("standart_margins")).toInt();
    loglevel = vars->value(_S("loglevel")).toInt();

    QGridLayout *mainLayout = new QGridLayout();
    this->setLayout(mainLayout);

    QSettings *settings = data->getSettings();

   // model = new QSqlQueryModel(this);
    model.setQuery(settings->value("cashbox/queries/operations").toString());
    model.setHeaderData(0, Qt::Horizontal, "Операции");

    view.setModel(&model);
    view.hideColumn(1);

    QHeaderView *header = view.verticalHeader();
    header->setDefaultSectionSize(button_height);
    header->setVisible(false);

    header = view.horizontalHeader();
    header->setStretchLastSection(true);

    view.setFocusPolicy(Qt::NoFocus);

    mainLayout->addWidget(&view,0,1);
    view.setMaximumWidth(button_width * 2);

    QVBoxLayout *numpadLayout = new QVBoxLayout();
    Numpad *npad = new Numpad(data, this);

    numpadLayout->addWidget(npad);
    numpadLayout->addStretch(1);

    mainLayout->addLayout(numpadLayout,0,2);

    connect(npad, SIGNAL(inputCommited(QString)),
            this, SLOT(summCommited(QString)));

    QVBoxLayout *totalsLayout = new QVBoxLayout();

    totalsLayout->addWidget(&totals);
    totalsLayout->addStretch();
   // totals.setMaximumWidth(button_width * 3);
    //totals.setMinimumWidth(Height(button_width * 3);

    mainLayout->addLayout(totalsLayout,0,0);

    updateTotals();

    setFocusProxy(npad);

    return true;
}