Ejemplo n.º 1
0
bool owm_weather_fetch(OWMWeatherCallback *callback) {
  if(!s_info) {
    APP_LOG(APP_LOG_LEVEL_ERROR, "OWM Weather library is not initialized!");
    return false;
  }

  if(!callback) {
    APP_LOG(APP_LOG_LEVEL_ERROR, "OWMWeatherCallback was NULL!");
    return false;
  }

  s_callback = callback;

  if(!bluetooth_connection_service_peek()) {
    s_status = OWMWeatherStatusBluetoothDisconnected;
    s_callback(s_info, s_status);
    return false;
  }

  app_message_deregister_callbacks();
  app_message_register_inbox_received(inbox_received_handler);
  app_message_open(2026, 656);

  return fetch();
}
Ejemplo n.º 2
0
 // -------------------------------------------------------------------------
 void Logger::LogVA(OutputMessageType::OutputMessageType type, const WCHAR * fmt, va_list args)
 {
     wchar_t wbuffer[c_bufferSize];
     _vsnwprintf_s(wbuffer, c_bufferSize, _TRUNCATE, fmt, args);           
     if(s_callback)
         s_callback((int)type, wbuffer);
     else
         wprintf(wbuffer);
 }
Ejemplo n.º 3
0
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
  Tuple *reply_tuple = dict_find(iter, get_app_key(OWMWeatherAppMessageKeyReply));
  if(reply_tuple) {
    Tuple *desc_tuple = dict_find(iter, get_app_key(OWMWeatherAppMessageKeyDescription));
    strncpy(s_info->description, desc_tuple->value->cstring, OWM_WEATHER_BUFFER_SIZE);

    Tuple *desc_short_tuple = dict_find(iter, get_app_key(OWMWeatherAppMessageKeyDescriptionShort));
    strncpy(s_info->description_short, desc_short_tuple->value->cstring, OWM_WEATHER_BUFFER_SIZE);

    Tuple *temp_tuple = dict_find(iter, get_app_key(OWMWeatherAppMessageKeyTempK));
    s_info->temp_k = temp_tuple->value->int32;
    s_info->temp_c = s_info->temp_k - 273;
    s_info->temp_f = ((s_info->temp_c * 9) / 5 /* *1.8 or 9/5 */) + 32;
    s_info->timestamp = time(NULL);

    Tuple *pressure_tuple = dict_find(iter, get_app_key(OWMWeatherAppMessageKeyPressure));
    s_info->pressure = pressure_tuple->value->int32;

    Tuple *wind_speed_tuple = dict_find(iter, get_app_key(OWMWeatherAppMessageKeyWindSpeed));
    s_info->wind_speed = wind_speed_tuple->value->int32;

    Tuple *wind_direction_tuple = dict_find(iter, get_app_key(OWMWeatherAppMessageKeyWindDirection));
    s_info->wind_direction = wind_direction_tuple->value->int32;

    s_status = OWMWeatherStatusAvailable;
    app_message_deregister_callbacks();
    s_callback(s_info, s_status);
  }

  Tuple *err_tuple = dict_find(iter, get_app_key(OWMWeatherAppMessageKeyBadKey));
  if(err_tuple) {
    s_status = OWMWeatherStatusBadKey;
    s_callback(s_info, s_status);
  }

  err_tuple = dict_find(iter, get_app_key(OWMWeatherAppMessageKeyLocationUnavailable));
  if(err_tuple) {
    s_status = OWMWeatherStatusLocationUnavailable;
    s_callback(s_info, s_status);
  }
}
Ejemplo n.º 4
0
 // -------------------------------------------------------------------------
 void Logger::LogVA(OutputMessageType::OutputMessageType type, const char * fmt, va_list args)
 {        
     char buffer[c_bufferSize];
     wchar_t wbuffer[c_bufferSize];
     _vsnprintf_s(buffer, c_bufferSize, _TRUNCATE, fmt, args);        
     MultiByteToWideChar(0, 0, buffer, -1, wbuffer, c_bufferSize);
     if(s_callback)
         s_callback((int)type, wbuffer);
     else
         wprintf(wbuffer);
     
 }
