BtsApiNotifier *BtsApi::getVersion() { QUrl apiUrl = getApiUrl(p, "get_version"); QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl)); BtsApiNotifier *notifier = new BtsApiNotifier(this); connect(reply, &QNetworkReply::finished, [this, reply, notifier]() { notifier->deleteLater(); if(checkForError(reply, notifier)) return; QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); if(checkForError(doc, notifier)) return; QJsonObject obj = doc.object(); emit getVersionResult(obj.value("version").toString()); emit notifier->getVersionResult(obj.value("version").toString()); }); return notifier; }
void * doFunction(char * fName, void ** argv) { void *handle; void * funcPtr; void * returnVal; FILE * filePtr = NULL; typedef void * (*funcType)(char *, void **); if (__ISWINDOWS__) { handle = dlopen("lib/libcallFunction.dll", RTLD_LAZY); } else { handle = dlopen("so/libcallFunction.so", RTLD_LAZY); }//END IF if (!handle) { checkForError(dlerror()); return NULL; }//END IF dlerror(); funcPtr = dlsym(handle, "callFunction"); if (checkForError(dlerror()) == 0) { funcType callFunction = (funcType) funcPtr; returnVal = (callFunction)(fName, argv); }//END IF dlclose(handle); handle = NULL; return returnVal; }
BtsApiNotifier *BtsApi::shutdown() { QUrl apiUrl = getApiUrl(p, "shutdown"); QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl)); BtsApiNotifier *notifier = new BtsApiNotifier(this); connect(reply, &QNetworkReply::finished, [this, reply, notifier]() { notifier->deleteLater(); if(checkForError(reply, notifier)) return; QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); if(checkForError(doc, notifier)) return; emit shutdownResult(); emit notifier->shutdownResult(); }); return notifier; }
BtsApiNotifier *BtsApi::addFolder(const QString &dir, bool selective_sync, const QString &secret) { QueryList ql; ql << QueryPair("dir", dir); if(!secret.isEmpty()) ql << QueryPair("secret", secret); if(selective_sync) ql << QueryPair("selective_sync", "1"); QUrl apiUrl = getApiUrl(p, "add_folder", ql); QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl)); BtsApiNotifier *notifier = new BtsApiNotifier(this); connect(reply, &QNetworkReply::finished, [this, reply, notifier]() { notifier->deleteLater(); if(checkForError(reply, notifier)) return; QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); if(checkForError(doc, notifier)) return; emit addFolderResult(); emit notifier->addFolderResult(); }); return notifier; }
BtsApiNotifier *BtsApi::getPreferences() { QUrl apiUrl = getApiUrl(p, "get_prefs"); QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl)); BtsApiNotifier *notifier = new BtsApiNotifier(this); connect(reply, &QNetworkReply::finished, [this, reply, notifier]() { notifier->deleteLater(); if(checkForError(reply, notifier)) return; QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); if(checkForError(doc, notifier)) return; QJsonObject obj = doc.object(); QVariantHash res; for(auto it = obj.constBegin(); it != obj.constEnd(); ++it) res[it.key()] = it.value().toVariant(); emit getPreferencesResult(res); emit notifier->getPreferencesResult(res); }); return notifier; }
BtsApiNotifier *BtsApi::getFolderPrefs(const QString &secret) { QueryList ql; ql << QueryPair("secret", secret); QUrl apiUrl = getApiUrl(p, "get_folder_prefs", ql); QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl)); BtsApiNotifier *notifier = new BtsApiNotifier(this); connect(reply, &QNetworkReply::finished, [this, reply, notifier, secret]() { notifier->deleteLater(); if(checkForError(reply, notifier)) return; QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); if(checkForError(doc, notifier)) return; QJsonObject obj = doc.object(); QVariantHash res; for(auto it = obj.constBegin(); it != obj.constEnd(); ++it) res[it.key()] = it.value().toVariant(); emit getFolderPrefsResult(res, secret); emit notifier->getFolderPrefsResult(res, secret); }); return notifier; }
BtsApiNotifier *BtsApi::removeFolder(const QString &secret) { QueryList ql; ql << QueryPair("secret", secret); QUrl apiUrl = getApiUrl(p, "remove_folder", ql); QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl)); BtsApiNotifier *notifier = new BtsApiNotifier(this); connect(reply, &QNetworkReply::finished, [this, reply, notifier, secret]() { notifier->deleteLater(); if(checkForError(reply, notifier)) return; QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); if(checkForError(doc, notifier)) return; emit removeFolderResult(secret); emit notifier->removeFolderResult(secret); }); return notifier; }
BtsApiNotifier *BtsApi::getSpeed() { QUrl apiUrl = getApiUrl(p, "get_speed"); QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl)); BtsApiNotifier *notifier = new BtsApiNotifier(this); connect(reply, &QNetworkReply::finished, [this, reply, notifier]() { notifier->deleteLater(); if(checkForError(reply, notifier)) return; QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); if(checkForError(doc, notifier)) return; QJsonObject obj = doc.object(); qint64 down = obj.value("download").toVariant().toLongLong(); qint64 up = obj.value("upload").toVariant().toLongLong(); emit getSpeedResult(down, up); emit notifier->getSpeedResult(down, up); }); return notifier; }
BtsApiNotifier *BtsApi::getFolders(const QString &secret) { QueryList ql; if(!secret.isEmpty()) ql << QueryPair("secret", secret); QUrl apiUrl = getApiUrl(p, "get_folders", ql); QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl)); BtsApiNotifier *notifier = new BtsApiNotifier(this); connect(reply, &QNetworkReply::finished, [this, reply, notifier, secret]() { notifier->deleteLater(); if(checkForError(reply, notifier)) return; QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); if(checkForError(doc, notifier)) return; QJsonArray arr = doc.array(); QVector<BtsGetFoldersResult> res; res.reserve(arr.size()); for(const QJsonValue &val: arr) { QJsonObject folderObj = val.toObject(); if(folderObj.isEmpty()) { emit error("Got an unexpected get_folders reply format"); return; } BtsGetFoldersResult resObj; resObj.dir = folderObj.value("dir").toString(); resObj.secret = folderObj.value("secret").toString(); resObj.size = folderObj.value("size").toVariant().toLongLong(); resObj.type = folderObj.value("type").toString(); resObj.files = folderObj.value("files").toVariant().toLongLong(); resObj.error = folderObj.value("error").toInt(); resObj.indexing = folderObj.value("indexing").toInt(); res << resObj; } emit getFoldersResult(res, secret); emit notifier->getFoldersResult(res, secret); }); return notifier; }
/** * Compliance Margin are the areas where output torque is 0. * Compliance Slope are the areas where output torque is reduced when they are getting close to Goal Position. * slope [1,254] * margin [0,254] */ void dynamixelApi_setCompliance(int actuator, char margin, char slope) { dxl_write_byte(dyna.actuators[actuator], P_CW_COMPLIANCE_MARGIN, margin); checkForError(actuator,9); dxl_write_byte(dyna.actuators[actuator], P_CCW_COMPLIANCE_MARGIN, margin); checkForError(actuator,10); dxl_write_byte(dyna.actuators[actuator], P_CW_COMPLIANCE_SLOPE, slope); checkForError(actuator,11); dxl_write_byte(dyna.actuators[actuator], P_CCW_COMPLIANCE_SLOPE, slope); checkForError(actuator,12); }
BtsApiNotifier *BtsApi::getFolderPeers(const QString &secret) { QueryList ql; ql << QueryPair("secret", secret); QUrl apiUrl = getApiUrl(p, "get_folder_peers", ql); QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl)); BtsApiNotifier *notifier = new BtsApiNotifier(this); connect(reply, &QNetworkReply::finished, [this, reply, notifier, secret]() { notifier->deleteLater(); if(checkForError(reply, notifier)) return; QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); if(checkForError(doc, notifier)) return; QJsonArray arr = doc.array(); QVector<BtsGetFolderPeersResult> res; res.reserve(arr.size()); for(const QJsonValue &val: arr) { QJsonObject peerObj = val.toObject(); if(peerObj.isEmpty()) { emit error("Got an unexpected get_folder_peers reply format"); return; } BtsGetFolderPeersResult resObj; resObj.id = peerObj.value("id").toString(); resObj.connection = peerObj.value("connection").toString(); resObj.name = peerObj.value("name").toString(); resObj.synced = peerObj.value("synced").toVariant().toLongLong(); resObj.download = peerObj.value("download").toVariant().toLongLong(); resObj.upload = peerObj.value("upload").toVariant().toLongLong(); res << resObj; } emit getFolderPeersResult(res, secret); emit notifier->getFolderPeersResult(res, secret); }); return notifier; }
BtsApiNotifier *BtsApi::getFiles(const QString &secret, const QString &path) { QueryList ql; ql << QueryPair("secret", secret); if(!path.isEmpty()) ql << QueryPair("path", path); QUrl apiUrl = getApiUrl(p, "get_files", ql); QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl)); BtsApiNotifier *notifier = new BtsApiNotifier(this); connect(reply, &QNetworkReply::finished, [this, reply, notifier, secret]() { notifier->deleteLater(); if(checkForError(reply, notifier)) return; QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); if(checkForError(doc, notifier)) return; QJsonArray arr = doc.array(); QVector<BtsGetFilesResult> res; res.reserve(arr.size()); for(const QJsonValue &val: arr) { QJsonObject fileObj = val.toObject(); if(fileObj.isEmpty()) { emit error("Got an unexpected get_files reply format"); return; } BtsGetFilesResult resObj; parseGetFilesResult(fileObj, resObj); res << resObj; } emit getFilesResult(res, secret); emit notifier->getFilesResult(res, secret); }); return notifier; }
int dynamixelApi_getSpeed(int actuator) { int temp = dxl_read_word( dyna.actuators[actuator], P_PRESENT_SPEED_L ); checkForError(actuator,15); int sign = (temp&&1<<10)?-1:1; int ratio = 0x03FF&&temp; return sign * ratio; }
void TwitterMicroBlog::slotFetchUserLists(KJob *job) { qCDebug(CHOQOK); if (!job) { qCWarning(CHOQOK) << "NULL Job returned"; return; } QString username = mFetchUsersListMap.take(job); Choqok::Account *theAccount = mJobsAccount.take(job); if (job->error()) { qCDebug(CHOQOK) << "Job Error:" << job->errorString(); Q_EMIT error(theAccount, Choqok::MicroBlog::CommunicationError, i18n("Fetching %1's lists failed. %2", username, job->errorString()), Critical); } else { KIO::StoredTransferJob *stj = qobject_cast<KIO::StoredTransferJob *> (job); QByteArray buffer = stj->data(); QList<Twitter::List> list = readUserListsFromJson(theAccount, buffer); if (list.isEmpty()) { qCDebug(CHOQOK) << buffer; QString errorMsg; errorMsg = checkForError(buffer); if (errorMsg.isEmpty()) { KMessageBox::information(choqokMainWindow, i18n("There is no list record for user %1", username)); } else { Q_EMIT error(theAccount, ServerError, errorMsg, Critical); } } else { Q_EMIT userLists(theAccount, username, list); } } }
int dynamixelApi_getLoad(int actuator) { int load = dxl_read_word( dyna.actuators[actuator], P_PRESENT_LOAD_L); checkForError(actuator,18); int sign = (load&&1<<10)?-1:1; int ratio = 0x03FF&&load; return sign * ratio; }
BtsApiNotifier *BtsApi::getSecrets(bool encryption, const QString &secret, const QUuid &uuid) { QueryList ql; if(!secret.isEmpty()) ql << QueryPair("secret", secret); if(encryption) ql << QueryPair("type", "encryption"); QUrl apiUrl = getApiUrl(p, "get_secrets", ql); QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl)); BtsApiNotifier *notifier = new BtsApiNotifier(this); connect(reply, &QNetworkReply::finished, [this, reply, notifier, uuid]() { notifier->deleteLater(); if(checkForError(reply, notifier)) return; QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); if(checkForError(doc, notifier)) return; QJsonObject obj = doc.object(); QString rw = obj.value("read_write").toString(); QString ro = obj.value("read_only").toString(); QString ec = obj.value("encryption").toString(); if(uuid.isNull()) { emit getSecretsResult(rw, ro, ec); emit notifier->getSecretsResult(rw, ro, ec); } else { emit getSecretsResultUuid(uuid, rw, ro, ec); emit notifier->getSecretsResultUuid(uuid, rw, ro, ec); } }); return notifier; }
int dynamixelApi_getPosition(int actuator) { long start = getLocalMsTime(); int presentPos = dxl_read_word( dyna.actuators[actuator], P_PRESENT_POSITION_L); long time = getLocalMsTime()-start; if(time>1) { // printf("time taken to comm = %i ms\n ",getLocalMsTime()-start); } checkForError(actuator,17); return presentPos; }
BtsApiNotifier *BtsApi::setFolderHosts(const QString &secret, const QStringList &hosts) { QueryList ql; ql << QueryPair("secret", secret) << QueryPair("hosts", hosts.join(',')); QUrl apiUrl = getApiUrl(p, "set_folder_hosts", ql); QString queryString = apiUrl.query(QUrl::FullyEncoded); QNetworkReply *reply = p->nam->get(QNetworkRequest(apiUrl)); BtsApiNotifier *notifier = new BtsApiNotifier(this); connect(reply, &QNetworkReply::finished, [this, reply, notifier, secret]() { notifier->deleteLater(); if(checkForError(reply, notifier)) return; QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); if(checkForError(doc, notifier)) return; QJsonObject obj = doc.object(); QJsonArray arr = obj.value("hosts").toArray(); QStringList res; for(const QJsonValue &val: arr) res << val.toString(); emit setFolderHostsResult(res, secret); emit notifier->setFolderHostsResult(res, secret); }); return notifier; }
bool g_init_world(World* d_world, World* h_world) { /* Initialize a world struct in device memory d_world : The world to initialize on the device h_world : The host world to use as a template returns true if an error occurred */ // Error checking bool error; // Soft clone world error = g_soft_clone_world(d_world, h_world); if (error) return true; // Allocate space for cities on device City *d_city; error = checkForError(cudaMalloc((void**)&d_city, h_world->num_cities * \ sizeof(City))); if (error) { cout << "DEVICE ERROR - Allocating cities on device during " \ << "world initialization" << endl; return true; } // Update pointer on device error = checkForError(cudaMemcpy(&d_world->cities, &d_city, \ sizeof(City*), cudaMemcpyHostToDevice)); if (error) { cout << "DEVICE ERROR - Updating city pointer on device during " \ << "world initialization" << endl; return true; } return false; }
GLuint Shader::createAndCompileShader(GLenum type, std::string source) { GLuint shader_index = glCreateShader(type); const int NUMBER_OF_SHADER_SOURCES = 1; const int* NULL_TERMINATED = NULL; // NULL equals null-terminated strings const char* source_cstr = source.c_str(); glShaderSource(shader_index, NUMBER_OF_SHADER_SOURCES, &source_cstr, NULL_TERMINATED); glCompileShader(shader_index); checkForError(shader_index); return shader_index; }
void dynamixelApi_setGoalPos(int actuator, int pos) { if(dynamixelApi_isWheelMode(actuator)) printf("WARNING: Position control in Dynamixel only possible in non-wheel model\n"); dxl_write_word(dyna.actuators[actuator], P_GOAL_POSITION_L, pos ); if(dyna.logPos) { if(dyna.posLog==0) { char name[100]; sprintf(name, "SetPos%li.log",time(NULL)); dyna.posLog = fopen(name,"w"); } fprintf(dyna.posLog,"%f \t %i \t %i \t %i\n",getLocalTime(), actuator, pos, dynamixelApi_getPosition(actuator)); fflush(dyna.posLog); } checkForError(actuator,13); }
bool g_soft_clone_world(World* d_world, World* h_world) { /* Clone most of the world in device memory d_world : The world to initialize on the device h_world : The host world to use as a template returns true if an error occurred */ // Error checking bool error; error = checkForError(cudaMemcpy(&d_world->width, &h_world->width, \ sizeof(int), cudaMemcpyHostToDevice)); if (error) { cout << "DEVICE ERROR - Copying world width to device during " \ << "world initialization" << endl; return true; } error = checkForError(cudaMemcpy(&d_world->height, &h_world->height, \ sizeof(int), cudaMemcpyHostToDevice)); if (error) { cout << "DEVICE ERROR - Copying world height to device during " \ << "world initialization" << endl; return true; } error = checkForError(cudaMemcpy(&d_world->num_cities, \ &h_world->num_cities, sizeof(int), cudaMemcpyHostToDevice)); if (error) { cout << "DEVICE ERROR - Copying number of cities to device " \ << "during world initialization" << endl; return true; } return false; }
void SymbolPlace::drawAt(int x, int y) const { float dx = (-(float)xLength + 2 * x) / xLength; float dy = ((float)yLength - 2 * (1 + y)) / yLength; glm::mat4 MP = glm::scale(glm::translate(glm::mat4(1.0), glm::vec3(dx, dy, 0)), glm::vec3(2.0 / xLength, 2.0 / yLength, 1.0)); glm::mat3 NM = glm::inverse(glm::transpose(glm::mat3(MP))); // Sending matrix glUniformMatrix4fv(matrixUniform, 1, GL_FALSE, glm::value_ptr(MP)); checkForError(__FILE__, __LINE__); glUniformMatrix3fv(normalMatrixUniform, 1, GL_FALSE, glm::value_ptr(NM)); checkForError(__FILE__, __LINE__); if (meshBuffer != NULL) { meshBuffer->process("in_mesh_vertexPosition", "in_mesh_normal", "in_mesh_textureCoords"); } else { printf("Nothing to process cause symbol position isn't set"); } }
void Redraw(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // curve.drawTexture(); if (opaque) glColor3ub(0, 64, 16); else glColor4ub(0, 64, 16, 128); curve.render(); if (controlPolygon) { glColor3ub(255,0,0); curve.drawControl(); } glutSwapBuffers(); checkForError("swap"); }
std::string KartinaTVClient::requestStreamUrl(const PVR_CHANNEL &channel) { XBMC->Log(ADDON::LOG_DEBUG, "void KartinaTVClient::requestStreamUrl()"); bool isProtected = false; for (const auto &c: channelsCache) { if (c.id == channel.iUniqueId && c.isProtected) isProtected = true; } PostFields parameters; parameters.insert(std::make_pair("cid", std::to_string(channel.iUniqueId))); if (isProtected) parameters.insert(std::make_pair("protect_code", protectCode)); std::string reply = makeRequest("get_url", parameters); XBMC->Log(ADDON::LOG_DEBUG, KTV_FUNC_INFO ": data: %s", reply.c_str()); KTVError ktvError; if (reply.size() != 0 && (ktvError = checkForError(reply)).code == 0) { Json::Reader json; Json::Value root; json.parse(reply, root); const char *urlData = root["url"].asCString(); std::vector<std::string> urlParams; std::stringstream stream(urlData); std::string param; while (stream >> param) { XBMC->Log(ADDON::LOG_DEBUG, "Extracted: %d %s", urlParams.size(), param.data()); urlParams.push_back(param); } std::string url = urlParams.front(); // http/ts url = url.replace(0, 7, "http"); return url; } else {
void dynamixelApi_wheelMove(int actuator, int torque, bool dir) { int command = (dir<<10)|(0x03FF&torque); dxl_write_word(dyna.actuators[actuator], P_GOAL_SPEED_L, command); checkForError(actuator,23); }
void dynamixelApi_setPunch(int actuator, int punch) { dxl_write_word(dyna.actuators[actuator], P_PUNCH_L, punch); checkForError(actuator,22); }
bool dynamixelApi_isMoving(int actuator) { int moving = dxl_read_byte( dyna.actuators[actuator], P_MOVING); checkForError(actuator,21); return moving==1; }
int dynamixelApi_getTemperature(int actuator) { int temp = dxl_read_byte( dyna.actuators[actuator], P_PRESENT_TEMPERATURE ); checkForError(actuator,20); return temp; }
int dynamixelApi_getVoltage(int actuator) { int temp = dxl_read_byte( dyna.actuators[actuator], P_PRESENT_VOLTAGE ); checkForError(actuator,19); return temp; }