osptoolkit.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <osp/osptrans.h>
00032 #include "../../dprint.h"
00033 #include "osptoolkit.h"
00034
00035 static OSPTTHREADRETURN ospReportUsageWork(void* usagearg);
00036
00037 typedef struct _osp_usage
00038 {
00039 OSPTTRANHANDLE ospvTransaction;
00040 unsigned ospvReleaseCode;
00041 unsigned ospvDuration;
00042 time_t ospvStartTime;
00043 time_t ospvEndTime;
00044 time_t ospvAlertTime;
00045 time_t ospvConnectTime;
00046 unsigned ospvIsPDDInfoPresent;
00047 unsigned ospvPostDialDelay;
00048 unsigned ospvReleaseSource;
00049 } osp_usage;
00050
00051
00052
00053
00054
00055
00056 unsigned long long ospGetTransactionId(
00057 OSPTTRANHANDLE transaction)
00058 {
00059 OSPTTRANS* context = NULL;
00060 unsigned long long id = 0;
00061 int errorcode = OSPC_ERR_NO_ERROR;
00062
00063 context = OSPPTransactionGetContext(transaction, &errorcode);
00064
00065 if (errorcode == OSPC_ERR_NO_ERROR) {
00066 id = (unsigned long long)context->TransactionID;
00067 } else {
00068 LM_ERR("failed to extract transaction_id from transaction handle %d (%d)\n",
00069 transaction,
00070 errorcode);
00071 }
00072
00073 return id;
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 void ospReportUsageWrapper(
00090 OSPTTRANHANDLE ospvTransaction,
00091 unsigned ospvReleaseCode,
00092 unsigned ospvDuration,
00093 time_t ospvStartTime,
00094 time_t ospvEndTime,
00095 time_t ospvAlertTime,
00096 time_t ospvConnectTime,
00097 unsigned ospvIsPDDInfoPresent,
00098 unsigned ospvPostDialDelay,
00099 unsigned ospvReleaseSource)
00100 {
00101 osp_usage* usage;
00102 OSPTTHREADID threadid;
00103 OSPTTHRATTR threadattr;
00104 int errorcode;
00105
00106 LM_DBG("schedule usage report for '%llu'\n", ospGetTransactionId(ospvTransaction));
00107
00108 usage = (osp_usage*)malloc(sizeof(osp_usage));
00109
00110 usage->ospvTransaction = ospvTransaction;
00111 usage->ospvReleaseCode = ospvReleaseCode;
00112 usage->ospvDuration = ospvDuration;
00113 usage->ospvStartTime = ospvStartTime;
00114 usage->ospvEndTime = ospvEndTime;
00115 usage->ospvAlertTime = ospvAlertTime;
00116 usage->ospvConnectTime = ospvConnectTime;
00117 usage->ospvIsPDDInfoPresent = ospvIsPDDInfoPresent;
00118 usage->ospvPostDialDelay = ospvPostDialDelay;
00119 usage->ospvReleaseSource = ospvReleaseSource;
00120
00121 OSPM_THRATTR_INIT(threadattr, errorcode);
00122
00123 OSPM_SETDETACHED_STATE(threadattr, errorcode);
00124
00125 OSPM_CREATE_THREAD(threadid, &threadattr, ospReportUsageWork, usage, errorcode);
00126
00127 OSPM_THRATTR_DESTROY(threadattr);
00128 }
00129
00130
00131
00132
00133
00134
00135 static OSPTTHREADRETURN ospReportUsageWork(
00136 void* usagearg)
00137 {
00138 int i;
00139 const int MAX_RETRIES = 5;
00140 osp_usage* usage;
00141 int errorcode;
00142
00143 usage = (osp_usage*)usagearg;
00144
00145 OSPPTransactionRecordFailure(
00146 usage->ospvTransaction,
00147 (enum OSPEFAILREASON)usage->ospvReleaseCode);
00148
00149 for (i = 1; i <= MAX_RETRIES; i++) {
00150 errorcode = OSPPTransactionReportUsage(
00151 usage->ospvTransaction,
00152 usage->ospvDuration,
00153 usage->ospvStartTime,
00154 usage->ospvEndTime,
00155 usage->ospvAlertTime,
00156 usage->ospvConnectTime,
00157 usage->ospvIsPDDInfoPresent,
00158 usage->ospvPostDialDelay,
00159 usage->ospvReleaseSource,
00160 (unsigned char*)"", 0, 0, 0, 0, NULL, NULL);
00161
00162 if (errorcode == OSPC_ERR_NO_ERROR) {
00163 LM_DBG("reporte usage for '%llu'\n",
00164 ospGetTransactionId(usage->ospvTransaction));
00165 break;
00166 } else {
00167 LM_ERR("failed to report usage for '%llu' (%d) attempt '%d' of '%d'\n",
00168 ospGetTransactionId(usage->ospvTransaction),
00169 errorcode,
00170 i,
00171 MAX_RETRIES);
00172 }
00173 }
00174
00175 OSPPTransactionDelete(usage->ospvTransaction);
00176
00177 free(usage);
00178
00179 OSPTTHREADRETURN_NULL();
00180 }