Ejemplo n.º 5
0
static bool fetch() {
  DictionaryIterator *out;
  AppMessageResult result = app_message_outbox_begin(&out);
  if(result != APP_MSG_OK) {
    fail_and_callback();
    return false;
  }

  dict_write_cstring(out, get_app_key(OWMWeatherAppMessageKeyRequest), s_api_key);

  result = app_message_outbox_send();
  if(result != APP_MSG_OK) {
    fail_and_callback();
    return false;
  }

  s_status = OWMWeatherStatusPending;
  s_callback(s_info, s_status);
  return true;
}
Ejemplo n.º 6
0
static void timer_handler(void *context) {
  s_callback();

  s_timer = app_timer_register(INTERVAL_MINUTES * 60 * 1000, timer_handler, NULL);
}
Ejemplo n.º 7
0
int pkg_archive_extract
(Pkg pkg, PkgContentFile *con_files, struct archive *a, 
char **file_path, PkgContentFile *con_file, const char *prefix, INSTALL_STEP_CALLBACK(s_callback)){
	struct archive_entry *entry;
	char *file,
	     *dir;
	const char *link_s;
	int r, rval = 1,
	    fd = 0,
	    len;
	u_int i = 0, ii;
	u_short ok = 0;
	pboolean is_slink,
	         is_hlink;
	
	if(a == NULL)
		RETURN_P_ERR(P_ERR_INVALID_DESCRIPTOR, -1);
		
	for(;;){
		r = archive_read_next_header(a, &entry);

		if(r == ARCHIVE_EOF){
			rval = 0;
			
			break;
		} else if(r != ARCHIVE_OK){
			rval = -1;
			
			break;
		}
		
		is_slink = is_hlink = 0;
		
		if((link_s = archive_entry_symlink(entry)) != NULL){
			is_slink = 1;
		} else if((link_s = archive_entry_hardlink(entry)) != NULL){
			is_hlink = 1;
		}
		
		file = (char *)archive_entry_pathname(entry);
		
		if(file == NULL){
			rval = -1;
			
			break;
		}
		
		char *fp;
		if(file[0] != '+')
			for(i = 0; con_files[i] != NULL; i++){
				len = strlen(con_files[i]->cwd);
				fp = con_files[i]->file;
				fp = fp + len;
			
				if(fp[0] == '/')
					fp++;

				if(strlen(fp) == strlen(file))
					if(!strcmp(fp, file)){
						ok = 1;
				
						break;
					}
			}
			
		if(ok){
			if(s_callback != NULL)
				s_callback(0, 0, con_files[i]->file, PSTEP_T_FCPY, 0, STAGE_PRE_T);
				
			*con_file = con_files[i];			
			*file_path = strdup(con_files[i]->file);
			
			len = strlen(*file_path);
			dir = (char *)malloc(len);
			assert(dir != NULL);
			memset(dir, 0, len);
			strncpy(dir, *file_path, len);
			
			for(ii = (len - 1);ii != 0;ii--)
				if(dir[ii] == '/'){
					dir[ii] = (char)0;
					
					break;
				}
			
			if(access(dir, F_OK) == -1)
				r = mkdir_tree(dir, DEF_O_MODE);
		}
			
		if(ok && (is_slink || is_hlink)){
			const char *dir;
			char *dir_s = NULL;
			
			*file_path = strdup(con_files[i]->file);
			dir = _find_link(link_s, con_files);
			
			if(!dir){
				asprintf(&dir_s, "%s/%s", prefix, link_s);
				assert(dir_s != NULL);
				
				dir = dir_s;
			}
			
			if(is_slink){
				r = symlink(dir, con_files[i]->file);
			} else
				r = link(dir, con_files[i]->file);
				
			free(dir_s);		
			
			if(r == -1)				
				RETURN_P_ERRNO(-1);
				
			break;
				
		} else if(ok){
			if(!r){
				fd = open(*file_path, O_CREAT | O_WRONLY, DEF_O_MODE);
			
				if(fd == -1){
					rval = -1;
				} else {
					rval = archive_read_data_into_fd(a, fd);
					if(rval < 0){
						rval = -1;
					} else
						rval = 1;
					close(fd);
					
					char *script = NULL;
					
					if(con_files[i]->mode != NULL){						
						asprintf(&script, "chmod %s %s 2>/dev/null",
						con_files[i]->mode, *file_path);
						assert(script != NULL);
						
						pkg_exec_script(script);
						free(script);
					}
					if(con_files[i]->group != NULL || con_files[i]->user != NULL){
						char *group;
						char *user;
						
						if(con_files[i]->group != NULL){
							asprintf(&group, ":%s", con_files[i]->group);
							assert(group != NULL);
						} else
							group = "";
						if(con_files[i]->user != NULL){
							user = con_files[i]->user;
						} else
							user = getenv("USER");						
							
						asprintf(&script, "chown %s%s %s 2>/dev/null",
						user, group, *file_path);
						assert(script != NULL);
						
						pkg_exec_script(script);
						free(script);
						
						if(group[0] != '\0')
							free(group);
					}
				}
			}
			else
				rval = -1;
				
			free(dir);			
			break;
		}
	}
	if(rval == -1){
		
		if(fd == -1){
			RETURN_P_ERRNO(-1);
		} else
			RETURN_P_LARCHIVE(-1, a);
	}
	
	return rval;
}
// come here after receiving ANY reply from the gigablast server
static void gotReplyWrapper ( void *state , TcpSocket *sock ) {

	processReply ( sock->m_readBuf , sock->m_readOffset );

	s_callback ();
}
Ejemplo n.º 9
0
static void fail_and_callback() {
  APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to send request!");
  s_status = OWMWeatherStatusFailed;
  s_callback(s_info, s_status);
}