PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/sblim-cmpi-dhcp-1.0/provider/Linux_DHCPPool/Linux_DHCPPool_Resource.c

#
C | 282 lines | 193 code | 50 blank | 39 comment | 36 complexity | 090f2b282a8c77302808ba5a0f9f5521 MD5 | raw file
Possible License(s): EPL-1.0
  1. /// ============================================================================
  2. /// Copyright Š 2007, International Business Machines
  3. ///
  4. /// THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
  5. /// ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
  6. /// CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
  7. ///
  8. /// You can obtain a current copy of the Eclipse Public License from
  9. /// http://www.opensource.org/licenses/eclipse-1.0.php
  10. ///
  11. /// Authors: Ashoka Rao S <ashoka.rao (at) in.ibm.com>
  12. /// Riyashmon Haneefa <riyashh1 (at) in.ibm.com>
  13. /// ============================================================================
  14. #include "Linux_DHCPPool_Resource.h"
  15. #include "sblim-dhcp.h"
  16. #include <string.h>
  17. #include <stdlib.h>
  18. /** Include the required CMPI data types, function headers, and macros. */
  19. #include <cmpidt.h>
  20. #include <cmpift.h>
  21. #include <cmpimacs.h>
  22. /// ----------------------------------------------------------------------------
  23. /** Set supported methods accordingly */
  24. bool Pool_isEnumerateInstanceNamesSupported() { return true; };
  25. bool Pool_isEnumerateInstancesSupported() { return true; };
  26. bool Pool_isGetSupported() { return true; };
  27. bool Pool_isCreateSupported() { return true; };
  28. bool Pool_isModifySupported() { return false; };
  29. bool Pool_isDeleteSupported() { return true; };
  30. /// ----------------------------------------------------------------------------
  31. /** Get a handle to the list of all system resources for this class. */
  32. _RA_STATUS Linux_DHCPPool_getResources( _RESOURCES** resources ) {
  33. _RA_STATUS ra_status = {RA_RC_OK, 0, NULL};
  34. (*resources) = (_RESOURCES *)malloc(sizeof(_RESOURCES));
  35. memset((*resources), '\0', sizeof(_RESOURCES));
  36. ///ERROR CONDITION , If malloc fails
  37. if( (*resources) == NULL) {
  38. setRaStatus( &ra_status, RA_RC_FAILED, DYNAMIC_MEMORY_ALLOCATION_FAILED, _("Dynamic Memory Allocation Failed") );
  39. return ra_status;
  40. }
  41. ra_lockRaData();
  42. (*resources)->Array = ra_getAllEntity(POOLF, NULL, &ra_status);
  43. if( (*resources)->Array == NULL) {
  44. setRaStatus( &ra_status, RA_RC_FAILED, ENTITY_NOT_FOUND, _("Entity Not Found") );
  45. return ra_status;
  46. }
  47. (*resources)->current = 0;
  48. return ra_status;
  49. }
  50. /// ----------------------------------------------------------------------------
  51. /** Iterator to get the next resource from the resources list. */
  52. _RA_STATUS Linux_DHCPPool_getNextResource( _RESOURCES* resources, _RESOURCE** resource ) {
  53. _RA_STATUS ra_status = {RA_RC_OK, 0, NULL};
  54. _RESOURCE * temp;
  55. if(resources->Array[resources->current] != NULL)
  56. {
  57. temp = (_RESOURCE *)malloc(sizeof(_RESOURCE));
  58. memset(temp, '\0', sizeof(_RESOURCE));
  59. ///ERROR CONDITION if malloc fails
  60. if( temp == NULL) {
  61. setRaStatus( &ra_status, RA_RC_FAILED, DYNAMIC_MEMORY_ALLOCATION_FAILED, _("Dynamic Memory Allocation Failed") );
  62. return ra_status;
  63. }
  64. temp->Entity = resources->Array[resources->current++];
  65. temp->InstanceID = ra_instanceId(temp->Entity, _CLASSNAME);
  66. (*resource) = temp;
  67. }else{
  68. (*resource) = NULL;
  69. }
  70. return ra_status;
  71. }
  72. /// ----------------------------------------------------------------------------
  73. /** Get the specific resource that matches the CMPI object path. */
  74. _RA_STATUS Linux_DHCPPool_getResourceForObjectPath( _RESOURCES* resources, _RESOURCE** resource, const CMPIObjectPath* objectpath ) {
  75. _RA_STATUS ra_status = {RA_RC_OK, 0, NULL};
  76. CMPIStatus cmpi_status = {CMPI_RC_OK, NULL};
  77. CMPIData cmpi_info;
  78. NODE ** itr;
  79. const char * cmpi_name = NULL;
  80. unsigned long long key = 0;
  81. int index = 0;
  82. if(CMIsNullObject(objectpath))
  83. {
  84. setRaStatus( &ra_status, RA_RC_FAILED, OBJECT_PATH_IS_NULL, _("Object Path is NULL") );
  85. return ra_status;
  86. }
  87. cmpi_info = CMGetKey(objectpath, "InstanceID", &cmpi_status);
  88. if((cmpi_status.rc != CMPI_RC_OK) || CMIsNullValue(cmpi_info)){
  89. setRaStatus( &ra_status, RA_RC_FAILED, FAILED_TO_FETCH_KEY_ELEMENT_DATA, _("Failed to fetch the key element data") );
  90. return ra_status;
  91. }
  92. cmpi_name = CMGetCharsPtr(cmpi_info.value.string, NULL);
  93. key = ra_getKeyFromInstance((char*) cmpi_name);
  94. if(cmpi_name == NULL) {
  95. setRaStatus( &ra_status, RA_RC_FAILED, CMPI_INSTANCE_NAME_IS_NULL, _("Cmpi instance name is NULL") );
  96. return ra_status;
  97. }
  98. for(itr = resources->Array, index = 0; *itr != NULL; index++, itr++){
  99. if(key == (*itr)->obID){
  100. (*resource) = (_RESOURCE *)malloc(sizeof(_RESOURCE));
  101. memset((*resource), '\0', sizeof(_RESOURCE));
  102. ///ERROR CONDITION if malloc fails
  103. if( (*resource) == NULL) {
  104. setRaStatus( &ra_status, RA_RC_FAILED, DYNAMIC_MEMORY_ALLOCATION_FAILED, _("Dynamic Memory Allocation Failed") );
  105. return ra_status;
  106. }
  107. (*resource)->Entity = resources->Array[index];
  108. (*resource)->InstanceID = ra_instanceId(resources->Array[index], _CLASSNAME);
  109. }
  110. }
  111. return ra_status;
  112. }
  113. /// ----------------------------------------------------------------------------
  114. /** Free/deallocate/cleanup the resource after use. */
  115. _RA_STATUS Linux_DHCPPool_freeResource( _RESOURCE* resource ) {
  116. _RA_STATUS ra_status = {RA_RC_OK, 0, NULL};
  117. if(resource) {
  118. if(resource->InstanceID) {
  119. free(resource->InstanceID);
  120. resource->InstanceID = NULL;
  121. }
  122. free(resource);
  123. resource = NULL;
  124. }
  125. return ra_status;
  126. }
  127. /// ----------------------------------------------------------------------------
  128. /** Free/deallocate/cleanup the resources list after use. */
  129. _RA_STATUS Linux_DHCPPool_freeResources( _RESOURCES* resources ) {
  130. _RA_STATUS ra_status = {RA_RC_OK, 0, NULL};
  131. if(resources) {
  132. if(resources->Array) {
  133. free( resources->Array);
  134. resources->Array = NULL;
  135. }
  136. free( resources);
  137. resources = NULL;
  138. }
  139. ra_unlockRaData();
  140. return ra_status;
  141. }
  142. /// ----------------------------------------------------------------------------
  143. /** Set the property values of a CMPI instance from a specific resource. */
  144. _RA_STATUS Linux_DHCPPool_setInstanceFromResource( _RESOURCE* resource, const CMPIInstance* instance, const CMPIBroker* broker ) {
  145. _RA_STATUS ra_status = {RA_RC_OK, 0, NULL};
  146. char * parentID;
  147. parentID = ra_instanceId(resource->Entity->parent, _CLASSNAME);
  148. CMSetProperty(instance, "InstanceID", (CMPIValue *)resource->InstanceID, CMPI_chars);
  149. CMSetProperty(instance, "ElementName", (CMPIValue *)"Pool", CMPI_chars);
  150. CMSetProperty(instance, "ParentID", (CMPIValue *)parentID, CMPI_chars);
  151. return ra_status;
  152. }
  153. /// ----------------------------------------------------------------------------
  154. /** Delete the specified resource from the system. */
  155. _RA_STATUS Linux_DHCPPool_deleteResource( _RESOURCES* resources, _RESOURCE* resource, const CMPIBroker* broker ) {
  156. _RA_STATUS ra_status = {RA_RC_OK, 0, NULL};
  157. if(resource){
  158. ra_deleteNode(resource->Entity);
  159. ra_updateDhcpdFile();
  160. ra_deletedEntity();
  161. }
  162. return ra_status;
  163. }
  164. /// ----------------------------------------------------------------------------
  165. /** Modify the specified resource using the property values of a CMPI instance. */
  166. _RA_STATUS Linux_DHCPPool_setResourceFromInstance( _RESOURCE** resource, const CMPIInstance* instance, const char** properties, const CMPIBroker* broker ) {
  167. _RA_STATUS ra_status = {RA_RC_OK, 0, NULL};
  168. return ra_status;
  169. }
  170. /// ----------------------------------------------------------------------------
  171. /** Create a new resource using the property values of a CMPI instance. */
  172. _RA_STATUS Linux_DHCPPool_createResourceFromInstance( _RESOURCES* resources, _RESOURCE** resource, const CMPIInstance* instance, const CMPIBroker* broker ) {
  173. _RA_STATUS ra_status = {RA_RC_OK, 0, NULL};
  174. CMPIStatus cmpi_status = {CMPI_RC_OK, NULL};
  175. CMPIData cmpi_info;
  176. NODE * pnode, * newnode;
  177. const char * cmpi_name = NULL;
  178. int level;
  179. unsigned long long pid;
  180. if(CMIsNullObject(instance)) {
  181. setRaStatus( &ra_status, RA_RC_FAILED, INSTANCE_ID_IS_NULL, _("Instance is NULL") );
  182. return ra_status;
  183. }
  184. cmpi_info = CMGetProperty(instance, "ParentID", &cmpi_status);
  185. if((cmpi_status.rc != CMPI_RC_OK) || CMIsNullValue(cmpi_info)){
  186. setRaStatus( &ra_status, RA_RC_FAILED, PARENTID_NOT_SPECIFIED_OR_NOT_PROPER, _("ParentID not specified properly or not provided") );
  187. return ra_status;
  188. }
  189. cmpi_name = CMGetCharsPtr(cmpi_info.value.string, NULL);
  190. level = ra_findLevel(cmpi_name);
  191. pid = ra_getKeyFromInstance((char*) cmpi_name);
  192. pnode = ra_getEntity(pid, NULL, &ra_status);
  193. ///ERROR CONDITION if malloc fails
  194. if (pnode == NULL) {
  195. setRaStatus( &ra_status, RA_RC_FAILED, ENTITY_NOT_FOUND , _("Entity Not Found") );
  196. return ra_status;
  197. }
  198. newnode = ra_createPool(strdup("pool"), 0);
  199. if (newnode == NULL) {
  200. setRaStatus( &ra_status, RA_RC_FAILED, FAILED_CREATING_A_NODE, _("Failed creating a Node") );
  201. return ra_status;
  202. }
  203. ra_setInstForNode(pnode,newnode, level);
  204. ra_dropChild(pnode, newnode);
  205. ra_updateDhcpdFile();
  206. newnode->obID = ra_getInsertKey();
  207. (*resource) = (_RESOURCE *)malloc(sizeof(_RESOURCE));
  208. memset((*resource), '\0', sizeof(_RESOURCE));
  209. if( (*resource) == NULL) {
  210. setRaStatus( &ra_status, RA_RC_FAILED, DYNAMIC_MEMORY_ALLOCATION_FAILED , _("Dynamic Memory Allocation Failed") );
  211. return ra_status;
  212. }
  213. (*resource)->Entity = newnode;
  214. (*resource)->InstanceID = ra_instanceId(newnode, _CLASSNAME);
  215. return ra_status;
  216. }
  217. _RA_STATUS Linux_DHCPPool_InstanceProviderInitialize( _RA_STATUS* ra_status){
  218. ra_Initialize(ra_status);
  219. return (*ra_status);
  220. }
  221. _RA_STATUS Linux_DHCPPool_InstanceProviderCleanUp(bool term){
  222. _RA_STATUS ra_status ={RA_RC_OK, 0, NULL};
  223. if(term) ra_CleanUp();
  224. return ra_status;
  225. }
  226. ///----------------------------------------------------------------------------
  227. _RA_STATUS Linux_DHCPPool_BuildObjectPath(CMPIObjectPath* objectpath, CMPIInstance* newinstance , char* namespace, _RESOURCE* resource) {
  228. _RA_STATUS ra_status ={RA_RC_OK, 0, NULL};
  229. CMSetNameSpace( objectpath, namespace );
  230. CMAddKey(objectpath, "InstanceID", (CMPIValue *)resource->InstanceID, CMPI_chars);
  231. return ra_status;
  232. }