~ubuntu-branches/ubuntu/raring/eucalyptus/raring

« back to all changes in this revision

Viewing changes to util/adb-helpers.h

  • Committer: Package Import Robot
  • Author(s): Brian Thomason
  • Date: 2011-11-29 13:17:52 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 185.
  • Revision ID: package-import@ubuntu.com-20111129131752-rq31al3ntutv2vvl
Tags: upstream-3.0.999beta1
ImportĀ upstreamĀ versionĀ 3.0.999beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#ifndef _ADB_HELPERS_H
2
2
#define _ADB_HELPERS_H
3
3
 
 
4
#define EUCA_MESSAGE_UNMARSHAL(thefunc, theadb, themeta)                \
 
5
  {                                                                     \
 
6
    int i, j;                                                           \
 
7
    adb_serviceInfoType_t *sit=NULL;                                    \
 
8
    bzero(themeta, sizeof(ncMetadata));                                 \
 
9
    themeta->correlationId = adb_##thefunc##_get_correlationId(theadb, env); \
 
10
    themeta->userId = adb_##thefunc##_get_userId(theadb, env);          \
 
11
    themeta->epoch = adb_##thefunc##_get_epoch(theadb, env);                    \
 
12
    themeta->servicesLen = adb_##thefunc##_sizeof_services(theadb, env); \
 
13
    for (i=0; i<themeta->servicesLen && i < 16; i++) {                  \
 
14
      sit = adb_##thefunc##_get_services_at(theadb, env, i);            \
 
15
      snprintf(themeta->services[i].type,32,"%s",adb_serviceInfoType_get_type(sit, env)); \
 
16
      snprintf(themeta->services[i].name,32,"%s",adb_serviceInfoType_get_name(sit, env)); \
 
17
      themeta->services[i].urisLen = adb_serviceInfoType_sizeof_uris(sit, env); \
 
18
      for (j=0; j<themeta->services[i].urisLen && j < 8; j++) {         \
 
19
        snprintf(themeta->services[i].uris[j], 512, "%s",adb_serviceInfoType_get_uris_at(sit, env, j)); \
 
20
      }                                                                 \
 
21
    }                                                                   \
 
22
    themeta->disabledServicesLen = adb_##thefunc##_sizeof_disabledServices(theadb, env); \
 
23
    for (i=0; i<themeta->disabledServicesLen && i < 16; i++) {                  \
 
24
      sit = adb_##thefunc##_get_disabledServices_at(theadb, env, i);            \
 
25
      snprintf(themeta->disabledServices[i].type,32,"%s",adb_serviceInfoType_get_type(sit, env)); \
 
26
      snprintf(themeta->disabledServices[i].name,32,"%s",adb_serviceInfoType_get_name(sit, env)); \
 
27
      themeta->disabledServices[i].urisLen = adb_serviceInfoType_sizeof_uris(sit, env); \
 
28
      for (j=0; j<themeta->disabledServices[i].urisLen && j < 8; j++) {         \
 
29
        snprintf(themeta->disabledServices[i].uris[j], 512, "%s",adb_serviceInfoType_get_uris_at(sit, env, j)); \
 
30
      }                                                                 \
 
31
    }                                                                   \
 
32
    themeta->notreadyServicesLen = adb_##thefunc##_sizeof_notreadyServices(theadb, env); \
 
33
    for (i=0; i<themeta->notreadyServicesLen && i < 16; i++) {                  \
 
34
      sit = adb_##thefunc##_get_notreadyServices_at(theadb, env, i);            \
 
35
      snprintf(themeta->notreadyServices[i].type,32,"%s",adb_serviceInfoType_get_type(sit, env)); \
 
36
      snprintf(themeta->notreadyServices[i].name,32,"%s",adb_serviceInfoType_get_name(sit, env)); \
 
37
      themeta->notreadyServices[i].urisLen = adb_serviceInfoType_sizeof_uris(sit, env); \
 
38
      for (j=0; j<themeta->notreadyServices[i].urisLen && j < 8; j++) {         \
 
39
        snprintf(themeta->notreadyServices[i].uris[j], 512, "%s",adb_serviceInfoType_get_uris_at(sit, env, j)); \
 
40
      }                                                                 \
 
41
    }                                                                   \
 
42
  }
 
43
 
 
44
 
 
45
#define EUCA_MESSAGE_MARSHAL(thefunc, theadb, themeta)          \
 
46
  {                                                                     \
 
47
    int i, j;                                                           \
 
48
    adb_serviceInfoType_t *sit=NULL;                                    \
 
49
    adb_##thefunc##_set_correlationId(theadb, env, themeta->correlationId); \
 
50
    adb_##thefunc##_set_userId(theadb, env, themeta->userId);           \
 
51
    adb_##thefunc##_set_epoch(theadb, env,  themeta->epoch);            \
 
52
    for (i=0; i<themeta->servicesLen && i < 16; i++) {                  \
 
53
      sit = adb_serviceInfoType_create(env);                            \
 
54
      adb_serviceInfoType_set_type(sit, env, themeta->services[i].type); \
 
55
      adb_serviceInfoType_set_name(sit, env, themeta->services[i].name); \
 
56
      for (j=0; j<themeta->services[i].urisLen && j < 8; j++) { \
 
57
        adb_serviceInfoType_add_uris(sit, env, themeta->services[i].uris[j]); \
 
58
      }                                                                 \
 
59
      adb_##thefunc##_add_services(theadb, env, sit);                   \
 
60
    }                                                                   \
 
61
  }
 
