void cb_vs_spawn_object(object *parent, int id, vec2i pos, int g, void *userdata) { scene *s = (scene*)userdata; // Get next animation bk_info *info = bk_get_info(&s->bk_data, id); if(info != NULL) { object *obj = malloc(sizeof(object)); object_create(obj, parent->gs, vec2i_add(pos, vec2f_to_i(parent->pos)), vec2f_create(0,0)); object_set_stl(obj, object_get_stl(parent)); object_set_animation(obj, &info->ani); object_set_spawn_cb(obj, cb_vs_spawn_object, userdata); object_set_destroy_cb(obj, cb_vs_destroy_object, userdata); game_state_add_object(parent->gs, obj, RENDER_LAYER_MIDDLE, 0, 0); } }
int console_cmd_har(game_state *gs, int argc, char **argv) { // change har if(argc == 2) { int i; if(strtoint(argv[1], &i)) { if(i < 0 || i > 10) { return 1; } game_player *player = game_state_get_player(gs, 0); if (scene_load_har(game_state_get_scene(gs), 0, player->har_id)) { return 1; } object *har_obj = game_player_get_har(player); vec2i pos = object_get_pos(har_obj); int hd = object_get_direction(har_obj); object *obj = malloc(sizeof(object)); object_create(obj, gs, pos, vec2f_create(0,0)); player->har_id = i; if(har_create(obj, game_state_get_scene(gs)->af_data[0], hd, player->har_id, player->pilot_id, 0)) { object_free(obj); free(obj); return 1; } // Set HAR to controller and game_player game_state_add_object(gs, obj, RENDER_LAYER_MIDDLE, 0, 0); game_state_del_object(gs, har_obj); // Set HAR for player game_player_set_har(player, obj); game_player_get_ctrl(player)->har = obj; game_player_get_har(player)->animation_state.enemy = game_player_get_har(game_state_get_player(gs, 1)); game_player_get_har(game_state_get_player(gs, 1))->animation_state.enemy = game_player_get_har(player); maybe_install_har_hooks(game_state_get_scene(gs)); return 0; } } return 1; }
object_t *vector_create(size_t length) { object_t *obj = object_create(TYPE_VECTOR); if (obj == NULL) error("Out of memory error in `vector_create`"); obj->vector.value = calloc(length, sizeof(object_t*)); if (obj->vector.value == NULL) error("Memory allocation error in `vector_create`"); obj->vector.length = length; obj->destructor = &vector_destructor; obj->to_string = &vector_to_string; return obj; }
void saImmOmCcbObjectModify_2_17(void) { const SaImmAdminOwnerNameT adminOwnerName = (SaImmAdminOwnerNameT) __FUNCTION__; const SaImmOiImplementerNameT implementerName = (SaImmOiImplementerNameT) __FUNCTION__; SaImmAdminOwnerHandleT ownerHandle; SaImmCcbHandleT ccbHandle; const SaNameT obj1 = { strlen("id=1"), "id=1" }; const SaNameT obj2 = { strlen("id=2"), "id=2" }; const SaNameT* attrValues[] = { &obj1 }; SaImmAttrValuesT_2 v1 = {"attr1", SA_IMM_ATTR_SANAMET, 1, (void**)attrValues}; SaImmAttrModificationT_2 attrMod = { SA_IMM_ATTR_VALUES_REPLACE, v1 }; const SaImmAttrModificationT_2 *attrMods[] = { &attrMod, NULL }; const SaNameT* rdnValues1[] = { &obj1 }; SaImmAttrValuesT_2 rdnAttr1 = { "rdn", SA_IMM_ATTR_SANAMET, 1, (void**)rdnValues1 }; const SaImmAttrValuesT_2 *attrValues1[] = { &rdnAttr1, NULL }; safassert(saImmOmInitialize(&immOmHandle, NULL, &immVersion), SA_AIS_OK); safassert(saImmOmAdminOwnerInitialize(immOmHandle, adminOwnerName, SA_TRUE, &ownerHandle), SA_AIS_OK); safassert(nodangling_class_create(immOmHandle), SA_AIS_OK); safassert(runtime_class_create(immOmHandle), SA_AIS_OK); safassert(object_create(immOmHandle, ownerHandle, nodanglingClassName, &obj2, NULL, NULL), SA_AIS_OK); safassert(saImmOiInitialize_2(&immOiHandle, &immOiCallbacks, &immVersion), SA_AIS_OK); safassert(saImmOiImplementerSet(immOiHandle, implementerName), SA_AIS_OK); safassert(saImmOiRtObjectCreate_2(immOiHandle, runtimeClassName, NULL, attrValues1), SA_AIS_OK); safassert(saImmOmCcbInitialize(ownerHandle, 0, &ccbHandle), SA_AIS_OK); rc = saImmOmCcbObjectModify_2(ccbHandle, &obj2, attrMods); safassert(saImmOmCcbFinalize(ccbHandle), SA_AIS_OK); safassert(saImmOiRtObjectDelete(immOiHandle, &obj1), SA_AIS_OK); safassert(saImmOiFinalize(immOiHandle), SA_AIS_OK); safassert(object_delete(ownerHandle, &obj2, 1), SA_AIS_OK); safassert(runtime_class_delete(immOmHandle), SA_AIS_OK); safassert(nodangling_class_delete(immOmHandle), SA_AIS_OK); safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK); safassert(saImmOmFinalize(immOmHandle), SA_AIS_OK); test_validate(rc, SA_AIS_ERR_INVALID_PARAM); }
struct dacp_client_t* dacp_client_create(endpoint_p endpoint, const char* identifier, const char* active_remote) { struct dacp_client_t* dc = (struct dacp_client_t*)object_create(sizeof(struct dacp_client_t), _dacp_client_destroy); dc->endpoint = endpoint_copy(endpoint); endpoint_set_port(dc->endpoint, 3689); dc->identifier = malloc(strlen(identifier) + 1); strcpy(dc->identifier, identifier); dc->active_remove = malloc(strlen(active_remote) + 1); strcpy(dc->active_remove, active_remote); dc->dacp_discover = zeroconf_dacp_discover_create(); zeroconf_dacp_discover_set_callback(dc->dacp_discover, _dacp_client_zeroconf_resolved_callback, dc); dc->playback_state = dacp_client_playback_state_stopped; return dc; }
static Link af_call(Link self, Link This, Link Arg){ // create the structure that will hold the data passed to the new thread struct Async_data * ad = malloc(sizeof(struct Async_data)); ad->This = NULL; ad->Arg = NULL; ad->Self = NULL; // populate the structure if (This) ad->This = link_dup(This); if (Arg) ad->Arg = object_copy(Arg); if (self) ad->Self = link_dup(self); // start the new thread, and return the thread handle thread_t thread_handle = run_async(_run_async , ad); Link thread = object_create(thread_type); thread->value.vptr = malloc(sizeof(thread_t)); *((thread_t *)(thread->value.vptr)) = thread_handle; return thread; }
int tree_objectify (state_t *ur, struct tree *tree, unsigned char sha1[20]) { struct list_elem *e; int od = -1; char buf[50]; if ((od = object_create (ur)) < 0) goto error; sprintf (buf, "%d", (int) list_size (&tree->blob_entries)); writeline (od, buf, strlen (buf), "\n"); for (e = list_begin (&tree->blob_entries); e != list_end (&tree->blob_entries); e = list_next (e)) { struct blob_tree_entry *en = list_entry (e, struct blob_tree_entry, elem); writeline (od, en->name, strlen (en->name), "\n"); sha1_to_hex (en->commit, buf); writeline (od, buf, strlen (buf), "\n"); } sprintf (buf, "%d", (int) list_size (&tree->branch_entries)); writeline (od, buf, strlen (buf), "\n"); for (e = list_begin (&tree->branch_entries); e != list_end (&tree->branch_entries); e = list_next (e)) { struct branch_tree_entry *en = list_entry (e, struct branch_tree_entry, elem); writeline (od, en->name, strlen (en->name), "\n"); writeline (od, en->branch, strlen (en->branch), "\n"); sha1_to_hex (en->commit, buf); writeline (od, buf, strlen (buf), "\n"); } return object_finalize (ur, od, sha1); error: return -1; }
void saImmOmCcbObjectModify_2_20(void) { SaImmHandleT immOmHandle1, immOmHandle2; const SaImmAdminOwnerNameT adminOwnerName1 = (SaImmAdminOwnerNameT) __FUNCTION__; const SaImmAdminOwnerNameT adminOwnerName2 = (SaImmAdminOwnerNameT) __FILE__; SaImmAdminOwnerHandleT ownerHandle1; SaImmAdminOwnerHandleT ownerHandle2; SaImmCcbHandleT ccbHandle1; SaImmCcbHandleT ccbHandle2; const SaNameT obj1 = { strlen("id=1"), "id=1" }; const SaNameT obj2 = { strlen("id=2"), "id=2" }; const SaNameT* attrValues[] = { &obj1 }; SaImmAttrValuesT_2 v1 = { "attr1", SA_IMM_ATTR_SANAMET, 1, (void**)attrValues }; SaImmAttrModificationT_2 attrMod = { SA_IMM_ATTR_VALUES_REPLACE, v1 }; const SaImmAttrModificationT_2 *attrMods[] = { &attrMod, NULL }; safassert(saImmOmInitialize(&immOmHandle1, NULL, &immVersion), SA_AIS_OK); safassert(saImmOmAdminOwnerInitialize(immOmHandle1, adminOwnerName1, SA_TRUE, &ownerHandle1), SA_AIS_OK); safassert(saImmOmInitialize(&immOmHandle2, NULL, &immVersion), SA_AIS_OK); safassert(saImmOmAdminOwnerInitialize(immOmHandle2, adminOwnerName2, SA_TRUE, &ownerHandle2), SA_AIS_OK); safassert(nodangling_class_create(immOmHandle1), SA_AIS_OK); safassert(object_create(immOmHandle2, ownerHandle2, nodanglingClassName, &obj2, NULL, NULL), SA_AIS_OK); safassert(saImmOmCcbInitialize(ownerHandle1, 0, &ccbHandle1), SA_AIS_OK); safassert(saImmOmCcbInitialize(ownerHandle2, 0, &ccbHandle2), SA_AIS_OK); safassert(object_create_2(immOmHandle1, ccbHandle1, nodanglingClassName, &obj1, NULL, NULL), SA_AIS_OK); rc = saImmOmCcbObjectModify_2(ccbHandle2, &obj2, attrMods); safassert(saImmOmCcbFinalize(ccbHandle2), SA_AIS_OK); safassert(saImmOmCcbFinalize(ccbHandle1), SA_AIS_OK); safassert(object_delete(ownerHandle2, &obj2, 1), SA_AIS_OK); safassert(nodangling_class_delete(immOmHandle1), SA_AIS_OK); safassert(saImmOmAdminOwnerFinalize(ownerHandle2), SA_AIS_OK); safassert(saImmOmAdminOwnerFinalize(ownerHandle1), SA_AIS_OK); safassert(saImmOmFinalize(immOmHandle2), SA_AIS_OK); safassert(saImmOmFinalize(immOmHandle1), SA_AIS_OK); test_validate(rc, SA_AIS_ERR_BUSY); }
struct web_headers_t* web_headers_copy(struct web_headers_t* wh) { struct web_headers_t* headers = (struct web_headers_t*)object_create(sizeof(struct web_headers_t), _web_headers_destroy); headers->count = wh->count; headers->headers = (struct web_header_t*)malloc(sizeof(struct web_header_t) * wh->count); for (uint32_t i = 0 ; i < wh->count ; i++) { size_t name_len = strlen(wh->headers[i].name); size_t value_len = strlen(wh->headers[i].value); headers->headers[i].name = malloc(name_len + value_len + 2); headers->headers[i].value = headers->headers[i].name + name_len + 1; strcpy(headers->headers[i].name, wh->headers[i].name); strcpy(headers->headers[i].value, wh->headers[i].value); } return headers; }
int new_image( lua_State* L ) { uiImage* maybecopy = 0; if( lua_isuserdata( L, 1 ) ) { int s; void* p = get_object( L, 1, &s ); if( s == uiImageSignature ) { maybecopy = p; } } uiImage* i = uiNewImage( maybecopy ); if( lua_isstring( L, 1 ) ) { uiImageLoad( i, lua_tostring( L, 1 ) ); } object_create( L, i, uiImageSignature, image_members, 0 ); return 1; }
object_t * object_get_fs_quad(void) { vbuf_fmt_t format = 0; mesh_t *mesh; object_t *object; float verts[] = { -1.0, -1.0, 0.0, 1.0, 1.0, -1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, -1.0, 1.0, 0.0, 1.0, }; uint16_t elems[] = { 0, 1, 2, 3 }; vbuf_fmt_add(&format, "position", 4, GL_FLOAT); mesh = mesh_create(4, verts, 4, elems, format, GL_TRIANGLE_FAN); object = object_create(NULL); object_set_mesh(object, mesh); mesh_ungrab(mesh); return object; }
static NATIVECALL(file_stream){ Link * args = array_getArray(Arg); size_t argn = array_getLength(Arg); string_t type = file_stream_def_type; string_t name = NULL; mode_t mode = 0666; switch (argn){ case 3: mode = object_asNumber( args[2] ); case 2: type = object_getString( args[1] ); case 1: name = object_getString( args[0] ); break; default: return exception("FileNameRequired", NULL, NULL); } Link link = object_create(stream_type); link->value.vptr = stream_open_file(name->data , type->data, mode); return link; }
static void saImmOmLongDn_04(void) { SaImmHandleT immHandle; SaImmAdminOwnerHandleT ownerHandle; SaImmCcbHandleT ccbHandle; SaAisErrorT rc; SaNameT dn; const SaImmAdminOwnerNameT ownerName = (const SaImmAdminOwnerNameT)__FUNCTION__; SaImmAttrValueT attrValues[1] = { &dn }; SaImmAttrModificationT_2 attrMod = { SA_IMM_ATTR_VALUES_REPLACE, { "attr8", SA_IMM_ATTR_SANAMET, 1, attrValues }}; const SaImmAttrModificationT_2 *attrMods[2] = { &attrMod, NULL }; safassert(saImmOmInitialize(&immHandle, NULL, &immVersion), SA_AIS_OK); config_class_create(immHandle); safassert(saImmOmAdminOwnerInitialize(immHandle, ownerName, SA_TRUE, &ownerHandle), SA_AIS_OK); osaf_extended_name_lend(longDn, &dn); safassert(object_create(immHandle, ownerHandle, configClassName, &dn, NULL, NULL), SA_AIS_OK); safassert(saImmOmCcbInitialize(ownerHandle, 0, &ccbHandle), SA_AIS_OK); rc = saImmOmCcbObjectModify_2(ccbHandle, &dn, attrMods); saImmOmCcbApply(ccbHandle); safassert(saImmOmCcbFinalize(ccbHandle), SA_AIS_OK); safassert(object_delete(ownerHandle, &dn, 1), SA_AIS_OK); config_class_delete(immHandle); safassert(saImmOmAdminOwnerFinalize(ownerHandle), SA_AIS_OK); safassert(saImmOmFinalize(immHandle), SA_AIS_OK); test_validate(rc, SA_AIS_OK); }
static NATIVECALL(bwindow_new){ BWindow self = malloc(sizeof(*self)); self->items = im_new(); self->width = 500; self->height = 500; self->title = NULL; self->x = self->y = 0; self->clear_color[0] = 1; self->clear_color[1] = 1; self->clear_color[2] = 1; self->clear_color[3] = 1; self->bindings = NULL; self->update = 0; self->onClose = NULL; self->onKeyDown = NULL; self->onKeyUp = NULL; Link obj = object_create(window_type); obj->value.vptr = self; bwindow_create(obj); return obj; }
uint8_t dm_handleRequest(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, lwm2m_server_t * serverP, coap_packet_t * message, coap_packet_t * response) { uint8_t result; lwm2m_media_type_t format; LOG_ARG("Code: %02X, server status: %s", message->code, STR_STATUS(serverP->status)); LOG_URI(uriP); if (IS_OPTION(message, COAP_OPTION_CONTENT_TYPE)) { format = utils_convertMediaType(message->content_type); } else { format = LWM2M_CONTENT_TLV; } if (uriP->objectId == LWM2M_SECURITY_OBJECT_ID) { return COAP_404_NOT_FOUND; } if (serverP->status != STATE_REGISTERED && serverP->status != STATE_REG_UPDATE_NEEDED && serverP->status != STATE_REG_FULL_UPDATE_NEEDED && serverP->status != STATE_REG_UPDATE_PENDING) { return COAP_IGNORE; } // TODO: check ACL switch (message->code) { case COAP_GET: { uint8_t * buffer = NULL; size_t length = 0; int res; if (IS_OPTION(message, COAP_OPTION_OBSERVE)) { lwm2m_data_t * dataP = NULL; int size = 0; result = object_readData(contextP, uriP, &size, &dataP); if (COAP_205_CONTENT == result) { result = observe_handleRequest(contextP, uriP, serverP, size, dataP, message, response); if (COAP_205_CONTENT == result) { if (IS_OPTION(message, COAP_OPTION_ACCEPT)) { format = utils_convertMediaType(message->accept[0]); } else { format = LWM2M_CONTENT_TLV; } res = lwm2m_data_serialize(uriP, size, dataP, &format, &buffer); if (res < 0) { result = COAP_500_INTERNAL_SERVER_ERROR; } else { length = (size_t)res; LOG_ARG("Observe Request[/%d/%d/%d]: %.*s\n", uriP->objectId, uriP->instanceId, uriP->resourceId, length, buffer); } } lwm2m_data_free(size, dataP); } } else if (IS_OPTION(message, COAP_OPTION_ACCEPT) && message->accept_num == 1 && message->accept[0] == APPLICATION_LINK_FORMAT) { format = LWM2M_CONTENT_LINK; result = object_discover(contextP, uriP, serverP, &buffer, &length); } else { if (IS_OPTION(message, COAP_OPTION_ACCEPT)) { format = utils_convertMediaType(message->accept[0]); } result = object_read(contextP, uriP, &format, &buffer, &length); } if (COAP_205_CONTENT == result) { coap_set_header_content_type(response, format); coap_set_payload(response, buffer, length); // lwm2m_handle_packet will free buffer } else { lwm2m_free(buffer); } } break; case COAP_POST: { if (!LWM2M_URI_IS_SET_INSTANCE(uriP)) { result = object_create(contextP, uriP, format, message->payload, message->payload_len); if (result == COAP_201_CREATED) { //longest uri is /65535/65535 = 12 + 1 (null) chars char location_path[13] = ""; //instanceId expected if ((uriP->flag & LWM2M_URI_FLAG_INSTANCE_ID) == 0) { result = COAP_500_INTERNAL_SERVER_ERROR; break; } if (sprintf(location_path, "/%d/%d", uriP->objectId, uriP->instanceId) < 0) { result = COAP_500_INTERNAL_SERVER_ERROR; break; } coap_set_header_location_path(response, location_path); lwm2m_update_registration(contextP, 0, true); } } else if (!LWM2M_URI_IS_SET_RESOURCE(uriP)) { result = object_write(contextP, uriP, format, message->payload, message->payload_len); } else { result = object_execute(contextP, uriP, message->payload, message->payload_len); } } break; case COAP_PUT: { if (IS_OPTION(message, COAP_OPTION_URI_QUERY)) { lwm2m_attributes_t attr; if (0 != prv_readAttributes(message->uri_query, &attr)) { result = COAP_400_BAD_REQUEST; } else { result = observe_setParameters(contextP, uriP, serverP, &attr); } } else if (LWM2M_URI_IS_SET_INSTANCE(uriP)) { result = object_write(contextP, uriP, format, message->payload, message->payload_len); } else { result = COAP_400_BAD_REQUEST; } } break; case COAP_DELETE: { if (!LWM2M_URI_IS_SET_INSTANCE(uriP) || LWM2M_URI_IS_SET_RESOURCE(uriP)) { result = COAP_400_BAD_REQUEST; } else { result = object_delete(contextP, uriP); if (result == COAP_202_DELETED) { lwm2m_update_registration(contextP, 0, true); } } } break; default: result = COAP_400_BAD_REQUEST; break; } return result; }
static NATIVECALL(streamserver_accept){ StreamServer ss = This->value.vptr; Link link = object_create(stream_type); link->value.vptr = stream_open_accept(ss); return link; }
static NATIVECALL(stdio_stream){ Link link = object_create(stream_type); link->value.vptr = stream_open_stdio(); return link; }
coap_status_t handle_bootstrap_command(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, lwm2m_server_t * serverP, coap_packet_t * message, coap_packet_t * response) { coap_status_t result; lwm2m_media_type_t format; format = prv_convertMediaType(message->content_type); result = prv_check_server_status(serverP); if (result != COAP_NO_ERROR) return result; switch (message->code) { case COAP_PUT: { if (LWM2M_URI_IS_SET_INSTANCE(uriP)) { if (object_isInstanceNew(contextP, uriP->objectId, uriP->instanceId)) { result = object_create(contextP, uriP, format, message->payload, message->payload_len); if (COAP_201_CREATED == result) { result = COAP_204_CHANGED; } } else { result = object_write(contextP, uriP, format, message->payload, message->payload_len); if (uriP->objectId == LWM2M_SECURITY_OBJECT_ID && result == COAP_204_CHANGED) { prv_tag_server(contextP, uriP->instanceId); } } } else { result = BAD_REQUEST_4_00; } } break; case COAP_DELETE: { if (LWM2M_URI_IS_SET_RESOURCE(uriP)) { result = BAD_REQUEST_4_00; } else { result = object_delete(contextP, uriP); if (uriP->objectId == LWM2M_SECURITY_OBJECT_ID && result == COAP_202_DELETED) { if (LWM2M_URI_IS_SET_INSTANCE(uriP)) { prv_tag_server(contextP, uriP->instanceId); } else { prv_tag_all_servers(contextP, NULL); } } } } break; case COAP_GET: case COAP_POST: default: result = BAD_REQUEST_4_00; break; } if (result == COAP_202_DELETED || result == COAP_204_CHANGED) { if (serverP->status != STATE_BS_PENDING) { serverP->status = STATE_BS_PENDING; contextP->state = STATE_BOOTSTRAPPING; } } return result; }
static NATIVECALL(mutex_new_native){ Link link = object_create(mutex_type); link->value.vptr = mutex_new(); return link; }
int main(int argc, char** argv) { struct character_t me, orc; char name[NAME_MAX]; sprintf(name, "Metiscus"); char* username = getenv("USER"); if(username) { if(isalpha(username[0])) { username[0] = toupper(username[0]); } sprintf(name, "%s", username); } char_create(&orc, "Munkres", R_Human); orc.skills[SK_Concentration] = 10; orc.weapon_id = 2; // bo staff char_add_inventory(&orc, object_create(5)); char_create(&me, name, R_Elf); me.weapon_id = 1; // katana me.skills[SK_Blade] = 10; srand(time(0)); int j; int meWins = 0; int trials = 1000; for(j=0; j<trials; ++j) { me.vitals.value[0] = me.vitals.max[0]; orc.vitals.value[0] = orc.vitals.max[0]; for( ; ; ) { //printf("Me: %d\tOrc: %d\n", me.vitals.value[0], orc.vitals.value[0]); combat_round(&me, &orc); // If the ORC health is near critical have him chug a potion unsigned criticalHealth = orc.vitals.max[0] / 2 + 1; unsigned canAttack = 1; if((orc.vitals.value[0] <= criticalHealth) && (orc.inventory_count > 0)) { // look for a potion to use unsigned item = 0; for(item=0; item<orc.inventory_count; ++item) { struct object_t *pObj = orc.inventory[item]; if(pObj->type == obj_consumable && pObj->consumable.type == con_potion) { // we have a potion // Check for charges and then use it! if(pObj->consumable.charge_qty > 0) { char_consumable_apply(&orc, pObj); canAttack = 0; break; } } } } if(canAttack) { combat_round(&orc, &me); } if(me.vitals.value[0]<=0 || orc.vitals.value[0]<=0) { meWins += (me.vitals.value[0]<=0) ? 0 : 1; printf("Battle complete!\n"); if(me.vitals.value[0]>0) { char_add_inventory(&orc, object_create(1)); } break; } } //printf("Me: %d\tOrc: %d\n", me.vitals.value[0], orc.vitals.value[0]); } char_explain(&me); char_explain(&orc); printf("Final result: me %d, Orc %d\n", meWins, trials - meWins); test_resourcemgr(); return 0; }
int main(int argc, char *argv[]) { object_t o1, o2, o3; struct my_msg msg; int error; printf("IPC test program\n"); /* * Create two objects. */ error = object_create("test-A", &o1); error = object_create("test-B", &o2); /* * Create existing object. * This must be error. */ error = object_create("test-B", &o3); if (error == 0) panic("Oops! object exist..."); /* * Start sender thread. */ error = thread_run(send_thread, stack + 1024); if (error) panic("failed to run thread"); /* * Wait message from non-existing object * This must be error. */ o3 = 0x12345678; error = msg_receive(o3, &msg, sizeof(msg)); if (error == 0) panic("Oops! invalid object..."); /* * Wait message from object 'A'. However, it will be failed * because the sender thread will delete the object A. */ printf("Wait message from object A\n"); error = msg_receive(o1, &msg, sizeof(msg)); if (error) printf("Receive error!\n"); else { printf("Rreceive ok!\n"); msg_reply(o1, &msg, sizeof(msg)); } /* * Wait message from object 'B'. */ printf("Wait message from object B\n"); error = msg_receive(o2, &msg, sizeof(msg)); if (error) printf("Receive error!\n"); else { printf("Receive ok!\n"); msg_reply(o2, &msg, sizeof(msg)); } printf("%s\n", msg.data); printf("%d\n", msg.hdr.code); printf("Test completed...\n"); return 0; }
uint8_t bootstrap_handleCommand(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, lwm2m_server_t * serverP, coap_packet_t * message, coap_packet_t * response) { uint8_t result; lwm2m_media_type_t format; LOG_ARG("Code: %02X", message->code); LOG_URI(uriP); format = utils_convertMediaType(message->content_type); result = prv_checkServerStatus(serverP); if (result != COAP_NO_ERROR) return result; switch (message->code) { case COAP_PUT: { if (LWM2M_URI_IS_SET_INSTANCE(uriP)) { if (object_isInstanceNew(contextP, uriP->objectId, uriP->instanceId)) { result = object_create(contextP, uriP, format, message->payload, message->payload_len); if (COAP_201_CREATED == result) { result = COAP_204_CHANGED; } } else { result = object_write(contextP, uriP, format, message->payload, message->payload_len); if (uriP->objectId == LWM2M_SECURITY_OBJECT_ID && result == COAP_204_CHANGED) { prv_tagServer(contextP, uriP->instanceId); } } } else { lwm2m_data_t * dataP = NULL; int size = 0; int i; if (message->payload_len == 0 || message->payload == 0) { result = COAP_400_BAD_REQUEST; } else { size = lwm2m_data_parse(uriP, message->payload, message->payload_len, format, &dataP); if (size == 0) { result = COAP_500_INTERNAL_SERVER_ERROR; break; } for (i = 0 ; i < size ; i++) { if(dataP[i].type == LWM2M_TYPE_OBJECT_INSTANCE) { if (object_isInstanceNew(contextP, uriP->objectId, dataP[i].id)) { result = object_createInstance(contextP, uriP, &dataP[i]); if (COAP_201_CREATED == result) { result = COAP_204_CHANGED; } } else { result = object_writeInstance(contextP, uriP, &dataP[i]); if (uriP->objectId == LWM2M_SECURITY_OBJECT_ID && result == COAP_204_CHANGED) { prv_tagServer(contextP, dataP[i].id); } } if(result != COAP_204_CHANGED) // Stop object create or write when result is error { break; } } else { result = COAP_400_BAD_REQUEST; } } lwm2m_data_free(size, dataP); } } } break; case COAP_DELETE: { if (LWM2M_URI_IS_SET_RESOURCE(uriP)) { result = COAP_400_BAD_REQUEST; } else { result = object_delete(contextP, uriP); if (uriP->objectId == LWM2M_SECURITY_OBJECT_ID && result == COAP_202_DELETED) { if (LWM2M_URI_IS_SET_INSTANCE(uriP)) { prv_tagServer(contextP, uriP->instanceId); } else { prv_tagAllServer(contextP, NULL); } } } } break; case COAP_GET: case COAP_POST: default: result = COAP_400_BAD_REQUEST; break; } if (result == COAP_202_DELETED || result == COAP_204_CHANGED) { if (serverP->status != STATE_BS_PENDING) { serverP->status = STATE_BS_PENDING; contextP->state = STATE_BOOTSTRAPPING; } } LOG_ARG("Server status: %s", STR_STATUS(serverP->status)); return result; }
/* * Main routine for power server. */ int main(int argc, char *argv[]) { static struct msg msg; const struct msg_map *map; object_t obj; struct bind_msg bm; object_t execobj, procobj; int error; sys_log("Starting power server\n"); /* Boost thread priority. */ thread_setpri(thread_self(), PRI_POW); /* * Wait until all required system servers * become available. */ wait_server("!proc", &procobj); wait_server("!exec", &execobj); /* * Request to bind a new capabilities for us. */ bm.hdr.code = EXEC_BINDCAP; strlcpy(bm.path, "/boot/pow", sizeof(bm.path)); msg_send(execobj, &bm, sizeof(bm)); /* * Register to process server */ register_process(); /* * Initialize power service. */ pow_init(); /* * Create an object to expose our service. */ error = object_create("!pow", &obj); if (error) sys_panic("fail to create object"); /* * Message loop */ for (;;) { /* * Wait for an incoming request. */ error = msg_receive(obj, &msg, sizeof(msg)); if (error) continue; DPRINTF(("pow: msg code=%x task=%x\n", msg.hdr.code, msg.hdr.task)); /* Check client's capability. */ if (task_chkcap(msg.hdr.task, CAP_POWERMGMT) != 0) { map = NULL; error = EPERM; } else { error = EINVAL; map = &powermsg_map[0]; while (map->code != 0) { if (map->code == msg.hdr.code) { error = (*map->func)(&msg); break; } map++; } } /* * Reply to the client. */ msg.hdr.status = error; msg_reply(obj, &msg, sizeof(msg)); #ifdef DEBUG_POWER if (map != NULL && error != 0) DPRINTF(("pow: msg code=%x error=%d\n", map->code, error)); #endif } }
int cutscene_create(scene *scene) { cutscene_local *local = malloc(sizeof(cutscene_local)); game_player *p1 = game_state_get_player(scene->gs, 0); const char *text = ""; switch (scene->id) { case SCENE_END: cutscene_music(PSM_END); text = lang_get(END_TEXT); local->text_x = 10; local->text_y = 5; local->text_width = 300; local->color = COLOR_YELLOW; break; case SCENE_END1: text = lang_get(END1_TEXT+p1->pilot_id); local->text_x = 10; local->text_y = 160; local->text_width = 300; local->color = COLOR_RED; // Pilot face animation *ani = &bk_get_info(&scene->bk_data, 3)->ani; object *obj = malloc(sizeof(object)); object_create(obj, scene->gs, vec2i_create(0,0), vec2f_create(0, 0)); object_set_animation(obj, ani); object_select_sprite(obj, p1->pilot_id); obj->halt=1; game_state_add_object(scene->gs, obj, RENDER_LAYER_TOP); // Face effects ani = &bk_get_info(&scene->bk_data, 10+p1->pilot_id)->ani; obj = malloc(sizeof(object)); object_create(obj, scene->gs, vec2i_create(0,0), vec2f_create(0, 0)); object_set_animation(obj, ani); game_state_add_object(scene->gs, obj, RENDER_LAYER_TOP); break; case SCENE_END2: text = lang_get(END2_TEXT+p1->pilot_id); local->text_x = 10; local->text_y = 160; local->text_width = 300; local->color = COLOR_GREEN; break; } local->len = strlen(text)-1; local->pos = 0; local->text = malloc(strlen(text)+1); strcpy(local->text, text); local->current = local->text; char *p; if ((p = strchr(local->text, '\n'))) { // null out the byte *p = '\0'; } // Callbacks scene_set_userdata(scene, local); scene_set_free_cb(scene, cutscene_free); scene_set_event_cb(scene, cutscene_event); scene_set_startup_cb(scene, cutscene_startup); scene_set_render_overlay_cb(scene, cutscene_render_overlay); // Pick renderer video_select_renderer(VIDEO_RENDERER_HW); return 0; }
static NATIVECALL(dict_create){ return object_create(dict_type); };
static NATIVECALL(mutex_unlock_native){ mutex_unlock(This->value.vptr); return object_create(Global->null_type); }
static NATIVECALL(make_async){ Link * args = array_getArray(Arg); Link self = object_create(asyncfunc_type); self->value.vptr = link_dup(args[0]); return self; }
// Init mechlab int mechlab_create(scene *scene) { // Alloc mechlab_local *local = malloc(sizeof(mechlab_local)); memset(local, 0, sizeof(mechlab_local)); animation *bg_ani[3]; // Init the background for(int i = 0; i < sizeof(bg_ani)/sizeof(animation*); i++) { sprite *spr = sprite_copy(animation_get_sprite(&bk_get_info(&scene->bk_data, 14)->ani, i)); bg_ani[i] = create_animation_from_single(spr, spr->pos); object_create(&local->bg_obj[i], scene->gs, vec2i_create(0,0), vec2f_create(0,0)); object_set_animation(&local->bg_obj[i], bg_ani[i]); object_select_sprite(&local->bg_obj[i], 0); object_set_repeat(&local->bg_obj[i], 1); object_set_animation_owner(&local->bg_obj[i], OWNER_OBJECT); } // Find last saved game ... game_player *p1 = game_state_get_player(scene->gs, 0); const char* last_name = settings_get()->tournament.last_name; if(last_name == NULL || strlen(last_name) == 0) { last_name = NULL; } // ... and attempt to load it, if one was found. if(last_name != NULL) { int ret = sg_load(&p1->pilot, last_name); if(ret != SD_SUCCESS) { PERROR("Could not load saved game for playername '%s': %s!", last_name, sd_get_error(ret)); last_name = NULL; } else { DEBUG("Loaded savegame for playername '%s'.", last_name); } } // Either initialize a new tournament if no savegame is found, // or just show old savegame stats directly if it was. local->dashtype = DASHBOARD_NONE; if(last_name == NULL) { DEBUG("No previous savegame found"); } else { DEBUG("Previous savegame found; loading as default."); } mechlab_select_dashboard(scene, local, DASHBOARD_STATS); // Create main menu local->frame = guiframe_create(0, 0, 320, 200); guiframe_set_root(local->frame, lab_menu_main_create(scene)); guiframe_layout(local->frame); // Load HAR animation *initial_har_ani = &bk_get_info(&scene->bk_data, 15 + p1->pilot.har_id)->ani; local->mech = malloc(sizeof(object)); object_create(local->mech, scene->gs, vec2i_create(0,0), vec2f_create(0,0)); object_set_animation(local->mech, initial_har_ani); object_set_repeat(local->mech, 1); object_dynamic_tick(local->mech); // Set callbacks scene_set_userdata(scene, local); scene_set_input_poll_cb(scene, mechlab_input_tick); scene_set_event_cb(scene, mechlab_event); scene_set_render_cb(scene, mechlab_render); scene_set_free_cb(scene, mechlab_free); scene_set_dynamic_tick_cb(scene, mechlab_tick); // Pick renderer video_select_renderer(VIDEO_RENDERER_HW); return 0; }
int vs_create(scene *scene) { // Init local data vs_local *local = malloc(sizeof(vs_local)); scene_set_userdata(scene, local); game_player *player1 = game_state_get_player(scene->gs, 0); game_player *player2 = game_state_get_player(scene->gs, 1); snprintf(local->vs_str, 128, "%s VS. %s", lang_get(20+player1->pilot_id), lang_get(20+player2->pilot_id)); animation *ani; palette *mpal = video_get_base_palette(); palette_set_player_color(mpal, 0, player1->colors[2], 0); palette_set_player_color(mpal, 0, player1->colors[1], 1); palette_set_player_color(mpal, 0, player1->colors[0], 2); palette_set_player_color(mpal, 1, player2->colors[2], 0); palette_set_player_color(mpal, 1, player2->colors[1], 1); palette_set_player_color(mpal, 1, player2->colors[0], 2); video_force_pal_refresh(); // HAR ani = &bk_get_info(&scene->bk_data, 5)->ani; object_create(&local->player1_har, scene->gs, vec2i_create(160,0), vec2f_create(0, 0)); object_set_animation(&local->player1_har, ani); object_select_sprite(&local->player1_har, player1->har_id); object_create(&local->player2_har, scene->gs, vec2i_create(160,0), vec2f_create(0, 0)); object_set_animation(&local->player2_har, ani); object_select_sprite(&local->player2_har, player2->har_id); object_set_direction(&local->player2_har, OBJECT_FACE_LEFT); object_set_pal_offset(&local->player2_har, 48); // PLAYER ani = &bk_get_info(&scene->bk_data, 4)->ani; object_create(&local->player1_portrait, scene->gs, vec2i_create(-10,150), vec2f_create(0, 0)); object_set_animation(&local->player1_portrait, ani); object_select_sprite(&local->player1_portrait, player1->pilot_id); object_create(&local->player2_portrait, scene->gs, vec2i_create(330,150), vec2f_create(0, 0)); object_set_animation(&local->player2_portrait, ani); object_select_sprite(&local->player2_portrait, player2->pilot_id); object_set_direction(&local->player2_portrait, OBJECT_FACE_LEFT); // clone the left side of the background image // Note! We are touching the scene-wide background surface! surface_sub(&scene->bk_data.background, // DST Surface &scene->bk_data.background, // SRC Surface 160, 0, // DST 0, 0, // SRC 160, 200, // Size SUB_METHOD_MIRROR); // Flip the right side horizontally if (player2->selectable) { // player1 gets to choose, start at arena 0 local->arena = 0; } else { // pick a random arena for 1 player mode local->arena = rand_int(5); // srand was done in melee } // Arena if(player2->selectable) { ani = &bk_get_info(&scene->bk_data, 3)->ani; object_create(&local->arena_select, scene->gs, vec2i_create(59,155), vec2f_create(0, 0)); object_set_animation(&local->arena_select, ani); object_select_sprite(&local->arena_select, local->arena); } // SCIENTIST int scientistpos = rand_int(4); vec2i scientistcoord = spawn_position(scientistpos, 1); if (scientistpos % 2) { scientistcoord.x += 50; } else { scientistcoord.x -= 50; } object *o_scientist = malloc(sizeof(object)); ani = &bk_get_info(&scene->bk_data, 8)->ani; object_create(o_scientist, scene->gs, scientistcoord, vec2f_create(0, 0)); object_set_animation(o_scientist, ani); object_select_sprite(o_scientist, 0); object_set_direction(o_scientist, scientistpos % 2 ? OBJECT_FACE_LEFT : OBJECT_FACE_RIGHT); game_state_add_object(scene->gs, o_scientist, RENDER_LAYER_MIDDLE, 0, 0); // WELDER int welderpos = rand_int(6); // welder can't be on the same gantry or the same *side* as the scientist // he also can't be on the same 'level' // but he has 10 possible starting positions while ((welderpos % 2) == (scientistpos % 2) || (scientistpos < 2 && welderpos < 2) || (scientistpos > 1 && welderpos > 1 && welderpos < 4)) { welderpos = rand_int(6); } object *o_welder = malloc(sizeof(object)); ani = &bk_get_info(&scene->bk_data, 7)->ani; object_create(o_welder, scene->gs, spawn_position(welderpos, 0), vec2f_create(0, 0)); object_set_animation(o_welder, ani); object_select_sprite(o_welder, 0); object_set_spawn_cb(o_welder, cb_vs_spawn_object, (void*)scene); object_set_destroy_cb(o_welder, cb_vs_destroy_object, (void*)scene); object_set_direction(o_welder, welderpos % 2 ? OBJECT_FACE_LEFT : OBJECT_FACE_RIGHT); game_state_add_object(scene->gs, o_welder, RENDER_LAYER_MIDDLE, 0, 0); // GANTRIES object *o_gantry_a = malloc(sizeof(object)); ani = &bk_get_info(&scene->bk_data, 11)->ani; object_create(o_gantry_a, scene->gs, vec2i_create(0,0), vec2f_create(0, 0)); object_set_animation(o_gantry_a, ani); object_select_sprite(o_gantry_a, 0); game_state_add_object(scene->gs, o_gantry_a, RENDER_LAYER_TOP, 0, 0); object *o_gantry_b = malloc(sizeof(object)); object_create(o_gantry_b, scene->gs, vec2i_create(320,0), vec2f_create(0, 0)); object_set_animation(o_gantry_b, ani); object_select_sprite(o_gantry_b, 0); object_set_direction(o_gantry_b, OBJECT_FACE_LEFT); game_state_add_object(scene->gs, o_gantry_b, RENDER_LAYER_TOP, 0, 0); // Background tex menu_background2_create(&local->arena_select_bg, 211, 50); // Quit Dialog dialog_create(&local->quit_dialog, DIALOG_STYLE_YES_NO, "ARE YOU SURE YOU WANT TO QUIT THIS GAME?", 72, 60); local->quit_dialog.userdata = scene; local->quit_dialog.clicked = vs_quit_dialog_clicked; // Too Pathetic Dialog char insult[512]; snprintf(insult, 512, lang_get(748), "Veteran", "Major Kreissack"); dialog_create(&local->too_pathetic_dialog, DIALOG_STYLE_OK, insult, 72, 60); local->too_pathetic_dialog.userdata = scene; local->too_pathetic_dialog.clicked = vs_too_pathetic_dialog_clicked; if (player2->pilot_id == 10 && settings_get()->gameplay.difficulty < 2) { // kriessack, but not on Veteran or higher dialog_show(&local->too_pathetic_dialog, 1); } // Callbacks scene_set_render_cb(scene, vs_render); scene_set_render_overlay_cb(scene, vs_render_overlay); scene_set_input_poll_cb(scene, vs_input_tick); scene_set_dynamic_tick_cb(scene, vs_dynamic_tick); scene_set_static_tick_cb(scene, vs_static_tick); scene_set_free_cb(scene, vs_free); // Pick renderer video_select_renderer(VIDEO_RENDERER_HW); return 0; }
static NATIVECALL(thread_join){ thread_t thread_handle = *((thread_t *)(This->value.vptr)); join_async(thread_handle); return object_create(Global->null_type); }