Example #1
0
File: WServer.C Project: LifeGo/wt
bool WServer::start()
{
  if (isRunning()) {
    log("error") << "WServer::start() error: server already started!";
    return false;
  }

  impl_->running_ = true;
  webController_ = new Wt::WebController(*this, "", false);

  try {
    isapi::IsapiStream isapiStream(isapi::IsapiServer::instance());

    WebMain requestServer(this, &isapiStream);
    webMain = &requestServer;

    requestServer.run();

    webMain = 0;

  } catch (std::exception& e) {
    log("fatal") << "ISAPI server: caught unhandled exception: " << e.what();

    throw;
  } catch (...) {
    log("fatal") << "ISAPI server: caught unknown, unhandled exception.";
    throw;
  }
  return true;
}
Example #2
0
void LongPoll::setRunning(bool set)
{
    Q_D(LongPoll);
    if (set != d->isRunning) {
        d->isRunning = set;
        if (set)
            requestServer();
    }
}
Example #3
0
// OPTION 1
void apiAddStudent (char * name, char * average) {
	Student *student = malloc(sizeof(Student));
	strcpy(student->name, name);
	strcpy(student->average, average);
	Connection *connection = malloc(sizeof(Connection));
	requestServer(connection, ADD_STUDENT, sizeof((*student)), student);
	int answer = getResponse(connection);
	printf("%s\n", server_msg[answer]);
}
Example #4
0
void VLongPollClient::onConnectionStateChanged(VConnectionState state)
{
	switch (state) {
	case Connected:
		requestServer();
		break;
	case Disconnected:
		break;
	default:
		break;
	}
}
Example #5
0
void VLongPollClient::onServerDataReceived()
{
	QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
	QByteArray rawData = reply->readAll();
	debug() << Q_FUNC_INFO << rawData;
	QVariantMap data = Json::parse(rawData).toMap().value("response").toMap();
	if (data.isEmpty() || reply->error() != QNetworkReply::NoError) {
		if (m_connection->connectionState() == Connected)
			QTimer::singleShot(1000, this, SLOT(requestServer()));
		return;
	}
	QString url("http://%1?act=a_check&key=%2&wait=25");
	m_url = url.arg(data.value("server").toString(), data.value("key").toString());
	
	if (m_connection->connectionState() == Connected)
		requestData(data.value("ts").toString());
}
Example #6
0
void LongPollPrivate::_q_request_server_finished(const QVariant &response)
{
    Q_Q(LongPoll);

    QVariantMap data = response.toMap();
    if (data.isEmpty()) {
        QTimer::singleShot(pollInterval, q, SLOT(requestServer()));
        return;
    }

    QString url("http://%1?act=a_check&key=%2&wait=%3&mode=%4");
    dataUrl = url.arg(data.value("server").toString(),
                      data.value("key").toString(),
                      QString::number(waitInterval),
                      QString::number(mode));

    q->requestData(data.value("ts").toByteArray());
}
Example #7
0
void apiReadStudents() {
	Connection *connection = malloc(sizeof(Connection));
	requestServer(connection, READ_STUDENTS, 0, NULL);
}
Example #8
0
void apiCreateTable() {
	Connection *connection = malloc(sizeof(Connection));
	requestServer(connection, CREATE_TABLE , 0, NULL);
}
Example #9
0
void apiDropTable() {
	Connection *connection = malloc(sizeof(Connection));
	requestServer(connection, DROP_TABLE , 0, NULL);
}
Example #10
0
// OPTION 3
void apiDeleteStudent (char * name) {
	Connection *connection = malloc(sizeof(Connection));
	requestServer(connection, DELETE_STUDENT, sizeof(name), name);
	getResponse(connection);
}
Example #11
0
void VLongPollClient::onDataReceived()
{
	QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
	reply->deleteLater();
	QByteArray rawData = reply->readAll();
	debug() << Q_FUNC_INFO << rawData;
	QVariantMap data = Json::parse(rawData).toMap();
	if (data.contains("failed")) {
		requestServer();
		return;
	} else if (data.isEmpty() || reply->error() != QNetworkReply::NoError) {
		if (m_connection->connectionState() == Connected)
			QTimer::singleShot(1000, this, SLOT(requestServer()));
		return;
	}
	QVariantList updates = data.value("updates").toList();
	for (int i = 0; i < updates.size(); i++) {
		QVariantList update = updates.at(i).toList();
		int updateType = update.value(0, -1).toInt();
		switch (updateType) {
		case MessageAdded: {
				MessageFlags flags(update.value(2).toInt());
				if (flags & MessageOutbox)
					continue;
				QString id = update.value(3).toString();
				QString messageId = update.value(1).toString();
				QString subject = update.value(5).toString();
				QString text = update.value(6).toString();

				VContact *contact = m_connection->account()->getContact(id, true);
				qutim_sdk_0_3::Message message;
				message.setChatUnit(contact);
				message.setProperty("subject", subject);
				message.setText(unescape(text));
				message.setProperty("mid",messageId);
				//message.setProperty("html",text);
				message.setTime(QDateTime::currentDateTime());
				message.setIncoming(true);
				ChatSession *s = ChatLayer::get(contact, true);
				s->appendMessage(message);
				connect(s,SIGNAL(unreadChanged(qutim_sdk_0_3::MessageList)),SLOT(onUnreadChanged(qutim_sdk_0_3::MessageList)));
				m_unread_mess[s].append(message);
				contact->setChatState(ChatStateActive);
				break;
			}
		case UserOnline:
		case UserOffline: {
				// WTF? Why VKontakte sends minus as first char of id?
				QString id = update.value(1).toString().mid(1);
				VContact *contact = m_connection->account()->getContact(id, false);
				if (contact)
					contact->setOnline(updateType == UserOnline);
				break;
			}
		}
	}

	
	if (m_connection->connectionState() == Connected)
		requestData(data.value("ts").toString());
}