62
 
 
63
//    logprintfl(EUCADEBUG, "eucalyptusMessageMarshal: excerpt: userId=%s correlationId=%s epoch=%d services[0].name=%s services[0].type=%s services[0].uris[0]=%s\n", SP(themeta->userId), SP(themeta->correlationId), themeta->epoch, SP(themeta->services[0].name), SP(themeta->services[0].type), SP(themeta->services[0].uris[0]));
 
64
 
 
65
 
 
66
static inline int datetime_to_unix (axutil_date_time_t *dt, const axutil_env_t *env)
 
67
{
 
68
    time_t tsu, ts, tsdelta, tsdelta_min;
 
69
    struct tm *tmu;
 
70
    
 
71
    if (!dt || !env) {
 
72
      return(0);
 
73
    }
 
74
 
 
75
    ts = time(NULL);
 
76
    tmu = gmtime(&ts);
 
77
    tsu = mktime(tmu);
 
78
    tsdelta = (tsu - ts) / 3600;
 
79
    tsdelta_min = ((tsu - ts) - (tsdelta * 3600)) / 60;
 
80
    
 
81
    struct tm t = {
 
82
        axutil_date_time_get_second(dt, env),
 
83
        axutil_date_time_get_minute(dt, env) - tsdelta_min,
 
84
        axutil_date_time_get_hour(dt, env) - tsdelta,
 
85
        axutil_date_time_get_date(dt, env),
 
86
        axutil_date_time_get_month(dt, env)-1,
 
87
        axutil_date_time_get_year(dt, env)-1900,
 
88
        0,
 
89
        0,
 
90
        0
 
91
    };
 
92
    
 
93
    return (int) mktime(&t);
 
94
}
 
95
 
