1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
|
/*
*
* (C) Copyright IBM Corp. 2001, 2003
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Module: option.c
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include "fullengine.h"
#include "task.h"
#include "option.h"
#include "engine.h"
#include "handlemgr.h"
#include "common.h"
#include "memman.h"
#include "remote.h"
/*
*
* int GetOptionCount(task_handle_t, int *)
*
* Description:
* This routine retrieves the total possible plug-in options for a
* specific task. The count remains unchanged through the duration
* of a specific task.
*
* Entry:
* handle - handle to task context created by CreateTask()
* count - address to copy option count to
*
* Exit:
* On success, returns a return code of 0 and *count is updated.
* On error, returns an error code < 0
*
*/
int evms_get_option_count(task_handle_t handle, int * count) {
int rc;
void * object;
object_type_t type;
LOG_PROC_ENTRY();
rc = check_engine_read_access();
if (rc != 0) {
LOG_PROC_EXIT_INT(rc);
return rc;
}
if (!local_focus) {
rc = remote_get_option_count(handle, count);
LOG_PROC_EXIT_INT(rc);
return rc;
}
rc = translate_handle(handle,
&object,
&type);
if (rc != HANDLE_MANAGER_NO_ERROR) {
LOG_PROC_EXIT_INT(rc);
return rc;
}
if (type == TASK) {
task_context_t * task = (task_context_t *) object;
if (count != NULL) {
*count = task->option_descriptors->count;
rc = 0;
} else {
LOG_ERROR("Can not return count through NULL pointer.\n");
rc = EINVAL;
}
} else {
LOG_ERROR("Not a task context handle.\n");
rc = EINVAL;
}
LOG_PROC_EXIT_INT(rc);
return rc;
}
void free_option_descriptor_contents(void * object) {
int i;
option_descriptor_t * descriptor = (option_descriptor_t *) object;
LOG_PROC_ENTRY();
if (descriptor->name != NULL) {
engine_free(descriptor->name);
}
if (descriptor->title != NULL) {
engine_free(descriptor->title);
}
if (descriptor->tip != NULL) {
engine_free(descriptor->tip);
}
if (descriptor->help != NULL) {
engine_free(descriptor->help);
}
/*
* The constraint member contains either a pointer to a list structure or a
* pointer to a range structure. Regardless, we free whatever it points to
* if allocated.
*/
switch (descriptor->constraint_type) {
case EVMS_Collection_List:
/*
* If the constraint type is for a list then we also check to see if
* it is a string list. If so, we free those strings before freeing
* the list.
*/
if (descriptor->constraint.list != NULL) {
if (descriptor->type == EVMS_Type_String) {
for (i = 0; i < descriptor->constraint.list->count; i++) {
if (descriptor->constraint.list->value[i].s != NULL) {
engine_free(descriptor->constraint.list->value[i].s);
}
}
}
engine_free(descriptor->constraint.list);
} else {
LOG_WARNING("Collection says it has a list but the list pointer is NULL.\n");
}
break;
case EVMS_Collection_Range:
if (descriptor->constraint.range != NULL) {
engine_free(descriptor->constraint.range);
} else {
LOG_WARNING("Collection says it has a range but the range pointer is NULL.\n");
}
default:
break;
}
/*
* If the value is a list, free the list. If it is a list of strings,
* free each of the strings, too.
*/
if (EVMS_OPTION_VALUE_IS_LIST (descriptor->flags) &&
EVMS_OPTION_HAS_VALUE (descriptor->flags)) {
if (descriptor->type == EVMS_Type_String) {
for (i = 0; i < descriptor->value.list->count; i++) {
if (descriptor->value.list->value[i].s != NULL) {
engine_free(descriptor->value.list->value[i].s);
}
}
}
engine_free(descriptor->value.list);
} else {
/* If the value is a string (not a collection of them), free the string. */
if (descriptor->type == EVMS_Type_String &&
descriptor->constraint_type == EVMS_Collection_None) {
if (descriptor->value.s != NULL) {
engine_free(descriptor->value.s);
}
}
}
if (descriptor->group.group_name) {
engine_free(descriptor->group.group_name);
}
LOG_PROC_EXIT_VOID();
}
void free_option_array_contents(void * arg)
{
option_array_t * options = (option_array_t *) arg;
int i;
for (i = 0; i < options->count; i++) {
if (options->option[i].name != NULL) {
engine_free(options->option[i].name);
}
if (options->option[i].flags & EVMS_KEY_VALUE_IS_LIST) {
if (options->option[i].type == EVMS_Type_String) {
int j;
for (j = 0; j < options->option[i].value.list->count; j++) {
if (options->option[i].value.list->value[j].s != NULL) {
engine_free(options->option[i].value.list->value[j].s);
}
}
}
engine_free(options->option[i].value.list);
} else if (options->option[i].type == EVMS_Type_String) {
if (options->option[i].value.s != NULL) {
engine_free(options->option[i].value.s);
}
}
}
}
static int copy_to_new_string(const char * source, char * * target) {
int rc = 0;
char * string;
LOG_PROC_ENTRY();
if (source != NULL) {
string = engine_alloc(strlen(source) + 1);
if (string != NULL) {
strcpy(string, source);
*target = string;
} else {
*target = NULL;
rc = ENOMEM;
}
} else {
*target = NULL;
}
LOG_PROC_EXIT_INT(rc);
return rc;
}
static int duplicate_value_list(value_list_t * source,
value_type_t type,
value_list_t ** target)
{
int rc=0;
if (source != NULL) {
uint size;
size = sizeof(value_list_t) + (sizeof(value_t) * source->count);
*target = engine_alloc(size);
if (*target != NULL) {
if (type == EVMS_Type_String) {
int i;
/* Copy the count of strings. */
(*target)->count = source->count;
/* Get new copies of the strings for the target. */
for (i = 0; (rc == 0) && (i < source->count); i++) {
rc = copy_to_new_string(source->value[i].s, &((*target)->value[i].s));
}
} else {
/* Copy the value list. */
memcpy(*target, source, size);
}
} else {
rc = ENOMEM;
}
}
return rc;
}
static int deep_copy_option_descriptor(option_descriptor_t * target,
option_descriptor_t * source) {
int rc = 0;
LOG_PROC_ENTRY();
/* Copy the base structure to the target descriptor. */
memcpy(target, source, sizeof(option_descriptor_t));
/*
* Wipe out the strings in the target descriptor. In case of an error we
* will clean up the target descriptor. We don't want any pointers to the
* original strings lying around and accidentally freed on the cleanup.
*/
target->name = NULL;
target->title = NULL;
target->tip = NULL;
target->help = NULL;
target->constraint.list = NULL;
target->group.group_name = NULL;
if (source->type == EVMS_Type_String || EVMS_OPTION_VALUE_IS_LIST (source->flags))
target->value.s = NULL;
/*
* Allocate new copies of the strings for the target descriptors and put
* them into the target descriptor.
*/
rc = copy_to_new_string(source->name, &target->name);
if (rc == 0) {
rc = copy_to_new_string(source->title, &target->title);
}
if (rc == 0) {
rc = copy_to_new_string(source->tip, &target->tip);
}
if (rc == 0) {
rc = copy_to_new_string(source->help, &target->help);
}
switch (source->constraint_type) {
case EVMS_Collection_List:
if (source->constraint.list != NULL)
rc = duplicate_value_list (source->constraint.list, source->type,
&(target->constraint.list));
break;
case EVMS_Collection_Range:
if (source->constraint.range != NULL) {
target->constraint.range = engine_alloc(sizeof(value_range_t));
if (target->constraint.range != NULL) {
memcpy((value_range_t *) target->constraint.range, source->constraint.range, sizeof(value_range_t));
} else {
rc = ENOMEM;
}
}
break;
default:
break;
}
if (rc == 0) {
rc = copy_to_new_string(source->group.group_name, &target->group.group_name);
}
/*
* Lastly, if the source had an initial value we need to copy it
* over if its a string or a list.
*/
if (rc == 0) {
if (EVMS_OPTION_HAS_VALUE (source->flags)) {
if (EVMS_OPTION_VALUE_IS_LIST (source->flags))
rc = duplicate_value_list (source->value.list, source->type, &(target->value.list));
else if (source->type == EVMS_Type_String) {
target->value.s = engine_alloc (source->max_len + 1);
if (target->value.s != NULL)
strcpy (target->value.s, source->value.s);
else
rc = ENOMEM;
}
}
}
LOG_PROC_EXIT_INT(rc);
return rc;
}
/* duplicate values from active option descriptors into a key/value pair array */
option_array_t * create_option_array_from_descriptors(option_desc_array_t *option_descriptors)
{
option_array_t *option_array;
option_array = engine_alloc(sizeof(option_array_t) +
(sizeof(key_value_pair_t) * option_descriptors->count));
if (option_array) {
int i, j, rc = 0;
for (i = 0, j = 0; i < option_descriptors->count && rc == 0; i++) {
option_descriptor_t *od;
od = &(option_descriptors->option[i]);
/* Only copy active options with values */
if (EVMS_OPTION_IS_ACTIVE(od->flags) &&
EVMS_OPTION_HAS_VALUE(od->flags)) {
option_array->option[j].type = od->type;
if (EVMS_OPTION_VALUE_IS_LIST(od->flags)) {
rc = duplicate_value_list(od->value.list, od->type,
&(option_array->option[j].value.list));
if (rc == 0) {
option_array->option[j].number |= EVMS_KEY_VALUE_IS_LIST;
}
} else if (od->type == EVMS_Type_String) {
option_array->option[j].value.s = engine_alloc(od->max_len + 1);
if (option_array->option[j].value.s != NULL) {
strncpy(option_array->option[j].value.s, od->value.s,
od->max_len);
} else {
rc = ENOMEM;
}
} else {
option_array->option[j].value = od->value;
}
if (rc == 0) {
option_array->option[j].is_number_based = TRUE;
option_array->option[j].number = i;
option_array->count++;
j++;
}
}
}
if (rc) {
/* Had a problem somewhere. Free the option_array and return NULL */
free_option_array_contents(option_array);
engine_free(option_array);
option_array = NULL;
}
}
return option_array;
}
/*
*
* int GetOptionDescriptor(task_handle_t, INT32, option_descriptor_t *)
*
* Description:
* This routine retrieves a full description of a back end option
* for the specified task context.
*
* Entry:
* handle - handle to task context created by CreateTask()
* index - zero-based ordinal number used to access descriptor
* descriptor - address to copy option descriptor to
*
* Exit:
* On success, returns a return code of 0 and *descriptor is updated
* On error, returns an error code < 0
*
*/
int evms_get_option_descriptor(task_handle_t handle,
u_int32_t index,
option_descriptor_t * * descriptor) {
int rc;
void * object;
object_type_t type;
LOG_PROC_ENTRY();
rc = check_engine_read_access();
if (rc != 0) {
LOG_PROC_EXIT_INT(rc);
return rc;
}
if (!local_focus) {
rc = remote_get_option_descriptor(handle, index, descriptor);
LOG_PROC_EXIT_INT(rc);
return rc;
}
rc = translate_handle(handle,
&object,
&type);
if (rc != HANDLE_MANAGER_NO_ERROR) {
LOG_PROC_EXIT_INT(rc);
return rc;
}
if (type == TASK) {
task_context_t * task = (task_context_t *) object;
if (descriptor != NULL) {
if (index < task->option_descriptors->count) {
*descriptor = alloc_app_struct(sizeof(option_descriptor_t), free_option_descriptor_contents);
if (*descriptor != NULL) {
rc = deep_copy_option_descriptor(*descriptor, &(task->option_descriptors->option[index]));
if (rc != 0) {
evms_free(*descriptor);
*descriptor = NULL;
}
} else {
rc = ENOMEM;
}
} else {
LOG_ERROR("Option index %d is not valid.\n", index);
rc = EINVAL;
}
} else {
LOG_ERROR("Can not return descriptor through NULL pointer.\n");
rc = EINVAL;
}
} else {
LOG_ERROR("Not a task context handle.\n");
rc = EINVAL;
}
LOG_PROC_EXIT_INT(rc);
return rc;
}
/*
*
* static inline void GetValue(task_context_t *, INT32, value_t *)
*
* Description:
* This private routine retrieves the current value in the option
* values array associated with the given task context and index
* and copies the value to the return value location.
*
* Entry:
* task - address of task context structure created by CreateTask()
* index - zero-based ordinal number used to access option value
* value - address to copy option value to
*
* Exit:
* *value is updated.
*
*/
static inline void GetValue(task_context_t * task,
u_int32_t index,
value_t * value) {
LOG_PROC_ENTRY();
switch (task->option_descriptors->option[index].type) {
case EVMS_Type_String:
value->s = task->option_descriptors->option[index].value.s;
break;
case EVMS_Type_Real32:
value->r32 = task->option_descriptors->option[index].value.r32;
break;
case EVMS_Type_Real64:
value->r64 = task->option_descriptors->option[index].value.r64;
break;
case EVMS_Type_Int8:
case EVMS_Type_Char:
case EVMS_Type_Unsigned_Int8:
case EVMS_Type_Unsigned_Char:
value->uc = task->option_descriptors->option[index].value.uc;
break;
case EVMS_Type_Int16:
case EVMS_Type_Unsigned_Int16:
value->ui16 = task->option_descriptors->option[index].value.ui16;
break;
case EVMS_Type_Int:
case EVMS_Type_Int32:
case EVMS_Type_Boolean:
case EVMS_Type_Unsigned_Int:
case EVMS_Type_Unsigned_Int32:
value->ui32 = task->option_descriptors->option[index].value.ui32;
break;
case EVMS_Type_Int64:
case EVMS_Type_Unsigned_Int64:
value->ui64 = task->option_descriptors->option[index].value.ui64;
break;
default:
LOG_ERROR("Unknown value type.\n");
break;
}
LOG_PROC_EXIT_VOID();
}
/*
*
* static inline void copy_value (task_context_t *, INT32, value_t *)
*
* Description:
* This private routine retrieves the current value in the option
* values array associated with the given task context and index
* and copies the value to the return value location.
*
* Entry:
* task - address of task context structure created by CreateTask()
* index - zero-based ordinal number used to access option value
* value - address to copy option value to
*
* Exit:
* *value is updated.
*
*/
static inline void copy_value (task_context_t *task, u_int32_t index, value_t *value) {
LOG_PROC_ENTRY();
if (EVMS_OPTION_VALUE_IS_LIST (task->option_descriptors->option[index].flags)) {
int size;
value_list_t *list;
list = task->option_descriptors->option[index].value.list;
size = sizeof (value_list_t) + (list->count * sizeof (value_t));
if (task->option_descriptors->option[index].type == EVMS_Type_String) {
int i;
for (i=0; i < list->count; i++) {
strcpy (value->list->value[i].s, list->value[i].s);
}
} else {
memcpy (value->list, list, size);
}
} else if (task->option_descriptors->option[index].type == EVMS_Type_String) {
strcpy (value->s, task->option_descriptors->option[index].value.s);
} else {
memcpy (value, &(task->option_descriptors->option[index].value), sizeof (value_t));
}
LOG_PROC_EXIT_VOID();
}
/*
*
* static inline int OptionNameToIndex(task_context_t *, const CHAR *, INT32 *)
*
* Description:
* This private routine takes an option name, scans the option
* descriptors in the array and returns the index corresponding
* to the option descriptor entry matching the name.
*
* Entry:
* task - address of task context structure created by CreateTask()
* name - address of NULL-terminated string containing option name
* index - address to copy matching option index to
*
* Exit:
* On success, returns a return code of 0 and *index is updated.
* On error, returns an error code of EINVAL
*
*/
static inline int OptionNameToIndex (task_context_t *task, const char *name,
u_int32_t *index) {
int i = 0;
int rc = EINVAL;
LOG_PROC_ENTRY();
/*
* Currently, don't care about search order so simply search from
* max option index down to 0...
*/
i = task->option_descriptors->count - 1;
while ((i >= 0) && (rc != 0)) {
if (strcasecmp(name, task->option_descriptors->option[i].name) == 0) {
*index = i;
rc = 0;
} else {
i--;
}
}
LOG_PROC_EXIT_INT(rc);
return rc;
}
/*
*
* static inline int SetValue(task_context_t *, INT32, value_t *, INT32 *)
*
* Description:
* This private routine calls the SetOption plug-in function
* to attempt to update the option value in the option values
* array corresponding to the given option index.
*
* Entry:
* task - address of task context structure created by CreateTask()
* index - zero-based ordinal number used to access option value
* value - address of new option value
* effect - address for returning side effect flags bitmap
*
* Exit:
* On success, returns a return code of 0 and option value in options
* array and possibly *info and *value are updated.
* On error, returns an error code < 0
*
*/
static inline int SetValue (task_context_t *task, u_int32_t index, value_t *value,
task_effect_t *effect) {
int rc;
task_effect_t local_effect;
LOG_PROC_ENTRY();
/*
* If the user did not specify an address for the effect, point the
* effect to a local variable so that the plug-in does not have to
* worry about handling a NULL pointer.
*/
if (effect == NULL) {
effect = &local_effect;
}
*effect = 0;
switch (GetPluginType(task->plugin->id)) {
case EVMS_DEVICE_MANAGER:
case EVMS_SEGMENT_MANAGER:
case EVMS_REGION_MANAGER:
case EVMS_FEATURE:
case EVMS_ASSOCIATIVE_FEATURE:
rc = task->plugin->functions.plugin->set_option(task,
index,
value,
effect);
break;
case EVMS_FILESYSTEM_INTERFACE_MODULE:
rc = task->plugin->functions.fsim->set_option(task,
index,
value,
effect);
break;
case EVMS_CLUSTER_MANAGER_INTERFACE_MODULE:
case EVMS_DISTRIBUTED_LOCK_MANAGER_INTERFACE_MODULE:
default:
rc = ENOSYS;
break;
}
if (rc == 0) {
/*
* We have a value so make sure that the flag that says there
* is no initial value is turned off...
*/
task->option_descriptors->option[index].flags &= ~EVMS_OPTION_FLAGS_NO_INITIAL_VALUE;
/*
* If the plug-in accepted the value but fudged it, get the
* fudged value from the option descriptor array in the
* task context and reflect the change in the user's supplied
* value buffer.
*/
if (*effect == EVMS_Effect_Inexact)
copy_value (task, index, value);
}
LOG_PROC_EXIT_INT(rc);
return rc;
}
/*
*
* int SetOptionValue(task_handle_t, INT32, value_t *, INT32 *)
*
* Description:
* This routine attempts to update the option value corresponding
* to the given option index.
*
* Entry:
* handle - handle to task context created by CreateTask()
* index - zero-based ordinal number used to access option value
* value - address of new option value
* effect - address for returning side effect flags bitmap
*
* Exit:
* On success, returns a return code of 0 and option value in task
* and possibly *value and *effect are updated.
* On error, returns an error code < 0
*
*/
int evms_set_option_value (task_handle_t handle,
u_int32_t index,
value_t * value,
task_effect_t * effect) {
int rc;
void * object;
object_type_t type;
task_effect_t local_effect;
LOG_PROC_ENTRY();
rc = check_engine_write_access();
if (rc != 0) {
LOG_PROC_EXIT_INT(rc);
return rc;
}
if (!local_focus) {
rc = remote_set_option_value(handle, index, value, effect);
LOG_PROC_EXIT_INT(rc);
return rc;
}
/*
* If the user did not specify an address for the effect, point the
* effect to a local variable so that the plug-in does not have to
* worry about handling a NULL pointer.
*/
if (effect == NULL) {
effect = &local_effect;
}
*effect = 0;
rc = translate_handle(handle,
&object,
&type);
if (rc != HANDLE_MANAGER_NO_ERROR) {
LOG_PROC_EXIT_INT(rc);
return rc;
}
if (type == TASK) {
task_context_t * task = (task_context_t *) object;
if (value != NULL) {
if (index < task->option_descriptors->count) {
rc = SetValue(task, index, value, effect);
} else {
LOG_ERROR("Invalid option index %d.\n", index);
rc = EINVAL;
}
} else {
LOG_ERROR("Can not accept NULL value pointer.\n");
rc = EINVAL;
}
} else {
LOG_ERROR("Not a task context handle.\n");
rc = EINVAL;
}
LOG_PROC_EXIT_INT(rc);
return rc;
}
/*
*
* int GetOptionDescriptorByName(task_handle_t, const CHAR *, option_descriptor_t *)
*
* Description:
* This routine retrieves a full description of a back end option
* for the specified task context.
*
* Entry:
* handle - handle to task context created by CreateTask()
* name - address of NULL-terminated string containing option name
* descriptor - address to copy option descriptor to
*
* Exit:
* On success, returns a return code of 0 and *descriptor is updated
* On error, returns an error code < 0
*
*/
int evms_get_option_descriptor_by_name(task_handle_t handle,
const char * name,
option_descriptor_t * * descriptor) {
int rc;
void * object;
object_type_t type;
LOG_PROC_ENTRY();
rc = check_engine_read_access();
if (rc != 0) {
LOG_PROC_EXIT_INT(rc);
return rc;
}
if (!local_focus) {
rc = remote_get_option_descriptor_by_name(handle, name, descriptor);
LOG_PROC_EXIT_INT(rc);
return rc;
}
rc = translate_handle(handle,
&object,
&type);
if (rc != HANDLE_MANAGER_NO_ERROR) {
LOG_PROC_EXIT_INT(rc);
return rc;
}
if (type == TASK) {
task_context_t * task = (task_context_t *) object;
if (descriptor != NULL) {
if (name != NULL) {
u_int32_t index;
rc = OptionNameToIndex(task, name, &index);
if (rc == 0) {
*descriptor = alloc_app_struct(sizeof(option_descriptor_t), free_option_descriptor_contents);
if (*descriptor != NULL) {
rc = deep_copy_option_descriptor(*descriptor, &(task->option_descriptors->option[index]));
if (rc != 0) {
evms_free(*descriptor);
*descriptor = NULL;
}
} else {
rc = ENOMEM;
}
} else {
LOG_ERROR("%s is not a known option name.\n", name);
}
} else {
LOG_ERROR("Option name is NULL.\n");
rc = EINVAL;
}
} else {
LOG_ERROR("Can not return descriptor through NULL pointer.\n");
rc = EINVAL;
}
} else {
LOG_ERROR("Not a task context handle.\n");
rc = EINVAL;
}
LOG_PROC_EXIT_INT(rc);
return rc;
}
/*
*
* int SetOptionValueByName(task_handle_t, const CHAR *, value_t *, INT32 *)
*
* Description:
* This routine attempts to update the option value corresponding
* to the given option name.
*
* Entry:
* handle - handle to task context created by CreateTask()
* name - address of NULL-terminated string containing option name
* value - address of new option value
* effect - address for returning side effect flags bitmap
*
* Exit:
* On success, returns a return code of 0 and option value in task
* and possibly *value and *effect are updated.
* On error, returns an error code < 0
*
*/
int evms_set_option_value_by_name(task_handle_t handle,
const char * name,
value_t * value,
task_effect_t * effect) {
int rc;
void * object;
object_type_t type;
task_effect_t local_effect;
LOG_PROC_ENTRY();
rc = check_engine_write_access();
if (rc != 0) {
LOG_PROC_EXIT_INT(rc);
return rc;
}
if (!local_focus) {
rc = remote_set_option_value_by_name(handle, name, value, effect);
LOG_PROC_EXIT_INT(rc);
return rc;
}
/*
* If the user did not specify an address for the effect, point the
* effect to a local variable so that the plug-in does not have to
* worry about handling a NULL pointer.
*/
if (effect == NULL) {
effect = &local_effect;
}
*effect = 0;
rc = translate_handle(handle,
&object,
&type);
if (rc != HANDLE_MANAGER_NO_ERROR) {
LOG_PROC_EXIT_INT(rc);
return rc;
}
if (type == TASK) {
task_context_t * task = (task_context_t *) object;
if (value != NULL) {
if (name != NULL) {
u_int32_t index;
rc = OptionNameToIndex(task, name, &index);
if (rc == 0) {
rc = SetValue(task, index, value, effect);
} else {
LOG_ERROR("%s is not a known option name.\n", name);
}
} else {
LOG_ERROR("Option name is NULL.\n");
rc = EINVAL;
}
} else {
LOG_ERROR("Can not accept NULL value pointer.\n");
rc = EINVAL;
}
} else {
LOG_ERROR("Not a task context handle.\n");
rc = EINVAL;
}
LOG_PROC_EXIT_INT(rc);
return rc;
}
|