void add_dir_entry(char* paramDir, char *dir, char *entry, uint32_t entry_size, char *kind, uint16_t elementary_pid, uint32_t carousel_id, uint16_t module_id, char *key, uint32_t key_size) { char *ascii_key; char realfile[PATH_MAX]; char linkfile[PATH_MAX]; /* BBC use numbers as object keys, so convert to a text value we can use as a file name */ ascii_key = convert_key(key, key_size); if (paramDir[0] == '/') { snprintf(realfile, sizeof(realfile), "../../../../../%s/%s/%u/%u/%s-%u-%s", paramDir + 1, CAROUSELS_DIR, elementary_pid, carousel_id, kind, module_id, ascii_key); } else { snprintf(realfile, sizeof(realfile), "../../../../../%s/%s/%u/%u/%s-%u-%s", paramDir, CAROUSELS_DIR, elementary_pid, carousel_id, kind, module_id, ascii_key); } snprintf(linkfile, sizeof(linkfile), "%s/%.*s", dir, entry_size, entry); /* * linkfile may already exist if we get an update to an existing module * if linkfile already exists, symlink will not update it * so delete it first to make sure the link gets updated */ unlink(linkfile); if(symlink(realfile, linkfile) < 0) fatal("Unable to create link '%s' to '%s': %s", linkfile, realfile, strerror(errno)); verbose("Added directory entry '%s' -> '%s'\n", linkfile, realfile); return; }
void dynamic_free(dfile *df,int key) { int block,length,next_block; if (!convert_key(df,key,&block,&length)) return; (void) store_int((char *)(df->keylist+key*2),-df->first_free_key); (void) store_int((char *)(df->keylist+key*2+1),0); df->first_free_key=key; /* simply keep adding blocks onto the top of the free list */ while(length>0) { if (block<=0) return; next_block = dynamic_get_next_block(df,block); dynamic_seek_block(df,block); store_int(stack,-df->first_free_block); if (write(df->data_fd,stack,4)!=4) handle_error("Failed to write next block"); df->first_free_block=block; block = next_block; length -= (df->granularity-4); } if (!(sys_flags&SECURE_DYNAMIC)) dynamic_key_sync(df); }
char * make_dir(char* paramDir, char *kind, uint16_t elementary_pid, uint32_t carousel_id, uint16_t module_id, char *key, uint32_t key_size, uint8_t module_version) { char *root; char *ascii_key; FILE *f; char filename[PATH_MAX]; /* make sure the carousel directory exists */ root = make_carousel_root(paramDir, elementary_pid, carousel_id); /* BBC use numbers as object keys, so convert to a text value we can use as a file name */ ascii_key = convert_key(key, key_size); snprintf(_dirname, sizeof(_dirname), "%s/%s-%u-%s", root, kind, module_id, ascii_key); /* may already exist if we get an updated version of it */ if(mkdir(_dirname, 0755) < 0 && errno != EEXIST) fatal("Unable to create directory '%s': %s", _dirname, strerror(errno)); verbose("Created directory '%s'\n", _dirname); snprintf(filename, sizeof(filename), "%s/%s-%u-%s.version", root, kind, module_id, ascii_key); if((f = fopen(filename, "wb")) == NULL) fatal("Unable to create file '%s': %s", filename, strerror(errno)); if(fwrite(&module_version, 1, 1, f) != 1) fatal("Unable to write to file '%s'", filename); fclose(f); return _dirname; }
int dynamic_save(dfile *df,char *data,int l,int key) { int block,length,next_block,blength,free_block; /* key==0 means this is a new entry */ if (!key) { key=dynamic_find_free_key(df); block=dynamic_find_free_block(df); } else if (!convert_key(df,key,&block,&length)) return -1; /* printf("Dynamic Save key=%d\n",key); */ (void) store_int((char *)(df->keylist+key*2),block); (void) store_int((char *)(df->keylist+key*2+1),l); blength=df->granularity-4; while(l>0) { next_block=dynamic_get_next_block(df,block); /* printf("DS block %d / next block %d\n",block,next_block); */ /* do we need more space ? */ if (l>blength) { if (next_block<=0) next_block=dynamic_find_free_block(df); } else { /* can we free up any blocks at the end ? */ free_block=next_block; while(free_block>0) { next_block=dynamic_get_next_block(df,free_block); dynamic_seek_block(df,free_block); store_int(stack,-df->first_free_block); if (write(df->data_fd,stack,4)!=4) handle_error("Failed to write next block"); df->first_free_block=free_block; free_block=next_block; } next_block=0; } store_int(stack,next_block); dynamic_seek_block(df,block); if (write(df->data_fd,stack,4)!=4) handle_error("Failed to write next block"); if (write(df->data_fd,data,blength)!=blength) handle_error("Failed to write block data"); block=next_block; l-=blength; data+=blength; } /* make sure the keylist is up to date */ if (!(sys_flags&SECURE_DYNAMIC)) dynamic_key_sync(df); return key; }
static address_t hash(hash_table_t *table, hash_key_t *key) { address_t h, address; h = convert_key(key); h %= PRIME_2; address = h & (table->maxp-1); /* h % maxp */ if (address < table->p) address = h & ((table->maxp << 1)-1); /* h % (2*table->maxp) */ return address; }
void mkyu::Keyboard::update() { auto update = [](KeyType key) { bool is_pressed = glfwGetKey(detail::window, convert_key(key)) == GLFW_PRESS; if (!is_pressed) m_key_states[key] = KeyState::Release; else if (m_key_states[key] == KeyState::Release) m_key_states[key] = KeyState::Push; else m_key_states[key] = KeyState::Hold; }; for (int i = 0; i <= static_cast<int>(KeyType::Space); i++) { update(static_cast<KeyType>(i)); } }
int dynamic_load(dfile *df,int key,char *data) { int block,length,l; /* printf("Dynamic load key=%d\n",key); */ if (!convert_key(df,key,&block,&length)) return -1; l=length; while(l>0) { /* printf("DL block %d, Length = %d\n",block,l); */ if (!load_block(df,&block,data)) handle_error("Failed to load block of data"); l-=(df->granularity-4); data+=(df->granularity-4); } return length; }
//default keyboard event handler static OSStatus KeyEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData) { OSStatus result = noErr; UInt32 class = GetEventClass (event); UInt32 kind = GetEventKind (event); result = CallNextEventHandler(nextHandler, event); if(class == kEventClassKeyboard) { char macCharCodes; UInt32 macKeyCode; UInt32 macKeyModifiers; GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(macCharCodes), NULL, &macCharCodes); GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(macKeyCode), NULL, &macKeyCode); GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(macKeyModifiers), NULL, &macKeyModifiers); if(macKeyModifiers != 256) { if (kind == kEventRawKeyRepeat || kind == kEventRawKeyDown) { int key = convert_key(macKeyCode, macCharCodes); if(key != -1) mplayer_put_key(key); } } else if(macKeyModifiers == 256) { switch(macCharCodes) { case '[': SetWindowAlpha(theWindow, winAlpha-=0.05); break; case ']': SetWindowAlpha(theWindow, winAlpha+=0.05); break; } } else result = eventNotHandledErr; } return result; }
void make_service_root(char* paramDir, uint16_t service_id, char *kind, uint16_t elementary_pid, uint32_t carousel_id, uint16_t module_id, char *key, uint32_t key_size) { char dirname[PATH_MAX]; char *ascii_key; char realfile[PATH_MAX]; char linkfile[PATH_MAX]; /* make sure the services directory exists */ snprintf(dirname, sizeof(dirname), "%s", paramDir); if(mkdir(dirname, 0755) < 0 && errno != EEXIST) fatal("Unable to create services directory '%s': %s", dirname, strerror(errno)); snprintf(dirname, sizeof(dirname), "%s/%s", paramDir, SERVICES_DIR); if(mkdir(dirname, 0755) < 0 && errno != EEXIST) fatal("Unable to create services directory '%s': %s", dirname, strerror(errno)); /* BBC use numbers as object keys, so convert to a text value we can use as a file name */ ascii_key = convert_key(key, key_size); /* create a symlink to the Service Gateway dir */ if (paramDir[0] == '/') { snprintf(realfile, sizeof(realfile), "../../%s/%s/%u/%u/%s-%u-%s", paramDir+1, CAROUSELS_DIR, elementary_pid, carousel_id, kind, module_id, ascii_key); } else { snprintf(realfile, sizeof(realfile), "../../%s/%s/%u/%u/%s-%u-%s", paramDir, CAROUSELS_DIR, elementary_pid, carousel_id, kind, module_id, ascii_key); } snprintf(linkfile, sizeof(linkfile), "%s/%u", dirname, service_id); /* * linkfile may already exist if we get an update to an existing module * if linkfile already exists, symlink will not update it * so delete it first to make sure the link gets updated */ unlink(linkfile); if(symlink(realfile, linkfile) < 0 && errno != EEXIST) fatal("Unable to create link '%s' to '%s': %s", linkfile, realfile, strerror(errno)); verbose("Added service root '%s' -> '%s'\n", linkfile, realfile); return; }
void gkpd_write_value(int value) { int i; int key; key = convert_key(value); if (key < 0) return; if (gkpd_last_index == 20) { gkpd_value[gkpd_last_index] = key; for (i = 0; i < 20; i++) { gkpd_value[i] = gkpd_value[i+1]; } gkpd_value[gkpd_last_index] = '\n'; } else { gkpd_value[gkpd_last_index] = key; gkpd_value[gkpd_last_index + 1] = '\n'; gkpd_last_index++; } }
void save_file(char* paramDir, char *kind, uint16_t elementary_pid, uint32_t carousel_id, uint16_t module_id, char *key, uint32_t key_size, char *file, uint32_t file_size, uint8_t module_version) { char *root; char *ascii_key; char filename[PATH_MAX]; FILE *f; /* make sure the carousel directory exists */ root = make_carousel_root(paramDir, elementary_pid, carousel_id); /* BBC use numbers as object keys, so convert to a text value we can use as a file name */ ascii_key = convert_key(key, key_size); /* construct the file name */ snprintf(filename, sizeof(filename), "%s/%s-%u-%s", root, kind, module_id, ascii_key); if((f = fopen(filename, "wb")) == NULL) fatal("Unable to create file '%s': %s", filename, strerror(errno)); if(fwrite(file, 1, file_size, f) != file_size) fatal("Unable to write to file '%s'", filename); fclose(f); verbose("Created file '%s'\n", filename); snprintf(filename, sizeof(filename), "%s/%s-%u-%s.version", root, kind, module_id, ascii_key); if((f = fopen(filename, "wb")) == NULL) fatal("Unable to create file '%s': %s", filename, strerror(errno)); if(fwrite(&module_version, 1, 1, f) != 1) fatal("Unable to write to file '%s'", filename); fclose(f); return; }
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { GHL::Application* appl = reinterpret_cast<GHL::Application*>(GetWindowLongPtr(hwnd,GWLP_USERDATA)); switch(msg) { case WM_MOUSEMOVE: { if ( wparam & MK_LBUTTON ) { if (appl) appl->OnMouseMove(GHL::MOUSE_BUTTON_LEFT,LOWORD(lparam),HIWORD(lparam)); } } break; case WM_LBUTTONDOWN: { { if (appl) appl->OnMouseDown(GHL::MOUSE_BUTTON_LEFT,LOWORD(lparam),HIWORD(lparam)); } } break; case WM_LBUTTONUP: { { if (appl) appl->OnMouseUp(GHL::MOUSE_BUTTON_LEFT,LOWORD(lparam),HIWORD(lparam)); } } break; case WM_KEYDOWN: { GHL::Key key = convert_key(wparam); if (key!=GHL::KEY_NONE) { if (appl) appl->OnKeyDown(key); } } break; case WM_KEYUP: { GHL::Key key = convert_key(wparam); if (key!=GHL::KEY_NONE) { if (appl) appl->OnKeyUp(key); } } break; case WM_CLOSE: SetWindowLongPtr(hwnd,GWLP_USERDATA,(LONG_PTR)0); PostMessage (hwnd, WM_QUIT, 0, 0); return 0; break; case WM_SETCURSOR: /*if (impl) { if(impl->m_window_active && LOWORD(lparam)==HTCLIENT && !impl->m_cursor_visible) SetCursor(NULL); else SetCursor(LoadCursor(NULL, IDC_ARROW)); return FALSE; }*/ break; case WM_ACTIVATE: if (appl) { /* // tricky: we should catch WA_ACTIVE and WA_CLICKACTIVE, // but only if HIWORD(wParam) (fMinimized) == FALSE (0) bool bActivating = (LOWORD(wparam) != WA_INACTIVE) && (HIWORD(wparam) == 0); if(impl->m_window_active != bActivating) { impl->m_window_active = bActivating; if (impl->m_controller) { if (bActivating) impl->m_controller->OnFocusGain(impl); else impl->m_controller->OnFocusLost(impl); } } return FALSE; */ } break; case WM_SYSCOMMAND: /*if(wparam==SC_CLOSE) { if (impl ) { if (impl->m_controller && !impl->m_controller->ExitAllowed()) return FALSE; return DefWindowProc(hwnd, msg, wparam, lparam); } }*/ break; } return DefWindowProc(hwnd, msg, wparam, lparam);; }