ADTErr SubscriberUpdate(Subscriber* _destination, const Subscriber* _source) { char errMsg[ERR_MSG_SIZE]; if (NULL == _destination || NULL == _source) { GetError(errMsg, ERR_NOT_INITIALIZED); LOG_ERROR_PRINT("%s", errMsg); return ERR_NOT_INITIALIZED; } if (strcmp(_destination->m_imsi, _source->m_imsi)) { GetError(errMsg, ERR_ILLEGAL_INPUT); LOG_ERROR_PRINT("%s", errMsg); return ERR_ILLEGAL_INPUT; } _destination->m_incomingDuration += _source->m_incomingDuration; _destination->m_outgoingDuration += _source->m_outgoingDuration; _destination->m_messagesReceived += _source->m_messagesReceived; _destination->m_messagesSent += _source->m_messagesSent; _destination->m_downloaded += _source->m_downloaded; _destination->m_uploaded += _source->m_uploaded; LOG_DEBUG_PRINT("Successfully updated %s.", _destination->m_imsi); return ERR_OK; }
ADTErr OperatorDBRemove(OperatorDB* _odb, const char* _operatorName, Operator** _op) { char errMsg[ERR_MSG_SIZE]; ADTErr err; if (NULL == _odb) { GetError(errMsg, ERR_NOT_INITIALIZED); LOG_ERROR_PRINT("%s", errMsg); return ERR_NOT_INITIALIZED; } if (NULL == _operatorName || NULL == _op) { GetError(errMsg, ERR_ILLEGAL_INPUT); LOG_ERROR_PRINT("%s", errMsg); return ERR_ILLEGAL_INPUT; } HashRemove(_odb->m_map, (const HashKey)_operatorName, (Data*)_op); err = (NULL == *_op) ? ERR_NOT_FOUND : ERR_OK; if (ERR_OK != err) { GetError(errMsg, err); LOG_WARN_PRINT("%s", errMsg); } else { LOG_DEBUG_PRINT("%s", "Successfully removed from database."); } return err; }
int Recover_Dsp(DSP_HPROCESSOR *hProcessor) { int status = 0; struct DSP_PROCESSORSTATE ProcStatus; DSP_HPROCESSOR hProc; LOG_ERROR_PRINT("***** TI DSP Monitor Recovering from DSP Crash *****\n"); RETRY: status = Attach_DspProc(&hProc); DSP_ERROR_EXIT(status, "Couldn't attach to DSP", EXIT); status = Load_Baseimage(hProc); DSPProcessor_GetState(hProc, &ProcStatus, sizeof(ProcStatus)); Dettach_DspProc(hProc); EXIT: /* keep trying to reload the baseimage until it can */ DEBUG_PRINT("Proc state = %d\n", ProcStatus.iState); if ((status != 0) || (ProcStatus.iState == PROC_ERROR)) { sleep(1); goto RETRY; } return status; }
ADTErr OperatorDBPrintToFile(const OperatorDB* _odb, const char* _fileName) { int fileDesc; char errMsg[ERR_MSG_SIZE]; if (NULL == _odb) { GetError(errMsg, ERR_NOT_INITIALIZED); LOG_ERROR_PRINT("%s", errMsg); return ERR_NOT_INITIALIZED; } if (NULL == _fileName) { GetError(errMsg, ERR_ILLEGAL_INPUT); LOG_ERROR_PRINT("%s", errMsg); return ERR_ILLEGAL_INPUT; } fileDesc = open(_fileName, O_RDWR | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR); if (fileDesc < 0) { GetError(errMsg, ERR_FILE_OPEN); LOG_ERROR_PRINT("%s", errMsg); return ERR_FILE_OPEN; } if ( ! HashForEach(_odb->m_map, PrintAllToFile, (void*)&fileDesc) ) { GetError(errMsg, ERR_GENERAL); LOG_ERROR_PRINT("%s", errMsg); return ERR_GENERAL; } if (-1 == close(fileDesc)) { GetError(errMsg, ERR_FILE_CLOSE); LOG_ERROR_PRINT("%s", errMsg); return ERR_FILE_CLOSE; } LOG_DEBUG_PRINT("Successfully wrote to file %s.", _fileName); return ERR_OK; }
ADTErr OperatorDBInsert(OperatorDB* _odb, const Operator* _op) { ADTErr err; char errMsg[ERR_MSG_SIZE]; char* operatorName = NULL; if (NULL == _odb) { GetError(errMsg, ERR_NOT_INITIALIZED); LOG_ERROR_PRINT("%s", errMsg); return ERR_NOT_INITIALIZED; } if (NULL == _op) { GetError(errMsg, ERR_ILLEGAL_INPUT); LOG_ERROR_PRINT("%s", errMsg); return ERR_ILLEGAL_INPUT; } operatorName = (char*) malloc(OPERATOR_NAME_SIZE * sizeof(char)); if (NULL == operatorName) { GetError(errMsg, ERR_ALLOCATION_FAILED); LOG_ERROR_PRINT("%s", errMsg); return ERR_ALLOCATION_FAILED; } OperatorGetName(_op, operatorName); err = HashInsert(_odb->m_map, (const HashKey)operatorName, (Data)_op); if (ERR_OK != err) { GetError(errMsg, err); LOG_WARN_PRINT("%s", errMsg); } else { LOG_DEBUG_PRINT("%s", "Successfully inserted to database."); } return err; }
ADTErr SubscriberGetIMSI(const Subscriber* _sub, char* _imsi) { char errMsg[ERR_MSG_SIZE]; if (NULL == _sub) { GetError(errMsg, ERR_NOT_INITIALIZED); LOG_ERROR_PRINT("%s", errMsg); return ERR_NOT_INITIALIZED; } if (NULL == _imsi) { GetError(errMsg, ERR_ILLEGAL_INPUT); LOG_ERROR_PRINT("%s", errMsg); return ERR_ILLEGAL_INPUT; } strcpy(_imsi, _sub->m_imsi); LOG_DEBUG_PRINT("Retrieved subscriber imsi: %s", _sub->m_imsi); return ERR_OK; }
OperatorDB* OperatorDBCreate(ADTErr* _err) { char errMsg[ERR_MSG_SIZE]; OperatorDB* odb = malloc(sizeof(OperatorDB)); if (NULL == odb) { if (NULL != _err) { *_err = ERR_ALLOCATION_FAILED; } GetError(errMsg, ERR_ALLOCATION_FAILED); LOG_ERROR_PRINT("%s", errMsg); return NULL; } odb->m_map = HashCreate(NUM_OF_BUCKETS, DJB2, CompareOperators); if (NULL == odb->m_map) { if (NULL != _err) { *_err = ERR_ALLOCATION_FAILED; } GetError(errMsg, ERR_ALLOCATION_FAILED); LOG_ERROR_PRINT("%s", errMsg); free(odb); return NULL; } if (NULL != _err) { *_err = ERR_OK; } LOG_DEBUG_PRINT("%s", "Successfully created operator database."); return odb; }
Subscriber* SubscriberCreate(CDR* _cdr, ADTErr* _err) { Subscriber* sub = NULL; e_callType type; char errMsg[ERR_MSG_SIZE]; if (NULL == _cdr) { if (NULL != _err) { *_err = ERR_NOT_INITIALIZED; } GetError(errMsg, ERR_NOT_INITIALIZED); LOG_ERROR_PRINT("%s", errMsg); return NULL; } sub = (Subscriber*) calloc(1, sizeof(Subscriber)); if (NULL == sub) { if (NULL != _err) { *_err = ERR_ALLOCATION_FAILED; } GetError(errMsg, ERR_ALLOCATION_FAILED); LOG_ERROR_PRINT("%s", errMsg); return NULL; } CDRGetIMSI(_cdr, sub->m_imsi); CDRGetCallType(_cdr, &type); switch (type) { case MOC: { CDRGetCallDuration(_cdr, &sub->m_outgoingDuration); LOG_DEBUG_PRINT("Subscriber %s updated outgoing call duration by %u seconds.", sub->m_imsi, sub->m_outgoingDuration); break; } case MTC: { CDRGetCallDuration(_cdr, &sub->m_incomingDuration); LOG_DEBUG_PRINT("Subscriber %s updated incoming call duration by %u seconds.", sub->m_imsi, sub->m_incomingDuration); break; } case SMS_MO: { ++sub->m_messagesSent; LOG_DEBUG_PRINT("Subscriber %s logged 1 sent message.", sub->m_imsi); break; } case SMS_MT: { ++sub->m_messagesReceived; LOG_DEBUG_PRINT("Subscriber %s logged 1 received message.", sub->m_imsi); break; } case GPRS: { CDRGetDownloadedMB(_cdr, &sub->m_downloaded); CDRGetUploadedMB(_cdr, &sub->m_uploaded); LOG_DEBUG_PRINT("Subscriber %s: %g MB downloaded, %g MB uploaded.", sub->m_imsi, sub->m_downloaded, sub->m_uploaded); break; } default: { free(sub); if (NULL != _err) { *_err = ERR_ILLEGAL_INPUT; } GetError(errMsg, ERR_ILLEGAL_INPUT); LOG_ERROR_PRINT("%s", errMsg); return NULL; } } if (NULL != _err) { *_err = ERR_OK; } LOG_DEBUG_PRINT("%s", "Successfully created subscriber!"); return sub; }
ADTErr SubscriberPrintToFile(const Subscriber* _sub, const int _fileDescriptor) { int nBytes; char buf[STRING_SIZE]; char errMsg[ERR_MSG_SIZE]; if (_fileDescriptor < 0) { LOG_ERROR_PRINT("%s", "Invalid file descriptor for output!"); return ERR_ILLEGAL_INPUT; } if (NULL == _sub) { LOG_WARN_PRINT("%s", "Subscriber data unavailable!"); nBytes = snprintf(buf, STRING_SIZE, "Subscriber data unavailable!\n\n"); write(_fileDescriptor, buf, nBytes); return ERR_NOT_INITIALIZED; } nBytes = snprintf(buf, STRING_SIZE, "IMSI: %s\n", _sub->m_imsi); if (write(_fileDescriptor, buf, nBytes) < 0) { GetError(errMsg, ERR_FILE_WRITE); LOG_ERROR_PRINT("%s", errMsg); return ERR_FILE_WRITE; } nBytes = snprintf(buf, STRING_SIZE, "----------------------\n"); if (write(_fileDescriptor, buf, nBytes) < 0) { GetError(errMsg, ERR_FILE_WRITE); LOG_ERROR_PRINT("%s", errMsg); return ERR_FILE_WRITE; } nBytes = snprintf(buf, STRING_SIZE, "Total incoming calls duration: %u\n", _sub->m_incomingDuration); if (write(_fileDescriptor, buf, nBytes) < 0) { GetError(errMsg, ERR_FILE_WRITE); LOG_ERROR_PRINT("%s", errMsg); return ERR_FILE_WRITE; } nBytes = snprintf(buf, STRING_SIZE, "Total outgoing calls duration: %u\n", _sub->m_outgoingDuration); if (write(_fileDescriptor, buf, nBytes) < 0) { GetError(errMsg, ERR_FILE_WRITE); LOG_ERROR_PRINT("%s", errMsg); return ERR_FILE_WRITE; } nBytes = snprintf(buf, STRING_SIZE, "Total messages received: %u\n", _sub->m_messagesReceived); if (write(_fileDescriptor, buf, nBytes) < 0) { GetError(errMsg, ERR_FILE_WRITE); LOG_ERROR_PRINT("%s", errMsg); return ERR_FILE_WRITE; } nBytes = snprintf(buf, STRING_SIZE, "Total messages sent: %u\n", _sub->m_messagesSent); if (write(_fileDescriptor, buf, nBytes) < 0) { GetError(errMsg, ERR_FILE_WRITE); LOG_ERROR_PRINT("%s", errMsg); return ERR_FILE_WRITE; } nBytes = snprintf(buf, STRING_SIZE, "Total downloaded data: %g [MB]\n", _sub->m_downloaded); if (write(_fileDescriptor, buf, nBytes) < 0) { GetError(errMsg, ERR_FILE_WRITE); LOG_ERROR_PRINT("%s", errMsg); return ERR_FILE_WRITE; } nBytes = snprintf(buf, STRING_SIZE, "Total uploaded data: %g [MB]\n\n", _sub->m_uploaded); if (write(_fileDescriptor, buf, nBytes) < 0) { GetError(errMsg, ERR_FILE_WRITE); LOG_ERROR_PRINT("%s", errMsg); return ERR_FILE_WRITE; } LOG_DEBUG_PRINT("%s", "Successfully printed subscriber to file."); return ERR_OK; }