4
96
static inline void copy_vm_type_from_adb (virtualMachine * params, adb_virtualMachineType_t * vm_type, const axutil_env_t *env)
5
97
{
6
98
  int i;
10
102
  params->mem = adb_virtualMachineType_get_memory(vm_type, env);
11
103
  params->cores = adb_virtualMachineType_get_cores(vm_type, env);
12
104
  params->disk = adb_virtualMachineType_get_disk(vm_type, env);
13
 
  strncpy(params->name, adb_virtualMachineType_get_name(vm_type, env), sizeof(params->name));
14
 
  int deviceMappingSize = adb_virtualMachineType_sizeof_deviceMapping(vm_type, env);
15
 
  for (i = 0; i<EUCA_MAX_DEVMAPS && i<deviceMappingSize; i++) {
16
 
    adb_deviceMappingType_t * dm_type = adb_virtualMachineType_get_deviceMapping_at (vm_type, env, i);
17
 
    strncpy (params->deviceMapping[i].deviceName, adb_deviceMappingType_get_deviceName(dm_type, env), sizeof(params->deviceMapping[i].deviceName));
18
 
    strncpy (params->deviceMapping[i].virtualName, adb_deviceMappingType_get_virtualName(dm_type, env), sizeof(params->deviceMapping[i].virtualName));
19
 
    params->deviceMapping[i].size = adb_deviceMappingType_get_size(dm_type, env);
20
 
    strncpy (params->deviceMapping[i].format, adb_deviceMappingType_get_format(dm_type, env), sizeof(params->deviceMapping[i].format));
 
105
  safe_strncpy(params->name, adb_virtualMachineType_get_name(vm_type, env), sizeof(params->name));
 
106
  params->virtualBootRecordLen = adb_virtualMachineType_sizeof_virtualBootRecord(vm_type, env);
 
107
  for (i = 0; i<EUCA_MAX_VBRS && i<params->virtualBootRecordLen; i++) {
 
108
    adb_virtualBootRecordType_t * vbr_type = adb_virtualMachineType_get_virtualBootRecord_at (vm_type, env, i);
 
109
    safe_strncpy (params->virtualBootRecord[i].resourceLocation, adb_virtualBootRecordType_get_resourceLocation(vbr_type, env), CHAR_BUFFER_SIZE);
 
110
    logprintfl (EUCADEBUG2, "resource location: %s\n", params->virtualBootRecord[i].resourceLocation);
 
111
    safe_strncpy (params->virtualBootRecord[i].guestDeviceName, adb_virtualBootRecordType_get_guestDeviceName(vbr_type, env), SMALL_CHAR_BUFFER_SIZE);
 
112
    logprintfl (EUCADEBUG2, "   guest dev name: %s\n", params->virtualBootRecord[i].guestDeviceName);
 
113
    params->virtualBootRecord[i].size = adb_virtualBootRecordType_get_size(vbr_type, env);
 
114
    logprintfl (EUCADEBUG2, "             size: %d\n", params->virtualBootRecord[i].size);
 
115
    safe_strncpy (params->virtualBootRecord[i].formatName, adb_virtualBootRecordType_get_format(vbr_type, env), SMALL_CHAR_BUFFER_SIZE);
 
116
    logprintfl (EUCADEBUG2, "           format: %s\n", params->virtualBootRecord[i].formatName);
 
117
    safe_strncpy (params->virtualBootRecord[i].id, adb_virtualBootRecordType_get_id(vbr_type, env), SMALL_CHAR_BUFFER_SIZE);
 
118
    logprintfl (EUCADEBUG2, "               id: %s\n", params->virtualBootRecord[i].id);
 
119
    safe_strncpy (params->virtualBootRecord[i].typeName, adb_virtualBootRecordType_get_type(vbr_type, env), SMALL_CHAR_BUFFER_SIZE);
 
120
    logprintfl (EUCADEBUG2, "             type: %s\n", params->virtualBootRecord[i].typeName);
21
121
  }
22
122
}
23
123
 
30
130
  adb_virtualMachineType_set_cores(vm_type, env, params->cores);
31
131
  adb_virtualMachineType_set_disk(vm_type, env, params->disk);
32
132
  adb_virtualMachineType_set_name(vm_type, env, params->name);
33
 
  for (i=0; i<sizeof(params->deviceMapping)/sizeof(deviceMapping); i++) {
34
 
    deviceMapping * dm = & params->deviceMapping [i];
35
 
    if (strlen(dm->deviceName)>0) {
36
 
      adb_deviceMappingType_t * dm_type = adb_deviceMappingType_create(env);
37
 
      adb_deviceMappingType_set_deviceName(dm_type, env, dm->deviceName);
38
 
      adb_deviceMappingType_set_virtualName(dm_type, env, dm->virtualName);
39
 
      adb_deviceMappingType_set_size(dm_type, env, dm->size);
40
 
      adb_deviceMappingType_set_format(dm_type, env, dm->format);
41
 
      adb_virtualMachineType_add_deviceMapping(vm_type, env, dm_type);
 
133
  //  for (i=0; i<sizeof(params->virtualBootRecord)/sizeof(virtualBootRecord); i++) { // TODO: dan ask dmitrii
 
134
  for (i=0; i<EUCA_MAX_VBRS && i<params->virtualBootRecordLen; i++) {
 
135
    virtualBootRecord * vbr = & params->virtualBootRecord [i];
 
136
    if (strlen(vbr->resourceLocation)>0) {
 
137
      adb_virtualBootRecordType_t * vbr_type = adb_virtualBootRecordType_create(env);
 
138
      adb_virtualBootRecordType_set_resourceLocation(vbr_type, env, vbr->resourceLocation);
 
139
      adb_virtualBootRecordType_set_guestDeviceName(vbr_type, env, vbr->guestDeviceName);
 
140
      adb_virtualBootRecordType_set_size(vbr_type, env, vbr->size);
 
141
      adb_virtualBootRecordType_set_format(vbr_type, env, vbr->formatName);
 
142
      adb_virtualBootRecordType_set_id(vbr_type, env, vbr->id);
 
143
      adb_virtualBootRecordType_set_type(vbr_type, env, vbr->typeName);
 
144
      adb_virtualMachineType_add_virtualBootRecord(vm_type, env, vbr_type);
42
145
    }
43
146
  }
44
147
 
45
148
  return vm_type;
46
149
}
47
150
 
 
151
static inline adb_serviceInfoType_t * copy_service_info_type_to_adb(const axutil_env_t *env, serviceInfoType * input) {
 
152
  int i;
 
153
  adb_serviceInfoType_t *sit = adb_serviceInfoType_create(env);
 
154
 
 
155
  adb_serviceInfoType_set_type(sit, env, input->type);
 
156
  adb_serviceInfoType_set_name(sit, env, input->name);
 
157
  for (i=0; i<input->urisLen; i++) {
 
158
    adb_serviceInfoType_add_uris(sit, env, input->uris[i]);
 
159
  }
 
160
  
 
161
  return (sit);
 
162
}
 
163
 
 
164
static inline void copy_service_info_type_from_adb(serviceInfoType * input, adb_serviceInfoType_t * sit, const axutil_env_t *env) {
 
165
  int i;
 
166
 
 
167
  snprintf(input->type, 32, "%s", adb_serviceInfoType_get_type(sit, env));
 
168
  snprintf(input->name, 32, "%s", adb_serviceInfoType_get_name(sit, env));
 
169
  input->urisLen = adb_serviceInfoType_sizeof_uris(sit, env);
 
170
  for (i=0; i<input->urisLen && i<8; i++) {
 
171
    snprintf(input->uris[i], 512, "%s", adb_serviceInfoType_get_uris_at(sit, env, i));
 
172
  }
 
173
}
 
174
 
48
175
#endif // _ADB_HELPERS_H