int main(int argc, char *argv[]) { print_time("Begin"); char *topo[5000]; int edge_num; char *demand; int demand_num; char *topo_file = argv[1]; edge_num = read_file(topo, 5000, topo_file); if (edge_num == 0) { printf("Please input valid topo file.\n"); return -1; } char *demand_file = argv[2]; demand_num = read_file(&demand, 1, demand_file); if (demand_num != 1) { printf("Please input valid demand file.\n"); return -1; } search_route(topo, edge_num, demand); char *result_file = argv[3]; write_result(result_file); release_buff(topo, edge_num); release_buff(&demand, 1); print_time("End"); return 0; }
/* * Subscribe the topic: IOT_MQTT_Subscribe(pclient, TOPIC_DATA, IOTX_MQTT_QOS1, _demo_message_arrive, NULL); * Publish the topic: IOT_MQTT_Publish(pclient, TOPIC_DATA, &topic_msg); */ static void mqtt_publish(void *pclient) { int rc = -1; if(is_subscribed == 0) { /* Subscribe the specific topic */ rc = IOT_MQTT_Subscribe(pclient, TOPIC_DATA, IOTX_MQTT_QOS1, _demo_message_arrive, NULL); if (rc<0) { // IOT_MQTT_Destroy(&pclient); LOG("IOT_MQTT_Subscribe() failed, rc = %d", rc); } is_subscribed = 1; aos_schedule_call(ota_init, gpclient); } else{ /* Initialize topic information */ memset(&topic_msg, 0x0, sizeof(iotx_mqtt_topic_info_t)); topic_msg.qos = IOTX_MQTT_QOS1; topic_msg.retain = 0; topic_msg.dup = 0; /* Generate topic message */ int msg_len = snprintf(msg_pub, sizeof(msg_pub), "{\"attr_name\":\"temperature\", \"attr_value\":\"%d\"}", cnt); if (msg_len < 0) { LOG("Error occur! Exit program"); } topic_msg.payload = (void *)msg_pub; topic_msg.payload_len = msg_len; rc = IOT_MQTT_Publish(pclient, TOPIC_DATA, &topic_msg); if (rc < 0) { LOG("error occur when publish"); } #ifdef MQTT_ID2_CRYPTO LOG("packet-id=%u, publish topic msg='0x%02x%02x%02x%02x'...", (uint32_t)rc, msg_pub[0], msg_pub[1], msg_pub[2], msg_pub[3]); #else LOG("packet-id=%u, publish topic msg=%s", (uint32_t)rc, msg_pub); #endif } cnt++; if(cnt < 200) { aos_post_delayed_action(3000, mqtt_publish, pclient); } else { IOT_MQTT_Unsubscribe(pclient, TOPIC_DATA); aos_msleep(200); IOT_MQTT_Destroy(&pclient); release_buff(); is_subscribed = 0; cnt = 0; } }
int main(int argc, char *argv[]) { Floyd test; test.initialvector((int *)V,6); test.floyd(); Dijkstra test_dijkstra; test_dijkstra.dijkstra(3,(int*)V,6); //print_time("Begin"); char *topo[5000]; int edge_num; char *demand; int demand_num; char *topo_file = argv[1]; edge_num = read_file(topo, 5000, topo_file); if (edge_num == 0) { printf("Please input valid topo file.\n"); return -1; } char *demand_file = argv[2]; demand_num = read_file(&demand, 1, demand_file); if (demand_num != 1) { printf("Please input valid demand file.\n"); return -1; } search_route(topo, edge_num, demand); char *result_file = argv[3]; write_result(result_file); release_buff(topo, edge_num); release_buff(&demand, 1); //print_time("End"); return 0; }
void PuString::set_char( int idx, char c ) { if ((*pbuff)[idx] != c) { if (pbuff->refc > 1) { PuBuffer *new_pbuff = new PuBuffer(c_str(), length()); release_buff(); pbuff = new_pbuff; } (*pbuff)[idx]=c; hash_Key = 0; } }
PuString & PuString::operator=( const char *x ) { if (pbuff) { if (pbuff->c_str() == x) { return *this; } release_buff(); } hash_Key = 0; pbuff = new PuBuffer(x); return *this; }
PuString & PuString::operator+=( const char *x ) { if (pbuff) { PuBuffer *new_pbuff = new PuBuffer(c_str(), length()); new_pbuff->append(x); release_buff(); pbuff = new_pbuff; hash_Key = 0; } else { pbuff = new PuBuffer(x); } return *this; }
PuString & PuString::operator=( const PuString &x ) { if (pbuff == x.pbuff) { return *this; } if (pbuff) { release_buff(); } pbuff = x.pbuff; hash_Key = x.hash_Key; if (pbuff) { ++pbuff->refc; } return *this; }
int main(int argc, char *argv[]) { //print_time("Experiment Beginn"); char *topo[MAX_EDGE_NUM]; int edgeNum; char *demand[MAX_DEMAND_NUM]; int demandNum; char *srlg[MAX_SRLG_NUM]; int srlgNum; //char[] of absolute path of file char *topo_file = argv[1]; char *demand_file = argv[2]; char *srlg_file = argv[3]; char *result_file = argv[4]; //algorthm types. int alg = atoi(argv[5]); // if (1 == argc) { string si = "0"; string suffix = "/home/franz/franz/franzDocuments/eclipse4cworkspace/SCLS/Sample/test"; string strtopo = "/topo.csv"; string strdemand = "/demand.csv"; string strsrlg = "/srlg.csv"; string strresult = "/result.csv"; // char argv1[100] ="/home/franz/eclipse4cworkspace/SRLG_Franz/test6/topo.csv"; // char argv2[100] ="/home/franz/eclipse4cworkspace/SRLG_Franz/test6/demand.csv"; // char argv3[100] ="/home/franz/eclipse4cworkspace/SRLG_Franz/test6/srlg.csv"; // char argv4[100] = "/home/franz/eclipse4cworkspace/SRLG_Franz/test6/result.csv"; // topo_file=argv1; // demand_file=argv2; // srlg_file=argv3; // result_file=argv4; alg = 0; string s1 = (suffix + si + strtopo); string s2 = (suffix + si + strdemand); string s3 = (suffix + si + strsrlg); string s4 = (suffix + si + strresult); topo_file = (char *) malloc(sizeof(char) * (s1.length() + 1)); demand_file = (char *) malloc(sizeof(char) * (s2.length() + 1)); srlg_file = (char *) malloc(sizeof(char) * (s3.length() + 1)); result_file = (char *) malloc(sizeof(char) * (s4.length() + 1)); strcpy(topo_file, s1.c_str()); strcpy(demand_file, s2.c_str()); strcpy(srlg_file, s3.c_str()); strcpy(result_file, s4.c_str()); } //read topo.csv file edgeNum = read_file(topo, MAX_EDGE_NUM, topo_file); if (edgeNum == 0) { printf("Please input valid topo file.\n"); return -1; } //read demand.csv file demandNum = read_file(demand, MAX_DEMAND_NUM, demand_file); if (demandNum != MAX_DEMAND_NUM) { printf("Please input valid demand file.\n"); return -1; } //read srlg.csv file srlgNum = read_file(srlg, MAX_SRLG_NUM, srlg_file); if (srlgNum == 0) { printf("Please input valid srlg file.\n"); return -1; } //begin to find disjoint paths. search_route(topo, edgeNum, demand, demandNum, srlg, srlgNum, alg, topo_file, srlg_file); //write disjoint paths to file. //write_result(result_file); //release buffer data. release_buff(topo, edgeNum); release_buff(demand, demandNum); release_buff(srlg, srlgNum); return 0; }
/* * initialization parameter: mqtt_params */ int mqtt_client_example(void) { int rc = 0; iotx_conn_info_pt pconn_info; iotx_mqtt_param_t mqtt_params; if (msg_buf != NULL) { return rc; } if (NULL == (msg_buf = (char *)aos_malloc(MSG_LEN_MAX))) { LOG("not enough memory"); rc = -1; release_buff(); return rc; } if (NULL == (msg_readbuf = (char *)aos_malloc(MSG_LEN_MAX))) { LOG("not enough memory"); rc = -1; release_buff(); return rc; } /* Device AUTH */ if (0 != IOT_SetupConnInfo(PRODUCT_KEY, DEVICE_NAME, DEVICE_SECRET, (void **)&pconn_info)) { LOG("AUTH request failed!"); rc = -1; release_buff(); return rc; } /* Initialize MQTT parameter */ memset(&mqtt_params, 0x0, sizeof(mqtt_params)); mqtt_params.port = pconn_info->port; mqtt_params.host = pconn_info->host_name; mqtt_params.client_id = pconn_info->client_id; mqtt_params.username = pconn_info->username; mqtt_params.password = pconn_info->password; mqtt_params.pub_key = pconn_info->pub_key; mqtt_params.request_timeout_ms = 2000; mqtt_params.clean_session = 0; mqtt_params.keepalive_interval_ms = 60000; mqtt_params.pread_buf = msg_readbuf; mqtt_params.read_buf_size = MSG_LEN_MAX; mqtt_params.pwrite_buf = msg_buf; mqtt_params.write_buf_size = MSG_LEN_MAX; mqtt_params.handle_event.h_fp = event_handle_mqtt; mqtt_params.handle_event.pcontext = NULL; /* Construct a MQTT client with specify parameter */ gpclient = IOT_MQTT_Construct(&mqtt_params); if (NULL == gpclient) { LOG("MQTT construct failed"); rc = -1; release_buff(); //aos_unregister_event_filter(EV_SYS, mqtt_service_event, gpclient); } else{ aos_register_event_filter(EV_SYS, mqtt_service_event, gpclient); } return rc; }