/* ====================================================================== Function: httpPost Purpose : Do a http post Input : hostname port url Output : true if received 200 OK Comments: - ====================================================================== */ boolean httpPost(char * host, uint16_t port, char * url) { HTTPClient http; bool ret = false; unsigned long start = millis(); // configure traged server and url http.begin(host, port, url); //http.begin("http://emoncms.org/input/post.json?node=20&apikey=2f13e4608d411d20354485f72747de7b&json={PAPP:100}"); //http.begin("emoncms.org", 80, "/input/post.json?node=20&apikey=2f13e4608d411d20354485f72747de7b&json={}"); //HTTP Debugf("http%s://%s:%d%s => ", port==443?"s":"", host, port, url); // start connection and send HTTP header int httpCode = http.GET(); if(httpCode) { // HTTP header has been send and Server response header has been handled Debug(httpCode); Debug(" "); // file found at server if(httpCode == 200) { String payload = http.getString(); Debug(payload); ret = true; } } else { DebugF("failed!"); } Debugf(" in %d ms\r\n",millis()-start); return ret; }
ProBInitialResponse prob_init(prob_client_t pc, int is_por) { Debugf("initializing ProB Zocket\n") zmsg_t *request = zmsg_new(); zmsg_addstr(request, "init"); zmsg_addstrf(request, "%d", pc->id_count); zmsg_addstrf(request, "%d", is_por); Debugf("sending message with length %zu, contents are:\n", zmsg_content_size(request)); #ifdef LTSMIN_DEBUG if (log_active(debug)) zmsg_print(request); #endif if (zmsg_send(&request, pc->zocket) != 0) Abort("Could not send message"); zmsg_destroy(&request); zmsg_t *response = zmsg_recv(pc->zocket); if (response == NULL) Abort("Did not receive valid response"); Debugf("received message with length %zu, contents are:\n", zmsg_content_size(response)); #ifdef LTSMIN_DEBUG if (log_active(debug)) zmsg_print(response); #endif ProBInitialResponse resp = prob_get_init_response(response); if (zmsg_size(response) != 0) Abort("Did not receive valid reponse size"); // puts("transition groups:"); // print_chunk_array(resp.transition_groups); // puts("variables"); // print_chunk_array(resp.variables); // for (size_t i = 0; i < resp.variables.size; i++) { // printf("%s (%s)\n", resp.variables.chunks[i].data, resp.variable_types.chunks[i].data); // } // puts("state labels"); // print_chunk_array(resp.state_labels); // // puts("May Write Matrix:"); // print_matrix(resp.may_write); // puts("Must Write Matrix:"); // print_matrix(resp.must_write); // puts("Reads Action Matrix:"); // print_matrix(resp.reads_action); // puts("Reads Guard Matrix:"); // print_matrix(resp.reads_guard); zmsg_destroy(&response); return resp; }
// add factory void AssetManager::registerType(int type, AssetFactory* factory) { SCOPE_LOCK; if (type < 0 || type >= Asset::MAX_TYPES) Errorf("out of bound"); if (m_datas[type] != nullptr) { Errorf("already registered"); } int poolsize = factory->getPoolSize(); m_datas[type] = TypeNew<Data>(poolsize); m_datas[type]->factory = factory; m_datas[type]->poolHint = factory->getPoolHint(); Asset* defaulted = factory->getDefaulted(); if (defaulted == nullptr) { defaulted = factory->create(); if (!defaulted->doInit("default", 0)) { factory->destroy(defaulted); defaulted = nullptr; } } m_datas[type]->defaulted = defaulted; if (defaulted != nullptr) { defaulted->m_isDefaulted = true; } else { // TODO Debugf("%s: can't found defaulted asset for type\n", __func__); } }
void InputSystem::queEvent(const Event& e) { if (!m_isCapturing) { return; } if (m_eventWritePos - m_eventReadPos > EVENT_POOL_SIZE) { Debugf("%s: event overflowed.\n", __func__); return; } m_events[m_eventWritePos&(EVENT_POOL_SIZE-1)] = e; m_eventWritePos++; }
static ProBState * prob_next_x(prob_client_t pc, ProBState s, char *transitiongroup, int *size, char *header) { zmsg_t *request = zmsg_new(); zmsg_addstr(request, header); zmsg_addstrf(request, "%d", pc->id_count); zmsg_addstr(request, transitiongroup); prob_put_state(request, s); Debugf("requesting next-state, contents:\n"); #ifdef LTSMIN_DEBUG if (log_active(debug)) zmsg_print(request); #endif zmsg_send(&request, pc->zocket); zmsg_destroy(&request); zmsg_t *response = zmsg_recv(pc->zocket); Debugf("response for next-state, contents:\n"); #ifdef LTSMIN_DEBUG if (log_active(debug)) zmsg_print(response); #endif drop_frame(response); drop_frame(response); char *nr_of_states_s = zmsg_popstr(response); sscanf(nr_of_states_s, "%d", size); RTfree(nr_of_states_s); ProBState *successors = RTmalloc(sizeof(ProBState) * (*size)); int i; for (i = 0; i < (*size); i++) { successors[i] = prob_get_state(response); } zmsg_destroy(&response); return successors; }
void AssetManager::removeAsset(Asset* asset) { SCOPE_LOCK; AX_ASSERT(asset->getRefCount() == 0); AX_ASSERT(asset); if (asset->isDefaulted()) return; int type = asset->getType(); checkType(__func__, type); Data* d = m_datas[type]; AssetDict::iterator it =d->assetDict.find(asset->m_key); if (it == d->assetDict.end()) { d->factory->destroy(asset); Debugf("%s: not found asset key", __func__); return; } // if is immortal asset, return if (d->poolHint == AssetFactory::Immortal) { return; } Asset* a = it->second; //AX_ASSERT(a == asset); // or, add to not referenced list asset->m_frameId = m_frameId; if (!asset->m_isInDeleteList) { d->assetNotRefed.push_back(asset); asset->m_isInDeleteList = true; } return; }
/* ====================================================================== Function: handleNotFound Purpose : default WEB routing when URI is not found Input : - Output : - Comments: - ====================================================================== */ void handleNotFound(void) { String response = ""; boolean found = false; // Led on LedBluON(); // try to return SPIFFS file found = handleFileRead(server.uri()); // Try Teleinfo ETIQUETTE if (!found) { // We check for an known label ValueList * me = tinfo.getList(); const char * uri; // convert uri to char * for compare uri = server.uri().c_str(); Debugf("handleNotFound(%s)\r\n", uri); // Got at least one and consistent URI ? if (me && uri && *uri=='/' && *++uri ) { // Loop thru the linked list of values while (me->next && !found) { // go to next node me = me->next; //Debugf("compare to '%s' ", me->name); // Do we have this one ? if (stricmp (me->name, uri) == 0 ) { // no need to continue found = true; // Add to respone response += F("{\"") ; response += me->name ; response += F("\":") ; formatNumberJSON(response, me->value); response += F("}\r\n"); } } } // Got it, send json if (found) server.send ( 200, "text/json", response ); } // All trys failed if (!found) { // send error message in plain text String message = F("File Not Found\n\n"); message += F("URI: "); message += server.uri(); message += F("\nMethod: "); message += ( server.method() == HTTP_GET ) ? "GET" : "POST"; message += F("\nArguments: "); message += server.args(); message += FPSTR(FP_NL); for ( uint8_t i = 0; i < server.args(); i++ ) { message += " " + server.argName ( i ) + ": " + server.arg ( i ) + FPSTR(FP_NL); } server.send ( 404, "text/plain", message ); } // Led off LedBluOFF(); }