fsl_osal_ptr dbg_realloc(fsl_osal_ptr ptr, fsl_osal_u32 size, fsl_osal_char * desc, fsl_osal_s32 line) { Mem_Desc * bt = tm->head; fsl_osal_ptr buf = NULL; if(ptr == NULL) return dbg_malloc(size, desc, line); if(size == 0) { dbg_free(ptr); return NULL; } //find the mem descripter for ptr while(bt) { if (bt->mem==ptr) break; bt=bt->next; } buf = dbg_malloc(size, desc, line); if(buf) { fsl_osal_memcpy(buf, ptr, bt->size - (PRE_SIZE + AFT_SIZE)); dbg_free(ptr); } else dbg_free(ptr); //FIXME return buf; }
int SaveChannelSetToOpenHandle(WaWEChannelSet_p pChannelSet, WaWEPlugin_p pPlugin, void *hFile, HWND hwndSavingDlg) { char *pchReadBuffer; int iBytesPerSample; int iNumOfChannels; WaWEPosition_t CurrPos; WaWESize_t SamplesToRead; WaWESize_t ReadedSamples; int rc; printf("[SaveChannelSetToOpenHandle] : Enter\n"); pchReadBuffer = (char *) dbg_malloc(READ_BUF_SIZE); if (!pchReadBuffer) { printf("[SaveChannelSetToOpenHandle] : Out of memory to allocate pchReadBuffer!\n"); return 0; } iNumOfChannels = GetNumOfChannelsFromChannelSet(pChannelSet); CurrPos = 0; iBytesPerSample = (pChannelSet->OriginalFormat.iBits + 7)/8; SamplesToRead = READ_BUF_SIZE / iBytesPerSample / iNumOfChannels; while (CurrPos<pChannelSet->Length) { ReadedSamples = 0; WaWEHelper_ChannelSet_ReadPackedSamples(pChannelSet, CurrPos, SamplesToRead, pchReadBuffer, &(pChannelSet->OriginalFormat), &ReadedSamples); if (ReadedSamples==0) break; CurrPos+=ReadedSamples; if (pChannelSet->Length>0) { #ifdef DEBUG_BUILD printf("[SaveChannelSetToOpenHandle] : Progress: %d%%\n", CurrPos * 100 / pChannelSet->Length); #endif WinSendDlgItemMsg(hwndSavingDlg, DID_SLIDER, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), (MPARAM) (CurrPos * 99 / pChannelSet->Length)); } rc = pPlugin->TypeSpecificInfo.ExportPluginInfo.fnWrite(hFile, pchReadBuffer, ReadedSamples*iBytesPerSample*iNumOfChannels); if (!rc) { dbg_free(pchReadBuffer); printf("[SaveChannelSetToOpenHandle] : Error from fnWrite() of export plugin!\n"); return 0; } } dbg_free(pchReadBuffer); printf("[SaveChannelSetToOpenHandle] : Done\n"); return 1; // Success }
/* * Attempt to interpret ASR metadata from a block device. This function * returns either NULL (not an ASR) or a pointer to a descriptor struct. * Note that the struct should be fully converted to the correct endianness * by the time this function returns. * * WARNING: If you take disks out of an ASR HostRAID array and plug them in * to a normal SCSI controller, the array will still show up! Even if you * scribble over the disks! I assume that the a320raid binary driver only * does its HostRAID magic if your controller is in RAID mode... but dmraid * lacks this sort of visibility as to where its block devices come from. * This is EXTREMELY DANGEROUS if you aren't careful! */ static void * read_metadata_areas(struct lib_context *lc, struct dev_info *di, size_t * sz, uint64_t * offset, union read_info *info) { size_t size = ASR_DISK_BLOCK_SIZE; uint64_t asr_sboffset = ASR_CONFIGOFFSET; struct asr *asr; struct asr_raid_configline *cl; /* * Read the ASR reserved block on each disk. This is the very * last sector of the disk, and we're really only interested in * the two magic numbers, the version, and the pointer to the * RAID table. Everything else appears to be unused in v8. */ if (!(asr = alloc_private(lc, handler, sizeof(*asr)))) goto bad0; if (!(asr->rt = alloc_private(lc, handler, sizeof(*asr->rt)))) goto bad1; if (!read_file(lc, handler, di->path, &asr->rb, size, asr_sboffset)) goto bad2; /* * Convert metadata and read in */ to_cpu(asr, ASR_BLOCK); /* Check Signature and read optional extended metadata. */ if (!is_asr(lc, di, asr) || !read_extended(lc, di, asr)) goto bad2; /* * Now that we made sure that we have all the metadata, we exit. */ cl = this_disk(asr); if (cl->raidstate == LSU_COMPONENT_STATE_FAILED) goto bad2; goto out; bad2: dbg_free(asr->rt); bad1: asr->rt = NULL; dbg_free(asr); bad0: asr = NULL; out: return asr; }
/* Fake a SCSI serial number by reading it from a file. */ static int get_dm_test_serial(struct lib_context *lc, struct dev_info *di, char *path) { int ret = 1; char *serial, buffer[32]; const char *dot_serial = ".serial"; FILE *f; if (!(serial = dbg_malloc(strlen(path) + strlen(dot_serial) + 1))) return log_alloc_err(lc, __func__); sprintf(serial, "%s%s", path, dot_serial); if ((f = fopen(serial, "r")) && fgets(buffer, 31, f) && !(di->serial = dbg_strdup(remove_white_space(lc, buffer, strlen(buffer))))) ret = 0; dbg_free(serial); if (f) fclose(f); else log_warn(lc, "missing dm serial file for %s", di->path); return ret; #undef DOT_SERIAL }
void *dbg_realloc(void *buf, size_t s) { struct head *p; realloc_cnt++; if(buf) /* when buf is NULL do malloc. counted twice as r and m */ if(s) /* when s = 0 realloc() acts like free(). counted twice: as r and f */ if((p = find_in_heap(buf))) { buf = realloc(buf, s); if(buf) { replace(p, buf, s); return buf; } else fprintf(stderr, "%s:%lu: dbg_realloc: not enough memory\n", dbg_file_name, dbg_line_number); } else dbg_check_addr("dbg_realloc", buf, CHK_FREED); else dbg_free(buf); else return dbg_malloc(s); return NULL; }
/* * Read the size in sectors from the sysfs "size" file. * Avoid access to removable devices. */ static int sysfs_get_size(struct lib_context *lc, struct dev_info *di, const char *path, char *name) { int ret = 0; char buf[22], *sysfs_file; const char *sysfs_size = "size"; FILE *f; if (!(sysfs_file = dbg_malloc(strlen(path) + strlen(name) + strlen(sysfs_size) + 3))) return log_alloc_err(lc, __func__); sprintf(sysfs_file, "%s/%s/%s", path, name, sysfs_size); if ((f = fopen(sysfs_file, "r"))) { /* Use fread+sscanf for klibc compatibility. */ if (fread(buf, sizeof(char), sizeof buf - 1, f) && (ret = sscanf(buf, "%" PRIu64, &di->sectors)) != 1) { ret = 0; log_err(lc, "reading disk size for %s from sysfs", di->path); } fclose(f); } else log_err(lc, "opening %s", sysfs_file); dbg_free(sysfs_file); return ret; }
void FreePluginList(WaWEPluginList_p pList) { WaWEPluginList_p pTemp; while (pList) { pTemp = pList; pList = pList->pNext; dbg_free(pTemp); } }
/* Ask sysfs, if a device is removable. */ int removable_device(struct lib_context *lc, char *dev_path) { int ret = 0; char buf[2], *name, *sysfs_path, *sysfs_file; const char *sysfs_removable = "removable"; FILE *f; if (!(sysfs_path = mk_sysfs_path(lc, BLOCK))) return 0; name = get_basename(lc, dev_path); if (!(sysfs_file = dbg_malloc(strlen(sysfs_path) + strlen(name) + strlen(sysfs_removable) + 3))) { log_alloc_err(lc, __func__); goto out; } sprintf(sysfs_file, "%s/%s/%s", sysfs_path, name, sysfs_removable); if ((f = fopen(sysfs_file, "r"))) { /* Using fread for klibc compatibility. */ if (fread(buf, sizeof(char), sizeof(buf) - 1, f) && *buf == '1') { log_notice(lc, "skipping removable device %s", dev_path); ret = 1; } fclose(f); } dbg_free(sysfs_file); out: dbg_free(sysfs_path); return ret; }
void ErasePluginList() { WaWEPlugin_p temp; if (DosRequestMutexSem(PluginListProtector_Sem, SEM_INDEFINITE_WAIT)==NO_ERROR) { while (PluginListHead) { temp = PluginListHead; PluginListHead=PluginListHead->pNext; DosFreeModule(temp->hmodDLL); dbg_free(temp); } DosReleaseMutexSem(PluginListProtector_Sem); } }
/* Read the whole metadata chunk at once */ static uint8_t * read_metadata_chunk(struct lib_context *lc, struct dev_info *di, uint64_t start) { uint8_t *ret; size_t size = (di->sectors - start) * ASR_DISK_BLOCK_SIZE; if (!(ret = dbg_malloc(size))) LOG_ERR(lc, ret, "%s: unable to allocate memory for %s", handler, di->path); if (!read_file(lc, handler, di->path, ret, size, start * ASR_DISK_BLOCK_SIZE)) { dbg_free(ret); LOG_ERR(lc, NULL, "%s: unable to read metadata on %s", handler, di->path); } return ret; }
/* * "File the metadata areas" -- I think this function is supposed to declare * which parts of the drive are metadata and thus off-limits to dmraid. */ static void file_metadata_areas(struct lib_context *lc, struct dev_info *di, void *meta) { uint8_t *buf; struct asr *asr = meta; uint64_t start = asr->rb.raidtbl; if (!(buf = read_metadata_chunk(lc, di, start))) return; /* Register the raid tables. */ file_metadata(lc, handler, di->path, buf, ASR_DISK_BLOCK_SIZE * 17, start * ASR_DISK_BLOCK_SIZE); dbg_free(buf); /* Record the device size if -D was specified. */ file_dev_size(lc, handler, di); }
/* * Find disk devices in sysfs or directly * in /dev (for Linux 2.4) and keep information. */ int discover_devices(struct lib_context *lc, char **devnodes) { int sysfs, ret = 0; const char *path; char *p; DIR *d; struct dirent *de; if ((p = mk_sysfs_path(lc, BLOCK))) { sysfs = 1; path = p; } else { sysfs = 0; path = _PATH_DEV; log_print(lc, "carrying on with %s", path); } if (!(d = opendir(path))) { log_err(lc, "opening path %s", path); goto out; } if (devnodes && *devnodes) { while (*devnodes) get_size(lc, path, get_basename(lc, *devnodes++), sysfs); } else { while ((de = readdir(d))) get_size(lc, path, de->d_name, sysfs); } closedir(d); ret = 1; out: if (p) dbg_free(p); return ret; }
void Uninitialize_EventCallbackList() { WaWEEventCallbackList_p temp; if (CallbackListProtector_Sem==-1) return; if (DosRequestMutexSem(CallbackListProtector_Sem, SEM_INDEFINITE_WAIT)==NO_ERROR) { while (CallbackListHead) { temp = CallbackListHead; #ifdef DEBUG_BUILD printf("[Uninitialize_EventCallbackList] : (Plugin fault?) Destroying registered callback: 0x%p for 0x%x events\n", temp->pEventCallback, temp->iEventCode); #endif CallbackListHead=CallbackListHead->pNext; dbg_free(temp); } DosReleaseMutexSem(CallbackListProtector_Sem); } DosCloseMutexSem(CallbackListProtector_Sem); CallbackListProtector_Sem = -1; }
static int get_size(struct lib_context *lc, const char *path, char *name, int sysfs) { int fd, ret = 0; char *dev_path; struct dev_info *di = NULL; if (!(dev_path = dbg_malloc(strlen(_PATH_DEV) + strlen(name) + 1))) return log_alloc_err(lc, __func__); sprintf(dev_path, "%s%s", _PATH_DEV, name); if (!interested(lc, dev_path)) { ret = 0; goto out; } if (removable_device(lc, dev_path) || !(di = alloc_dev_info(lc, dev_path)) || (sysfs && !sysfs_get_size(lc, di, path, name)) || (fd = open(dev_path, O_RDONLY)) == -1) goto out; if (di_ioctl(lc, fd, di)) { list_add(&di->list, LC_DI(lc)); ret = 1; } close(fd); out: dbg_free(dev_path); if (!ret && di) free_dev_info(lc, di); return ret; }
static int init_file_locking(struct lib_context *lc) { int ret = 0; char *dir; if (!(dir = get_dirname(lc, lock_file))) return 0; if (!mk_dir(lc, dir)) goto out; /* Fail on read-only file system. */ if (access(dir, R_OK | W_OK) && errno == EROFS) goto out; lc->lock = &file_locking; ret = 1; out: dbg_free(dir); return ret; }
int UpdateReOpenedChannelSet(WaWEChannelSet_p pChannelSet, int bRedrawNow) { WaWEPlugin_p pPlugin; WaWEImP_Open_Handle_p hFile; WaWEChannel_p pChannel; WaWESize_t ChannelLength; int iChannelNum; int bOldModifiedFlag; int rc; pPlugin = pChannelSet->pOriginalPlugin; hFile = pChannelSet->hOriginalFile; pChannelSet->OriginalFormat.iFrequency = hFile->iFrequency; pChannelSet->OriginalFormat.iBits = hFile->iBits; pChannelSet->OriginalFormat.iIsSigned = hFile->iIsSigned; bOldModifiedFlag = pChannelSet->bModified; WaWEHelper_ChannelSet_StartChSetFormatUsage(pChannelSet); WaWEHelper_ChannelSetFormat_DeleteAllKeys(&(pChannelSet->ChannelSetFormat)); pChannelSet->ChannelSetFormat = hFile->ChannelSetFormat; hFile->ChannelSetFormat = NULL; WaWEHelper_ChannelSet_StopChSetFormatUsage(pChannelSet, TRUE); pChannelSet->bModified = bOldModifiedFlag; // Make the channel-set cache empty, if turned on! if (pChannelSet->ChannelSetCache.bUseCache) { WaWEChannelSetCachePage_p pCachePages; unsigned int uiTemp; pCachePages = pChannelSet->ChannelSetCache.CachePages; for (uiTemp=0; uiTemp<pChannelSet->ChannelSetCache.uiNumOfCachePages; uiTemp++) { if (pCachePages->puchCachedData) { dbg_free(pCachePages->puchCachedData); pCachePages->puchCachedData = NULL; } pCachePages->uiNumOfBytesOnPage = 0; pCachePages->PageNumber = -1; } } // Calculate number of samples in one channel! ChannelLength = pPlugin->TypeSpecificInfo.ImportPluginInfo.fnSeek(hFile, 0, WAWE_SEEK_END); ChannelLength++; // Last position + 1 will mean the number of bytes in file. pChannelSet->ChannelSetCache.FileSize = ChannelLength; // Also update cache! #ifdef DEBUG_BUILD printf("[UpdateReOpenedChannelSet] : Enter\n"); printf("FileSize = %d\n", ChannelLength); #endif pPlugin->TypeSpecificInfo.ImportPluginInfo.fnSeek(hFile, 0, WAWE_SEEK_SET); ChannelLength /= (pChannelSet->OriginalFormat.iBits/8); ChannelLength /= hFile->iChannels; pChannelSet->Length = ChannelLength; #ifdef DEBUG_BUILD printf("ChannelLength = %d\n", ChannelLength); printf("Number of channels = %d\n", hFile->iChannels); #endif // Setup the list of channels inside the channel-set! pChannel = pChannelSet->pChannelListHead; iChannelNum = 0; while ((pChannel) && (iChannelNum<hFile->iChannels)) { #ifdef DEBUG_BUILD printf("Updating channel %p (Channel num %d)\n", pChannel, hFile->iChannels); fflush(stdout); #endif memcpy(&(pChannel->VirtualFormat), &(pChannelSet->OriginalFormat), sizeof(pChannel->VirtualFormat)); pChannel->Length = ChannelLength; if (DosRequestMutexSem(pChannel->hmtxUseChunkList, SEM_INDEFINITE_WAIT)==NO_ERROR) { WaWEChunk_p pToDelete; while (pChannel->pChunkListHead) { pToDelete = pChannel->pChunkListHead; pChannel->pChunkListHead = pChannel->pChunkListHead->pNext; if (pToDelete->iChunkType == WAWE_CHUNKTYPE_MODIFIED) { // Delete the modified chunk if (pToDelete->pSampleBuffer) { dbg_free(pToDelete->pSampleBuffer); pToDelete->pSampleBuffer = NULL; } } else { // Delete the original chunk // Nothing special to do here, anyway, we'll recreate one original chunk. } dbg_free(pToDelete); } pChannel->pChunkListHead = (WaWEChunk_p) dbg_malloc(sizeof(WaWEChunk_t)); if (pChannel->pChunkListHead) { // At the beginning, the channel will contain one big chunk. pChannel->pChunkListHead->iChunkType = WAWE_CHUNKTYPE_ORIGINAL; pChannel->pChunkListHead->VirtPosStart = 0; pChannel->pChunkListHead->VirtPosEnd = ChannelLength-1; #ifdef DEBUG_BUILD printf("Chunk is from %d to %d\n", 0, ChannelLength-1); #endif pChannel->pChunkListHead->pPlugin = pPlugin; pChannel->pChunkListHead->hFile = hFile; pChannel->pChunkListHead->iChannelNum = iChannelNum; pChannel->pChunkListHead->RealPosStart = 0; pChannel->pChunkListHead->pSampleBuffer = NULL; pChannel->pChunkListHead->pPrev = NULL; pChannel->pChunkListHead->pNext = NULL; } DosReleaseMutexSem(pChannel->hmtxUseChunkList); } #ifndef OPTIMIZE_REDRAW_AT_OPEN // Note that the channel has been changed, so // redraw the channel. pChannel->bRedrawNeeded = 1; #endif iChannelNum++; pChannel = pChannel->pNext; } // Ok, out of loop. // Now, delete every extra channel which remained in channel-set! while (pChannel) { WaWEChannel_p pToDelete; pToDelete = pChannel; pChannel = pChannel->pNext; #ifdef DEBUG_BUILD printf("Deleting old channel %p\n", pToDelete); #endif WaWEHelper_ChannelSet_DeleteChannel(pToDelete); } // Now, create every extra channel which appeared in file! while (iChannelNum<hFile->iChannels) { #ifdef DEBUG_BUILD printf("Creating new channel num %d\n", hFile->iChannels); #endif rc = WaWEHelper_ChannelSet_CreateChannel(pChannelSet, WAWECHANNEL_BOTTOM, NULL, &pChannel); if (rc==WAWEHELPER_NOERROR) { // Fill new channel with info! char *pchProposedName; if ((hFile->apchProposedChannelName) && (hFile->apchProposedChannelName[iChannelNum])) pchProposedName = hFile->apchProposedChannelName[iChannelNum]; else pchProposedName = NULL; // Set initial values of channel memcpy(&(pChannel->VirtualFormat), &(pChannelSet->OriginalFormat), sizeof(pChannel->VirtualFormat)); if (pchProposedName) strncpy(pChannel->achName, pchProposedName, sizeof(pChannel->achName)); pChannel->Length = ChannelLength; if (pChannelSet->pChannelListHead) { // Copy settings from other channels pChannel->FirstSamplePos = pChannelSet->pChannelListHead->FirstSamplePos; pChannel->LastSamplePos = pChannelSet->pChannelListHead->LastSamplePos; } else { pChannel->FirstSamplePos = 0; pChannel->LastSamplePos = pChannelSet->iWidth-1; } if (DosRequestMutexSem(pChannel->hmtxUseChunkList, SEM_INDEFINITE_WAIT)==NO_ERROR) { WaWEChunk_p pToDelete; while (pChannel->pChunkListHead) { pToDelete = pChannel->pChunkListHead; pChannel->pChunkListHead = pChannel->pChunkListHead->pNext; if (pToDelete->pSampleBuffer) dbg_free(pToDelete->pSampleBuffer); dbg_free(pToDelete); } pChannel->pChunkListHead = (WaWEChunk_p) dbg_malloc(sizeof(WaWEChunk_t)); if (pChannel->pChunkListHead) { // At the beginning, the channel will contain one big chunk. pChannel->pChunkListHead->iChunkType = WAWE_CHUNKTYPE_ORIGINAL; pChannel->pChunkListHead->VirtPosStart = 0; pChannel->pChunkListHead->VirtPosEnd = ChannelLength-1; #ifdef DEBUG_BUILD printf("Chunk is from %d to %d\n", 0, ChannelLength-1); #endif pChannel->pChunkListHead->pPlugin = pPlugin; pChannel->pChunkListHead->hFile = hFile; pChannel->pChunkListHead->iChannelNum = iChannelNum; pChannel->pChunkListHead->RealPosStart = 0; pChannel->pChunkListHead->pSampleBuffer = NULL; pChannel->pChunkListHead->pPrev = NULL; pChannel->pChunkListHead->pNext = NULL; } DosReleaseMutexSem(pChannel->hmtxUseChunkList); } #ifndef OPTIMIZE_REDRAW_AT_OPEN // Note that the channel has been changed, so // redraw the channel. pChannel->bRedrawNeeded = 1; #endif } iChannelNum++; } // Notify that the channel-set has been changed // This will update channel-set length pChannelSet->bRedrawNeeded = 1; if (bRedrawNow) { // Redraw everything that's changed! RedrawChangedChannelsAndChannelSets(); } #ifdef DEBUG_BUILD printf("[UpdateReOpenedChannelSet] : Leave\n"); #endif return 1; }
int main(int argc, char* argv[]) { int opt, opt_idx; int in_fmt = INPUT_FMT_FASTA; int out_fmt = ADJ_GRAPH_FMT_MM; /* Size of the graph structure. */ size_t n = 100000000; /* K-mer size. */ size_t k = 25; /* Number of threads. */ size_t num_threads = 1; struct option long_options[] = { {"fasta", no_argument, &in_fmt, INPUT_FMT_FASTA}, {"fastq", no_argument, &in_fmt, INPUT_FMT_FASTQ}, {"mm", no_argument, &out_fmt, ADJ_GRAPH_FMT_MM}, {"hb", no_argument, &out_fmt, ADJ_GRAPH_FMT_HB}, {"threads", required_argument, NULL, 't'}, {"verbose", no_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, {0, 0, 0, 0} }; while (true) { opt = getopt_long(argc, argv, "n:k:t:vh", long_options, &opt_idx); if (opt == -1) break; switch (opt) { case 'n': n = strtoul(optarg, NULL, 10); break; case 'k': k = strtoul(optarg, NULL, 10); break; case 't': num_threads = strtoul(optarg, NULL, 10); break; case 'v': pique_verbose = true; break; case 'h': print_help(stdout); return EXIT_SUCCESS; case '?': return 1; case 0: break; default: abort(); } } kmer_init(); dbg_t* G = dbg_alloc(n, k); pthread_mutex_t f_mutex; pthread_mutex_init_or_die(&f_mutex, NULL); pthread_t* threads = malloc_or_die(num_threads * sizeof(pthread_t)); pique_ctx_t ctx; ctx.fmt = in_fmt; ctx.G = G; ctx.f_mutex = &f_mutex; size_t i; if (optind >= argc) { ctx.f = fastq_create(stdin); for (i = 0; i < num_threads; ++i) { pthread_create(&threads[i], NULL, pique_thread, &ctx); } for (i = 0; i < num_threads; ++i) { pthread_join(threads[i], NULL); } fastq_free(ctx.f); } else { FILE* file; for (; optind < argc; ++optind) { file = fopen(argv[optind], "r"); if (file == NULL) { fprintf(stderr, "Cannot open %s for reading.\n", argv[optind]); return EXIT_FAILURE; } ctx.f = fastq_create(file); for (i = 0; i < num_threads; ++i) { pthread_create(&threads[i], NULL, pique_thread, &ctx); } for (i = 0; i < num_threads; ++i) { pthread_join(threads[i], NULL); } fastq_free(ctx.f); } } dbg_dump(G, stdout, num_threads, out_fmt); pthread_mutex_destroy(&f_mutex); dbg_free(G); kmer_free(); return EXIT_SUCCESS; }
void operator delete(fsl_osal_ptr ptr) { dbg_free(ptr); }
WaWEPlugin_p CreatePluginListElement(HWND hwndOwner, char *filename) { HMODULE DLLHandle; APIRET rc; pfn_WaWEP_GetPluginInfo pDLL_GetPluginInfo; WaWEPlugin_p result = NULL; WaWEPluginHelpers_t PluginHelpers; // Open the DLL DLLHandle = NULLHANDLE; rc = DosLoadModule(NULL, 0, filename, &DLLHandle); if (rc!=NO_ERROR) return NULL; // Get the entry point rc = DosQueryProcAddr(DLLHandle, 0, "WaWE_GetPluginInfo", (PFN *) &pDLL_GetPluginInfo); if (rc==NO_ERROR) { result = (WaWEPlugin_p) dbg_malloc(sizeof(WaWEPlugin_t)); if (!result) { DosFreeModule(DLLHandle); return NULL; } // Fill the info block about this dll: result->hmodDLL = DLLHandle; result->pPrev = NULL; result->pNext = NULL; // Then the info block (query from DLL) if (!((*pDLL_GetPluginInfo)(sizeof(WaWEPlugin_t), result, WAWE_APPVERSIONMAJOR, WAWE_APPVERSIONMINOR))) { #ifdef DEBUG_BUILD // printf("[CreatePluginListElement] : GetPluginInfo() reported error!\n"); #endif dbg_free(result); DosFreeModule(DLLHandle); return NULL; } // Now initialize the plugin (if it requires it!) if (result->fnInitializePlugin) { FillPluginHelpersStructure(&PluginHelpers); if (!(result->fnInitializePlugin(hwndOwner, &PluginHelpers))) { #ifdef DEBUG_BUILD // printf("[CreatePluginListElement] : fnInitializePlugin() reported error!\n"); #endif dbg_free(result); DosFreeModule(DLLHandle); return NULL; } } #ifdef DEBUG_BUILD // printf("[CreatePluginListElement] : Plugin [%s] loaded, importance is %d\n", // filename, result->iPluginImportance); #endif // Make sure the plugin does not overwrite these fields: result->hmodDLL = DLLHandle; result->pPrev = NULL; result->pNext = NULL; } // That was all for today. return result; }
int SetEventCallback(int iEventCode, pfn_WaWEP_EventCallback pEventCallback) { int iResult = 1; WaWEEventCallbackList_p pTempEvent, pPrev; if (!pEventCallback) return 0; if (DosRequestMutexSem(CallbackListProtector_Sem, SEM_INDEFINITE_WAIT)==NO_ERROR) { pPrev = NULL; pTempEvent = CallbackListHead; while ((pTempEvent) && (pTempEvent->pEventCallback!=pEventCallback)) { pPrev = pTempEvent; pTempEvent = pTempEvent->pNext; } if (iEventCode == WAWE_EVENT_NONE) { // The callback has to be removed from the list! if (pTempEvent) { // Fine, found in list, so remove it from there! if (pPrev) pPrev->pNext = pTempEvent->pNext; else CallbackListHead = pTempEvent->pNext; dbg_free(pTempEvent); } else { #ifdef DEBUG_BUILD printf("[SetEventCallback] : Could not remove event callback (0x%p), not found in list!\n", pEventCallback); #endif iResult = 0; } } else { // The callback has to be changed or has to be registered! if (pTempEvent) { // This callback is already in the list, so // only change its subscribed event type! pTempEvent->iEventCode = iEventCode; } else { pTempEvent = (WaWEEventCallbackList_p) dbg_malloc(sizeof(WaWEEventCallbackList_t)); if (!pTempEvent) { #ifdef DEBUG_BUILD printf("[SetEventCallback] : Out of memory, event callback (0x%p) could not be registered!\n", pEventCallback); #endif iResult = 0; } else { pTempEvent->iEventCode = iEventCode; pTempEvent->pEventCallback = pEventCallback; pTempEvent->pNext = CallbackListHead; CallbackListHead = pTempEvent; } } } DosReleaseMutexSem(CallbackListProtector_Sem); } else iResult = 0; return iResult; }