static void deliveryServiceSubscribe( void *o, void *arg) { v_partition p = v_partition(o); v_deliveryServiceEntry e = v_deliveryServiceEntry(arg); v_kernel kernel; v_group g; assert(C_TYPECHECK(e,v_deliveryServiceEntry)); assert(C_TYPECHECK(p,v_partition)); kernel = v_objectKernel(e); g = v_groupSetCreate(kernel->groupSet,p,e->topic); if(v_groupPartitionAccessMode(g) == V_ACCESS_MODE_READ_WRITE || v_groupPartitionAccessMode(g) == V_ACCESS_MODE_READ) { v_groupAddEntry(g,v_entry(e)); } c_free(g); }
u_group u_groupNew( u_participant participant, const c_char *partitionName, const c_char *topicName, v_duration timeout) { u_result r; v_participant kparticipant; v_kernel kernel; v_topic ktopic; v_partition kpartition; v_group kgroup; c_iter topics; os_time delay; u_group group = NULL; if ((partitionName != NULL) && (topicName != NULL)) { if (participant != NULL) { r = u_entityWriteClaim(u_entity(participant), (v_entity*)(&kparticipant)); if (r == U_RESULT_OK){ assert(kparticipant); kernel = v_objectKernel(kparticipant); topics = v_resolveTopics(kernel,topicName); if (c_iterLength(topics) == 0) { c_iterFree(topics); delay.tv_sec = timeout.seconds; delay.tv_nsec = timeout.nanoseconds; os_nanoSleep(delay); topics = v_resolveTopics(v_objectKernel(kparticipant), topicName); } if (c_iterLength(topics) > 1) { OS_REPORT_1(OS_WARNING, "u_groupNew", 0, "Internal error: " "Multiple topics found with name = <%s>.", topicName); } ktopic = c_iterTakeFirst(topics); /* If ktopic == NULL, the topic definition is unknown. * This is not critical since it may become known in the near future. * In that case the caller is responsible for retrying to create this group, * and log something if, eventually, the group still cannot be created. */ if (ktopic != NULL) { kpartition = v_partitionNew(kernel, partitionName, NULL); if (kpartition != NULL) { kgroup = v_groupSetCreate(kernel->groupSet, kpartition, ktopic); if (kgroup != NULL) { group = u_groupCreate(kgroup, participant); if (group == NULL) { OS_REPORT_2(OS_ERROR,"u_groupNew",0, "Create proxy failed. " "For Partition <%s> and Topic <%s>.", partitionName, topicName); } c_free(kgroup); } else { OS_REPORT_2(OS_ERROR,"u_groupNew",0, "Create kernel entity failed. " "For Partition <%s> and Topic <%s>.", partitionName, topicName); } c_free(kpartition); } else { OS_REPORT_2(OS_ERROR,"u_groupNew", 0, "Failed to create partition. " "For Partition <%s> and Topic <%s>.", partitionName, topicName); } c_free(ktopic); } ktopic = c_iterTakeFirst(topics); while (ktopic != NULL) { c_free(ktopic); ktopic = c_iterTakeFirst(topics); } c_iterFree(topics); r = u_entityRelease(u_entity(participant)); } else { OS_REPORT_2(OS_ERROR,"u_groupNew",0, "Claim kernel participant failed." "For Partition <%s> and Topic <%s>.", partitionName, topicName); } } else { OS_REPORT_2(OS_ERROR,"u_groupNew",0, "No participant specified. " "For Partition <%s> and Topic <%s>.", partitionName, topicName); } } else { OS_REPORT_2(OS_ERROR,"u_groupNew",0, "Illegal parameter." "partitionName = <0x%x>, topicName = <0x%x>.", partitionName, topicName); } return group; }
u_group u_groupNew( u_participant participant, const c_char *partitionName, const c_char *topicName, v_duration timeout) { u_result r; v_participant kparticipant; v_kernel kernel; v_topic ktopic; v_partition kpartition; v_group kgroup; c_iter topics; os_time delay; u_group group = NULL; if ((partitionName != NULL) && (topicName != NULL)) { if (participant != NULL) { r = u_entityWriteClaim(u_entity(participant), (v_entity*)(&kparticipant)); if (r == U_RESULT_OK){ assert(kparticipant); kernel = v_objectKernel(kparticipant); topics = v_resolveTopics(kernel,topicName); if (c_iterLength(topics) == 0) { c_iterFree(topics); delay.tv_sec = timeout.seconds; delay.tv_nsec = timeout.nanoseconds; os_nanoSleep(delay); topics = v_resolveTopics(v_objectKernel(kparticipant), topicName); } if (c_iterLength(topics) > 1) { OS_REPORT_1(OS_WARNING, "u_groupNew", 0, "Internal error: " "Multiple topics found with name = <%s>.", topicName); } ktopic = c_iterTakeFirst(topics); if (ktopic != NULL) { kpartition = v_partitionNew(kernel, partitionName, NULL); if (kpartition != NULL) { kgroup = v_groupSetCreate(kernel->groupSet, kpartition, ktopic); if (kgroup != NULL) { group = u_groupCreate(kgroup, participant); if (group == NULL) { OS_REPORT_2(OS_ERROR,"u_groupNew",0, "Create proxy failed. " "For Partition <%s> and Topic <%s>.", partitionName, topicName); } c_free(kgroup); } else { OS_REPORT_2(OS_ERROR,"u_groupNew",0, "Create kernel entity failed. " "For Partition <%s> and Topic <%s>.", partitionName, topicName); } c_free(kpartition); } else { OS_REPORT_2(OS_ERROR,"u_groupNew", 0, "Failed to create partition. " "For Partition <%s> and Topic <%s>.", partitionName, topicName); } c_free(ktopic); }else { OS_REPORT_2(OS_ERROR,"u_groupNew", 0, "Topic not (yet) known. " "For Partition <%s> and Topic <%s>.", partitionName, topicName); } ktopic = c_iterTakeFirst(topics); while (ktopic != NULL) { c_free(ktopic); ktopic = c_iterTakeFirst(topics); } c_iterFree(topics); r = u_entityRelease(u_entity(participant)); } else { OS_REPORT_2(OS_ERROR,"u_groupNew",0, "Claim kernel participant failed." "For Partition <%s> and Topic <%s>.", partitionName, topicName); } } else { OS_REPORT_2(OS_ERROR,"u_groupNew",0, "No participant specified. " "For Partition <%s> and Topic <%s>.", partitionName, topicName); } } else { OS_REPORT_2(OS_ERROR,"u_groupNew",0, "Illegal parameter." "partitionName = <0x%x>, topicName = <0x%x>.", partitionName, topicName); } return group; }