Fix error handling
Signed-off-by: Mahyar Koshkouei <deltabeard@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
/* Channel to play music on */
|
/* Channel to play music on */
|
||||||
#define CHANNEL 0x08
|
#define CHANNEL 0x08
|
||||||
|
|||||||
@@ -17,8 +17,9 @@
|
|||||||
|
|
||||||
#include "all.h"
|
#include "all.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "main.h"
|
// TODO: Remove order requirement.
|
||||||
#include "playback.h"
|
#include "playback.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
volatile bool runThreads = true;
|
volatile bool runThreads = true;
|
||||||
|
|
||||||
@@ -30,11 +31,11 @@ int main(int argc, char **argv)
|
|||||||
int fileNum = 0;
|
int fileNum = 0;
|
||||||
int from = 0;
|
int from = 0;
|
||||||
Thread watchdogThread;
|
Thread watchdogThread;
|
||||||
Handle* playbackFailEvent = malloc(sizeof(Handle));
|
Handle playbackFailEvent;
|
||||||
struct watchdogInfo* watchdogInfoIn;
|
struct watchdogInfo watchdogInfoIn;
|
||||||
struct errInfo_t* errInfo;
|
struct errInfo_t errInfo;
|
||||||
static volatile int error;
|
struct playbackInfo_t playbackInfo;
|
||||||
static volatile char* errorstr = NULL;
|
int error = 0;
|
||||||
|
|
||||||
gfxInitDefault();
|
gfxInitDefault();
|
||||||
sdmcInit();
|
sdmcInit();
|
||||||
@@ -42,17 +43,18 @@ int main(int argc, char **argv)
|
|||||||
consoleInit(GFX_BOTTOM, &bottomScreen);
|
consoleInit(GFX_BOTTOM, &bottomScreen);
|
||||||
consoleSelect(&bottomScreen);
|
consoleSelect(&bottomScreen);
|
||||||
|
|
||||||
svcCreateEvent(playbackFailEvent, RESET_ONESHOT);
|
svcCreateEvent(&playbackFailEvent, RESET_ONESHOT);
|
||||||
watchdogInfoIn = calloc(1, sizeof(struct watchdogInfo));
|
errInfo.error = &error;
|
||||||
errInfo = calloc(1, sizeof(struct errInfo_t));
|
errInfo.failEvent = &playbackFailEvent;
|
||||||
errInfo->error = &error;
|
errInfo.errstr = NULL;
|
||||||
errInfo->failEvent = playbackFailEvent;
|
|
||||||
errInfo->errstr = errorstr;
|
watchdogInfoIn.screen = &topScreen;
|
||||||
watchdogInfoIn->screen = &topScreen;
|
watchdogInfoIn.errInfo = &errInfo;
|
||||||
watchdogInfoIn->errInfo = errInfo;
|
watchdogThread = threadCreate(playbackWatchdog, &watchdogInfoIn, 4 * 1024, 0x20, -2, true);
|
||||||
watchdogThread = threadCreate(playbackWatchdog, watchdogInfoIn, 4 * 1024, 0x20, -2, true);
|
|
||||||
|
playbackInfo.file = NULL;
|
||||||
|
playbackInfo.errInfo = &errInfo;
|
||||||
|
|
||||||
printf("%p", playbackFailEvent);
|
|
||||||
chdir(DEFAULT_DIR);
|
chdir(DEFAULT_DIR);
|
||||||
chdir("MUSIC");
|
chdir("MUSIC");
|
||||||
if(listDir(from, MAX_LIST, 0) < 0)
|
if(listDir(from, MAX_LIST, 0) < 0)
|
||||||
@@ -129,7 +131,7 @@ int main(int argc, char **argv)
|
|||||||
if(kDown & KEY_B)
|
if(kDown & KEY_B)
|
||||||
{
|
{
|
||||||
stopPlayback();
|
stopPlayback();
|
||||||
changeFile(NULL, NULL, NULL);
|
changeFile(NULL, NULL);
|
||||||
consoleSelect(&topScreen);
|
consoleSelect(&topScreen);
|
||||||
puts("Stopped");
|
puts("Stopped");
|
||||||
continue;
|
continue;
|
||||||
@@ -219,7 +221,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
consoleSelect(&topScreen);
|
consoleSelect(&topScreen);
|
||||||
changeFile(ep->d_name, &error, playbackFailEvent);
|
changeFile(ep->d_name, &playbackInfo);
|
||||||
consoleSelect(&bottomScreen);
|
consoleSelect(&bottomScreen);
|
||||||
|
|
||||||
if(closedir(dp) != 0)
|
if(closedir(dp) != 0)
|
||||||
@@ -239,7 +241,7 @@ out:
|
|||||||
puts("Exiting...");
|
puts("Exiting...");
|
||||||
runThreads = false;
|
runThreads = false;
|
||||||
stopPlayback();
|
stopPlayback();
|
||||||
changeFile(NULL, NULL, NULL);
|
changeFile(NULL, NULL);
|
||||||
|
|
||||||
gfxExit();
|
gfxExit();
|
||||||
sdmcExit();
|
sdmcExit();
|
||||||
@@ -278,41 +280,35 @@ void playbackWatchdog(void* infoIn)
|
|||||||
|
|
||||||
while(runThreads)
|
while(runThreads)
|
||||||
{
|
{
|
||||||
|
printf("%s:%d\n", __func__, __LINE__);
|
||||||
svcWaitSynchronization(*info->errInfo->failEvent, U64_MAX);
|
svcWaitSynchronization(*info->errInfo->failEvent, U64_MAX);
|
||||||
|
printf("%s:%d\n", __func__, __LINE__);
|
||||||
svcClearEvent(*info->errInfo->failEvent);
|
svcClearEvent(*info->errInfo->failEvent);
|
||||||
|
printf("%s:%d\n", __func__, __LINE__);
|
||||||
consoleSelect(info->screen);
|
consoleSelect(info->screen);
|
||||||
printf("Here %s:%d err:%d\n", __func__, __LINE__, *info->errInfo->error);
|
printf("Here %s:%d err:%d\n", __func__, __LINE__, *info->errInfo->error);
|
||||||
#if 0
|
|
||||||
if(*info->error != 0)
|
if(*info->errInfo->error != 0)
|
||||||
{
|
{
|
||||||
printf("An error occurred: %s", ctrmus_strerror(*info->error));
|
printf("An error occurred: %s", ctrmus_strerror(*info->errInfo->error));
|
||||||
if(info->str != NULL)
|
if(info->errInfo->errstr != NULL)
|
||||||
printf(" %s", info->str);
|
{
|
||||||
|
printf(" %s", info->errInfo->errstr);
|
||||||
|
delete(info->errInfo->errstr);
|
||||||
|
}
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
info->str = NULL;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int changeFile(const char* ep_file, volatile int* error, Handle* failEvent)
|
static int changeFile(const char* ep_file, struct playbackInfo_t* playbackInfo)
|
||||||
{
|
{
|
||||||
s32 prio;
|
s32 prio;
|
||||||
static Thread thread = NULL;
|
static Thread thread = NULL;
|
||||||
static struct playbackInfo* info = NULL;
|
|
||||||
|
|
||||||
if(info == NULL)
|
|
||||||
info = calloc(1, sizeof(struct playbackInfo));
|
|
||||||
|
|
||||||
if(ep_file != NULL && getFileType(ep_file) < 0)
|
|
||||||
{
|
|
||||||
puts("Unsupported file.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If music is playing, stop it. Only one playback thread should be playing
|
* If music is playing, stop it. Only one playback thread should be playing
|
||||||
* at any time.
|
* at any time.
|
||||||
@@ -327,19 +323,17 @@ static int changeFile(const char* ep_file, volatile int* error, Handle* failEven
|
|||||||
thread = NULL;
|
thread = NULL;
|
||||||
|
|
||||||
/* free allocated file string */
|
/* free allocated file string */
|
||||||
delete(info->file);
|
delete(playbackInfo->file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ep_file == NULL)
|
if(ep_file == NULL || playbackInfo == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
info->file = strdup(ep_file);
|
playbackInfo->file = strdup(ep_file);
|
||||||
info->errInfo->error = error;
|
printf("Playing: %s\n", playbackInfo->file);
|
||||||
info->errInfo->failEvent = failEvent;
|
|
||||||
printf("Playing: %s\n", info->file);
|
|
||||||
|
|
||||||
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
|
||||||
thread = threadCreate(playFile, info, 32 * 1024, prio - 1, -2, false);
|
thread = threadCreate(playFile, playbackInfo, 32 * 1024, prio - 1, -2, false);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ void playbackWatchdog(void* infoIn);
|
|||||||
|
|
||||||
static void showControls(void);
|
static void showControls(void);
|
||||||
|
|
||||||
static int changeFile(const char* ep_file, volatile int* error, Handle* failEvent);
|
static int changeFile(const char* ep_file, struct playbackInfo_t* playbackInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get number of files in current working folder
|
* Get number of files in current working folder
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ static volatile bool stop = false;
|
|||||||
void playFile(void* infoIn)
|
void playFile(void* infoIn)
|
||||||
{
|
{
|
||||||
struct decoder_fn decoder;
|
struct decoder_fn decoder;
|
||||||
struct playbackInfo* info = infoIn;
|
struct playbackInfo_t* info = infoIn;
|
||||||
int16_t* buffer1 = NULL;
|
int16_t* buffer1 = NULL;
|
||||||
int16_t* buffer2 = NULL;
|
int16_t* buffer2 = NULL;
|
||||||
ndspWaveBuf waveBuf[2];
|
ndspWaveBuf waveBuf[2];
|
||||||
@@ -26,9 +26,10 @@ void playFile(void* infoIn)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
const char* file = info->file;
|
const char* file = info->file;
|
||||||
|
|
||||||
//info->str = strdup("Testing.");
|
|
||||||
errno = 12;
|
//info->errInfo->errstr = strdup("Testing.");
|
||||||
goto err;
|
//errno = 1001;
|
||||||
|
//goto err;
|
||||||
/* Reset previous stop command */
|
/* Reset previous stop command */
|
||||||
stop = false;
|
stop = false;
|
||||||
|
|
||||||
@@ -154,6 +155,7 @@ out:
|
|||||||
|
|
||||||
err:
|
err:
|
||||||
*info->errInfo->error = errno;
|
*info->errInfo->error = errno;
|
||||||
|
printf("%s:%d errno:%d %d\n", __func__, __LINE__, errno, *info->errInfo->error);
|
||||||
svcSignalEvent(*info->errInfo->failEvent);
|
svcSignalEvent(*info->errInfo->failEvent);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ enum file_types
|
|||||||
FILE_TYPE_MP3
|
FILE_TYPE_MP3
|
||||||
};
|
};
|
||||||
|
|
||||||
struct playbackInfo
|
struct playbackInfo_t
|
||||||
{
|
{
|
||||||
char* file;
|
char* file;
|
||||||
struct errInfo_t* errInfo;
|
struct errInfo_t* errInfo;
|
||||||
|
|||||||
Reference in New Issue
Block a user