Exemple #1
0
void TAO::PG_Group_Factory::delete_group (
  PortableGroup::ObjectGroupId group_id)
{
  if (! destroy_group (group_id))
  {
    throw PortableGroup::ObjectNotFound ();
  }
}
Exemple #2
0
void TAO::PG_Group_Factory::delete_group (
  PortableGroup::ObjectGroup_ptr object_group)
{
  if (! destroy_group (object_group))
  {
    throw PortableGroup::ObjectNotFound ();
  }
}
Exemple #3
0
TEST(core, send_to_invalid_address)
{
    ::dsn::rpc_address group = build_group();
    /* here we assume 10.255.254.253:32766 is not assigned */
    dsn_group_set_leader(group.group_handle(), ::dsn::rpc_address("10.255.254.253", 32766).c_addr());

    rpc_reply_handler action_on_succeed = [](error_code, dsn_message_t, dsn_message_t resp) {
        std::string hehe_str;
        ::unmarshall(resp, hehe_str);
        EXPECT_TRUE(hehe_str == "hehehe");
    };
    rpc_reply_handler action_on_failure = [](error_code err, dsn_message_t, dsn_message_t) {
        EXPECT_TRUE(err != ERR_OK);
    };

    send_message(group, std::string("echo hehehe"), 10, action_on_succeed, action_on_failure);
    destroy_group(group);
}
Exemple #4
0
TEST(core, group_address_no_response_2)
{
    ::dsn::rpc_address addr = build_group();
    rpc_reply_handler action_on_succeed = [](error_code, dsn_message_t, dsn_message_t resp) {
        std::string result;
        ::unmarshall(resp, result);
        ::dsn::rpc_address a = dsn_address_from_string(result);
        EXPECT_TRUE(a.port()==TEST_PORT_END);
    };

    rpc_reply_handler action_on_failure = [](error_code err, dsn_message_t req, dsn_message_t) {
        if (err==ERR_TIMEOUT) {
            EXPECT_TRUE( ((dsn::message_ex*)req)->to_address.port()!=TEST_PORT_END );
        }
    };

    send_message(addr, std::string("expect_no_reply"), 10, action_on_succeed, action_on_failure);
    destroy_group(addr);
}
Exemple #5
0
TEST(core, group_address_change_leader)
{
    ::dsn::rpc_address addr = build_group();

    error_code rpc_err;
    auto typed_callback =
            [addr, &rpc_err](error_code err_code, const std::string& result)->void {
        rpc_err = err_code;
        if (ERR_OK == err_code)
        {
            ::dsn::rpc_address addr_got;
            ddebug("talk to others callback, result: %s", result.c_str());
            EXPECT_TRUE(addr_got.from_string_ipv4(result.c_str()));
            EXPECT_EQ(TEST_PORT_END, addr_got.port());
        }
    };

    ::dsn::task_ptr resp_task;

    // not update leader on forwarding
    addr.group_address()->set_update_leader_automatically(false);
    dsn_group_set_leader(addr.group_handle(), ::dsn::rpc_address("localhost", TEST_PORT_BEGIN).c_addr());
    resp_task = ::dsn::rpc::call(addr, dsn_task_code_t(RPC_TEST_STRING_COMMAND), std::string("expect_talk_to_others"),
                                 nullptr, typed_callback);
    resp_task->wait();
    if (rpc_err == ERR_OK)
    {
        EXPECT_EQ(::dsn::rpc_address("localhost", TEST_PORT_BEGIN), ::dsn::rpc_address(dsn_group_get_leader(addr.group_handle())));
    }
    // update leader on forwarding
    addr.group_address()->set_update_leader_automatically(true);
    dsn_group_set_leader(addr.group_handle(), ::dsn::rpc_address("localhost", TEST_PORT_BEGIN).c_addr());
    resp_task = ::dsn::rpc::call(addr, dsn_task_code_t(RPC_TEST_STRING_COMMAND), std::string("expect_talk_to_others"),
                                 nullptr, typed_callback);
    resp_task->wait();
    ddebug("addr.leader=%s", ::dsn::rpc_address(dsn_group_get_leader(addr.group_handle())).to_string());
    if (rpc_err == ERR_OK)
    {
        EXPECT_EQ(TEST_PORT_END, ::dsn::rpc_address(dsn_group_get_leader(addr.group_handle())).port());
    }
    destroy_group(addr);
}
Exemple #6
0
void merge_group(struct group *group, struct group *child)
{
    struct groupdata *groupdata = group->data;
    struct groupdata *childdata = child->data;

    for (size_t i = 0; i < ptrarray_count(childdata->blocks); ++i)
    {
        struct block *copy = copy_block(get_ptrarray(childdata->blocks, i));
        translate_block(copy, &child->position);
        push_ptrarray(groupdata->blocks, copy);
    }

    for (size_t i = 0; i < ptrarray_count(childdata->groups); ++i)
    {
        struct group *copy = copy_group(get_ptrarray(childdata->groups, i));
        vec3_add(&copy->position, &copy->position, &child->position);
        insert_group(group, copy);
    }

    destroy_group(child);
    update_group_vertexarray(group);
}
Exemple #7
0
static void release_groupdata(struct groupdata *groupdata)
{
    if (groupdata && --groupdata->refcount == 0)
    {
        size_t blockcount = ptrarray_count(groupdata->blocks);
        for (size_t i = 0; i < blockcount; ++i)
        {
            destroy_block(get_ptrarray(groupdata->blocks, i));
        }

        size_t groupcount = ptrarray_count(groupdata->groups);
        for (size_t i = 0; i < groupcount; ++i)
        {
            destroy_group(get_ptrarray(groupdata->groups, i));
        }

        destroy_ptrarray(groupdata->blocks);
        destroy_ptrarray(groupdata->groups);
        destroy_buffer(groupdata->vertices);

        free(groupdata);
    }
}
Exemple #8
0
TEST(core, group_address_talk_to_others)
{
    ::dsn::rpc_address addr = build_group();

    auto typed_callback =
            [addr](error_code err_code, const std::string& result) {
        EXPECT_EQ(ERR_OK, err_code);
        ::dsn::rpc_address addr_got;
        ddebug("talk to others callback, result: %s", result.c_str());
        EXPECT_TRUE(addr_got.from_string_ipv4(result.c_str()));
        EXPECT_EQ(TEST_PORT_END, addr_got.port());
    };

    std::vector<task_ptr> resp_tasks;
    for (unsigned int i=0; i<10; ++i) {
         ::dsn::task_ptr resp_task = ::dsn::rpc::call(addr, dsn_task_code_t(RPC_TEST_STRING_COMMAND), std::string("expect_talk_to_others"),
                                          nullptr, typed_callback);
         resp_tasks.push_back(resp_task);
    }

    for (unsigned int i=0; i<10; ++i)
        resp_tasks[i]->wait();
    destroy_group(addr);
}
Exemple #9
0
int TAO::PG_Group_Factory::destroy_group (PortableGroup::ObjectGroup_ptr object_group)
{
  PortableGroup::TagGroupTaggedComponent tc;
  TAO::PG_Utils::get_tagged_component (object_group, tc);
  return destroy_group (tc.object_group_id);
}
Exemple #10
0
int cfg_read(Cfg *cfg) 
{ 
    CfgLoc *loc; 
    CfgLoc *loc_inc; 
    List *lines;
    List *expand; 
    List *stack; 
    Octstr *name;
    Octstr *value;
    Octstr *filename; 
    CfgGroup *grp;
    long equals;
    long lineno;
    long error_lineno;
    
    loc = loc_inc = NULL;

    /* 
     * expand initial main config file and add it to the recursion 
     * stack to protect against cycling 
     */ 
    if ((lines = expand_file(cfg->filename, 1)) == NULL) { 
        panic(0, "Failed to load main configuration file `%s'. Aborting!", 
              octstr_get_cstr(cfg->filename)); 
    } 
    stack = gwlist_create(); 
    gwlist_insert(stack, 0, octstr_duplicate(cfg->filename)); 

    grp = NULL;
    lineno = 0;
    error_lineno = 0;
    while (error_lineno == 0 && (loc = gwlist_extract_first(lines)) != NULL) { 
        octstr_strip_blanks(loc->line); 
        if (octstr_len(loc->line) == 0) { 
            if (grp != NULL && add_group(cfg, grp) == -1) { 
                error_lineno = loc->line_no; 
                destroy_group(grp); 
            } 
            grp = NULL; 
        } else if (octstr_get_char(loc->line, 0) != '#') { 
            equals = octstr_search_char(loc->line, '=', 0); 
            if (equals == -1) { 
                error(0, "An equals sign ('=') is missing on line %ld of file %s.", 
                      loc->line_no, octstr_get_cstr(loc->filename)); 
                error_lineno = loc->line_no; 
            } else  
             
            /* 
             * check for special config directives, like include or conditional 
             * directives here 
             */ 
            if (octstr_search(loc->line, octstr_imm("include"), 0) != -1) { 
                filename = octstr_copy(loc->line, equals + 1, octstr_len(loc->line)); 
                parse_value(filename); 
 
                /* check if we are cycling */ 
                if (gwlist_search(stack, filename, octstr_item_match) != NULL) { 
                    panic(0, "Recursive include for config file `%s' detected " 
                             "(on line %ld of file %s).", 
                          octstr_get_cstr(filename), loc->line_no,  
                          octstr_get_cstr(loc->filename)); 
                } else {     
                    List *files = gwlist_create();
                    Octstr *file;
                    struct stat filestat;

                    /* check if included file is a directory */
                    if (lstat(octstr_get_cstr(filename), &filestat) != 0) {
                        error(errno, "lstat failed: couldn't stat `%s'", 
                              octstr_get_cstr(filename));
                        panic(0, "Failed to include `%s' "
                              "(on line %ld of file %s). Aborting!",  
                              octstr_get_cstr(filename), loc->line_no,  
                              octstr_get_cstr(loc->filename)); 
                    }
                    
                    /* 
                     * is a directory, create a list with files of
                     * this directory and load all as part of the
                     * whole configuration.
                     */
                    if (S_ISDIR(filestat.st_mode)) {
                        DIR *dh;
                        struct dirent *diritem;

                        debug("gwlib.cfg", 0, "Loading include dir `%s' "
                              "(on line %ld of file %s).",  
                              octstr_get_cstr(filename), loc->line_no,  
                              octstr_get_cstr(loc->filename)); 

                        dh = opendir(octstr_get_cstr(filename));
                        while ((diritem = readdir(dh))) {
                            Octstr *fileitem;

                            fileitem = octstr_duplicate(filename);
                            octstr_append_cstr(fileitem, "/");
                            octstr_append_cstr(fileitem, diritem->d_name);

                            lstat(octstr_get_cstr(fileitem), &filestat);
                            if (!S_ISDIR(filestat.st_mode)) {
                                gwlist_insert(files, 0, fileitem);
                            } else {
                            	octstr_destroy(fileitem);
                            }
                        }
                        closedir(dh);
                    } 
		    
                    /* is a file, create a list with it */
                    else {
                        gwlist_insert(files, 0, octstr_duplicate(filename));
                    }

                    /* include files */
                    while ((file = gwlist_extract_first(files)) != NULL) {

                        gwlist_insert(stack, 0, octstr_duplicate(file)); 
                        debug("gwlib.cfg", 0, "Loading include file `%s' (on line %ld of file %s).",  
                              octstr_get_cstr(file), loc->line_no,  
                              octstr_get_cstr(loc->filename)); 

                        /*  
                         * expand the given include file and add it to the current 
                         * processed main while loop 
                         */ 
                        if ((expand = expand_file(file, 0)) != NULL) {
                            while ((loc_inc = gwlist_extract_first(expand)) != NULL) 
                                gwlist_insert(lines, 0, loc_inc); 
                        } else { 
                            panic(0, "Failed to load whole configuration. Aborting!"); 
                        } 
                 
                        gwlist_destroy(expand, NULL); 
                        cfgloc_destroy(loc_inc);
                        octstr_destroy(file);
                    }
                    gwlist_destroy(files, octstr_destroy_item);
                } 
                octstr_destroy(filename); 
            }  
             
            /* 
             * this is a "normal" line, so process it accodingly 
             */ 
            else  { 
                name = octstr_copy(loc->line, 0, equals); 
                octstr_strip_blanks(name); 
                value = octstr_copy(loc->line, equals + 1, octstr_len(loc->line)); 
                parse_value(value); 
 
    	    	if (grp == NULL)
                    grp = create_group(); 
                 
                if (grp->configfile != NULL) {
                    octstr_destroy(grp->configfile); 
                    grp->configfile = NULL;
                }
                grp->configfile = octstr_duplicate(cfg->filename); 

                cfg_set(grp, name, value); 
                octstr_destroy(name); 
                octstr_destroy(value); 
            } 
        } 

        cfgloc_destroy(loc); 
    }

    if (grp != NULL && add_group(cfg, grp) == -1) {
        error_lineno = 1; 
        destroy_group(grp); 
    }

    gwlist_destroy(lines, NULL); 
    gwlist_destroy(stack, octstr_destroy_item); 

    if (error_lineno != 0) {
        error(0, "Error found on line %ld of file `%s'.",  
	          error_lineno, octstr_get_cstr(cfg->filename)); 
        return -1; 
    }

    return 0;
}
Exemple #11
0
int main(int argc, char* argv[])
{
    GPU_Target* screen;

    printRenderers();

    screen = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS);
    if(screen == NULL)
        return -1;

    printCurrentRenderer();

    {
        Uint32 startTime;
        long frameCount;
        Uint8 done;
        SDL_Event event;

        int i = 0;

        float dt = 0.010f;

#define MAX_GROUPS 30
        Group groups[MAX_GROUPS];
        int num_groups;

        memset(groups, 0, sizeof(Group)*MAX_GROUPS);

        num_groups = 0;
        groups[num_groups] = create_first_group();
        num_groups++;

        startTime = SDL_GetTicks();
        frameCount = 0;

        done = 0;
        while(!done)
        {
            while(SDL_PollEvent(&event))
            {
                if(event.type == SDL_QUIT)
                    done = 1;
                else if(event.type == SDL_KEYDOWN)
                {
                    if(event.key.keysym.sym == SDLK_ESCAPE)
                        done = 1;
                    else if(event.key.keysym.sym == SDLK_EQUALS || event.key.keysym.sym == SDLK_PLUS)
                    {
                        for(i = 0; i < MAX_GROUPS; i++)
                        {
                            if(groups[i].target == NULL)
                            {
                                groups[i] = create_group();
                                num_groups++;
                                GPU_Log("Added window %u.  num_groups: %d\n", groups[i].target->context->windowID, num_groups);
                                break;
                            }
                        }
                    }
                    else if(event.key.keysym.sym == SDLK_MINUS)
                    {
                        if(num_groups > 0)
                        {

                            for(i = MAX_GROUPS-1; i >= 0; i--)
                            {
                                if(groups[i].target != NULL)
                                {
                                    GPU_Log("Removed window %u.  num_groups: %d\n", groups[i].target->context->windowID, num_groups-1);

                                    destroy_group(groups, i);

                                    num_groups--;
                                    break;
                                }
                            }

                            if(num_groups == 0)
                                done = 1;
                        }
                    }
                }
                else if(event.type == SDL_MOUSEBUTTONDOWN)
                {
                    GPU_Target* target = GPU_GetWindowTarget(event.button.windowID);
                    if(target == NULL)
                        GPU_Log("Clicked on window %u.  NULL target.\n", event.button.windowID);
                    else
                        GPU_Log("Clicked on window %u.  Target dims: %dx%d\n", event.button.windowID, target->w, target->h);
                }
                else if(event.type == SDL_WINDOWEVENT)
                {
                    if(event.window.event == SDL_WINDOWEVENT_CLOSE)
                    {
                        Uint8 closed = 0;
                        for(i = 0; i < MAX_GROUPS; i++)
                        {
                            if(groups[i].target != NULL && groups[i].target->context->windowID == event.window.windowID)
                            {
                                closed = 1;
                                GPU_Log("Removed window %u.  num_groups: %d\n", groups[i].target->context->windowID, num_groups-1);

                                destroy_group(groups, i);
                                num_groups--;
                                break;
                            }
                        }

                        // The last window was closed, then.
                        if(!closed || num_groups == 0)
                            done = 1;
                    }
                }
            }

            for(i = 0; i < MAX_GROUPS; i++)
            {
                if(groups[i].target == NULL)
                    continue;

                groups[i].sprite.x += groups[i].sprite.velx*dt;
                groups[i].sprite.y += groups[i].sprite.vely*dt;
                if(groups[i].sprite.x < 0)
                {
                    groups[i].sprite.x = 0;
                    groups[i].sprite.velx = -groups[i].sprite.velx;
                }
                else if(groups[i].sprite.x > screen_w)
                {
                    groups[i].sprite.x = screen_w;
                    groups[i].sprite.velx = -groups[i].sprite.velx;
                }

                if(groups[i].sprite.y < 0)
                {
                    groups[i].sprite.y = 0;
                    groups[i].sprite.vely = -groups[i].sprite.vely;
                }
                else if(groups[i].sprite.y > screen_h)
                {
                    groups[i].sprite.y = screen_h;
                    groups[i].sprite.vely = -groups[i].sprite.vely;
                }
            }

            for(i = 0; i < MAX_GROUPS; i++)
            {
                if(groups[i].target == NULL)
                    continue;

                GPU_Clear(groups[i].target);

                GPU_Blit(groups[i].sprite.image, NULL, groups[i].target, groups[i].sprite.x, groups[i].sprite.y);

                GPU_Flip(groups[i].target);
            }

            frameCount++;
            if(frameCount%500 == 0)
                GPU_Log("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime));
        }

        GPU_Log("Average FPS: %.2f\n", 1000.0f*frameCount/(SDL_GetTicks() - startTime));

        for(i = 0; i < MAX_GROUPS; i++)
        {
            if(groups[i].target == NULL)
                continue;

            destroy_group(groups, i);
        }

    }

    GPU_Quit();

    return 0;
}