Skip to content

Commit

Permalink
Merge pull request #272 from parasol-framework/test/core
Browse files Browse the repository at this point in the history
Altered SubscribeEvent() function
  • Loading branch information
paul-manias authored Nov 17, 2024
2 parents 9818481 + a89e74f commit 1b4cd36
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 129 deletions.
10 changes: 5 additions & 5 deletions data/icons/Default/items/bookmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions data/icons/Default/items/new_bookmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/xml/modules/classes/compressedstream.xml
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,10 @@
</constants>

<constants lookup="VOLUME" comment="Options for SetVolume()">
<const name="HIDDEN">Hides the volume so that it will not show up when reading the root folder.</const>
<const name="HIDDEN">Hides the volume so that it will not show up when reading volumes from the root path <code>:</code>.</const>
<const name="PRIORITY">If the volume already exists, the path will be inserted at the beginning of the path list so that it has priority over the others.</const>
<const name="REPLACE">If the volume already exists, all paths that are attached to it will be replaced with the new path setting.</const>
<const name="SYSTEM">Identifies the volume as being created by the system, is immutable and persistent between sessions.</const>
<const name="SYSTEM">Identifies the volume as being created by the system (this flag is not for client use).</const>
</constants>

</types>
Expand Down
15 changes: 7 additions & 8 deletions docs/xml/modules/core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1756,18 +1756,18 @@ SetField(Object, FID_Statement|TSTR, "string");
<function>
<name>SetVolume</name>
<category>Files</category>
<comment>Adds a new volume name to the system.</comment>
<comment>Create or modify a filesystem volume.</comment>
<prototype>ERR SetVolume(CSTRING Name, CSTRING Path, CSTRING Icon, CSTRING Label, CSTRING Device, VOLUME Flags)</prototype>
<input>
<param type="CSTRING" name="Name">Required. The name of the volume.</param>
<param type="CSTRING" name="Path">Required. The path to be associated with the volume. If setting multiple paths, separate each path with a semi-colon character. Each path must terminate with a forward slash to denote a folder.</param>
<param type="CSTRING" name="Icon">An icon can be associated with the volume so that it has graphical representation when viewed in the UI. The required icon string format is <code>category/name</code>.</param>
<param type="CSTRING" name="Label">An optional label or short comment may be applied to the volume. This may be useful if the volume name has little meaning to the user (e.g. <code>drive1</code>, <code>drive2</code> ...).</param>
<param type="CSTRING" name="Device">If the volume references the root of a device, specify a code of <code>disk</code>, <code>hd</code>, <code>cd</code>, <code>network</code> or <code>usb</code>.</param>
<param type="CSTRING" name="Device">If the volume references the root of a device, specify a device name of <code>disk</code>, <code>hd</code>, <code>cd</code>, <code>network</code> or <code>usb</code>.</param>
<param type="VOLUME" name="Flags" lookup="VOLUME">Optional flags.</param>
</input>
<description>
<p>The SetVolume() function is used to create a volume that is associated with one or more paths. If the volume already exists, it possible to append more paths or replace them entirely.</p>
<p>SetVolume() is used to create or modify a volume that is associated with one or more paths. If the named volume already exists, it possible to append more paths or replace them entirely. Volume changes that are made with this function will only apply to the current process, and are lost after the program closes.</p>
<p>Flags that may be passed are as follows:</p>
<types lookup="VOLUME"/>
</description>
Expand Down Expand Up @@ -1820,17 +1820,16 @@ SetField(Object, FID_Statement|TSTR, "string");
<name>SubscribeEvent</name>
<category>Events</category>
<comment>Subscribe to a system event.</comment>
<prototype>ERR SubscribeEvent(LARGE Event, FUNCTION * Callback, APTR Custom, APTR * Handle)</prototype>
<prototype>ERR SubscribeEvent(LARGE Event, FUNCTION * Callback, APTR * Handle)</prototype>
<input>
<param type="LARGE" name="Event">An event identifier.</param>
<param type="FUNCTION *" name="Callback">The function that will be subscribed to the event.</param>
<param type="APTR" name="Custom">A custom pointer that will be sent to the callback function, set to <code>NULL</code> if not required.</param>
<param type="APTR *" name="Handle">Pointer to an address that will receive the event handle.</param>
</input>
<description>
<p>Use the SubscribeEvent() function to listen for system events. An event ID (obtainable from <function>GetEventID</function>) must be provided, as well as a reference to a function that will be called each time that the event is broadcast.</p>
<p>An event handle will be returned in the <code>Handle</code> parameter to identify the subscription. This must be retained to later unsubscribe from the event with the <function>UnsubscribeEvent</function> function.</p>
<p>The prototype for the <code>Callback</code> function is <code>Function(APTR Custom, APTR Event, LONG Size)</code>, where <code>Event</code> is the event structure that matches to the subscribed EventID.</p>
<p>The prototype for the <code>Callback</code> function is <code>Function(APTR Event, LONG Size, APTR CallbackMeta)</code>, where <code>Event</code> is the event structure that matches to the subscribed EventID.</p>
</description>
<result type="ERR">
<error code="Okay">Operation successful.</error>
Expand Down Expand Up @@ -2955,10 +2954,10 @@ SetField(Object, FID_Statement|TSTR, "string");
</constants>

<constants lookup="VOLUME" comment="Options for SetVolume()">
<const name="HIDDEN">Hides the volume so that it will not show up when reading the root folder.</const>
<const name="HIDDEN">Hides the volume so that it will not show up when reading volumes from the root path <code>:</code>.</const>
<const name="PRIORITY">If the volume already exists, the path will be inserted at the beginning of the path list so that it has priority over the others.</const>
<const name="REPLACE">If the volume already exists, all paths that are attached to it will be replaced with the new path setting.</const>
<const name="SYSTEM">Identifies the volume as being created by the system, is immutable and persistent between sessions.</const>
<const name="SYSTEM">Identifies the volume as being created by the system (this flag is not for client use).</const>
</constants>

</types>
Expand Down
38 changes: 20 additions & 18 deletions include/parasol/modules/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ struct OpenInfo {
#define FDF_SYNONYM FD_SYNONYM

#define FDF_UNSIGNED FD_UNSIGNED
#define FDF_FUNCTION FD_FUNCTION // sizeof(struct rkFunction) - use FDF_FUNCTIONPTR for sizeof(APTR)
#define FDF_FUNCTION FD_FUNCTION // sizeof(FUNCTION) - use FDF_FUNCTIONPTR for sizeof(APTR)
#define FDF_FUNCTIONPTR (FD_FUNCTION|FD_POINTER)
#define FDF_STRUCT FD_STRUCT
#define FDF_RESOURCE FD_RESOURCE
Expand Down Expand Up @@ -2052,7 +2052,7 @@ struct CoreBase {
ERR (*_SetName)(OBJECTPTR Object, CSTRING Name);
void (*_LogReturn)(void);
ERR (*_SubscribeAction)(OBJECTPTR Object, AC Action, FUNCTION *Callback);
ERR (*_SubscribeEvent)(LARGE Event, FUNCTION *Callback, APTR Custom, APTR *Handle);
ERR (*_SubscribeEvent)(LARGE Event, FUNCTION *Callback, APTR *Handle);
ERR (*_SubscribeTimer)(DOUBLE Interval, FUNCTION *Callback, APTR *Subscription);
ERR (*_UpdateTimer)(APTR Subscription, DOUBLE Interval);
ERR (*_UnsubscribeAction)(OBJECTPTR Object, AC Action);
Expand Down Expand Up @@ -2151,7 +2151,7 @@ inline ERR ScanDir(struct DirInfo *Info) { return CoreBase->_ScanDir(Info); }
inline ERR SetName(OBJECTPTR Object, CSTRING Name) { return CoreBase->_SetName(Object,Name); }
inline void LogReturn(void) { return CoreBase->_LogReturn(); }
inline ERR SubscribeAction(OBJECTPTR Object, AC Action, FUNCTION *Callback) { return CoreBase->_SubscribeAction(Object,Action,Callback); }
inline ERR SubscribeEvent(LARGE Event, FUNCTION *Callback, APTR Custom, APTR *Handle) { return CoreBase->_SubscribeEvent(Event,Callback,Custom,Handle); }
inline ERR SubscribeEvent(LARGE Event, FUNCTION *Callback, APTR *Handle) { return CoreBase->_SubscribeEvent(Event,Callback,Handle); }
inline ERR SubscribeTimer(DOUBLE Interval, FUNCTION *Callback, APTR *Subscription) { return CoreBase->_SubscribeTimer(Interval,Callback,Subscription); }
inline ERR UpdateTimer(APTR Subscription, DOUBLE Interval) { return CoreBase->_UpdateTimer(Subscription,Interval); }
inline ERR UnsubscribeAction(OBJECTPTR Object, AC Action) { return CoreBase->_UnsubscribeAction(Object,Action); }
Expand Down Expand Up @@ -2244,7 +2244,7 @@ extern "C" ERR ScanDir(struct DirInfo *Info);
extern "C" ERR SetName(OBJECTPTR Object, CSTRING Name);
extern "C" void LogReturn(void);
extern "C" ERR SubscribeAction(OBJECTPTR Object, AC Action, FUNCTION *Callback);
extern "C" ERR SubscribeEvent(LARGE Event, FUNCTION *Callback, APTR Custom, APTR *Handle);
extern "C" ERR SubscribeEvent(LARGE Event, FUNCTION *Callback, APTR *Handle);
extern "C" ERR SubscribeTimer(DOUBLE Interval, FUNCTION *Callback, APTR *Subscription);
extern "C" ERR UpdateTimer(APTR Subscription, DOUBLE Interval);
extern "C" ERR UnsubscribeAction(OBJECTPTR Object, AC Action);
Expand Down Expand Up @@ -2315,8 +2315,8 @@ inline ERR SubscribeAction(OBJECTPTR Object, AC Action, FUNCTION Callback) {
return SubscribeAction(Object,Action,&Callback);
}

inline ERR SubscribeEvent(LARGE Event, FUNCTION Callback, APTR Custom, APTR *Handle) {
return SubscribeEvent(Event,&Callback,Custom,Handle);
inline ERR SubscribeEvent(LARGE Event, FUNCTION Callback, APTR *Handle) {
return SubscribeEvent(Event,&Callback,Handle);
}

inline ERR SubscribeTimer(DOUBLE Interval, FUNCTION Callback, APTR *Subscription) {
Expand Down Expand Up @@ -4419,22 +4419,22 @@ class objCompressedStream : public Object {
#include <pthread.h>
#endif

#ifdef __system__

struct ActionMessage {
OBJECTID ObjectID; // The object that is to receive the action
LONG Time;
AC ActionID; // ID of the action or method to execute
bool SendArgs;
namespace pf {

// Action arguments follow this structure in a buffer
};
#ifdef __system__
struct ActionMessage {
OBJECTID ObjectID; // The object that is to receive the action
LONG Time;
AC ActionID; // ID of the action or method to execute
bool SendArgs;

// Action arguments follow this structure in a buffer
};
#endif

// Event support

struct rkEvent {
struct Event {
EVENTID EventID;
// Data follows
};
Expand Down Expand Up @@ -4505,6 +4505,8 @@ struct evHotplug {
char Vendor[40]; // Name of vendor
};

} // namespace

namespace fl {

// Read endian values from files and objects.
Expand Down Expand Up @@ -4561,11 +4563,11 @@ template<class T> ERR ReadBE(OBJECTPTR Object, T *Result)

// Function construction (refer types.h)

template <class T> FUNCTION C_FUNCTION(T *pRoutine, APTR pMeta = NULL) {
template <class T, class X = APTR> FUNCTION C_FUNCTION(T *pRoutine, X pMeta = 0) {
auto func = FUNCTION(CALL::STD_C);
func.Context = CurrentContext();
func.Routine = (APTR)pRoutine;
func.Meta = pMeta;
func.Meta = reinterpret_cast<void *>(pMeta);
return func;
};

Expand Down
30 changes: 25 additions & 5 deletions scripts/gui/fileview.fluid
Original file line number Diff line number Diff line change
Expand Up @@ -1483,14 +1483,10 @@ gui.fileview = function(View, Options)
self.browse(nil)
end)

Bar.addItem(2, 'Parent', 'Parent Folder', 'arrows/arrow_nw', function()
Bar.addItem(2, 'Parent', 'Parent Folder', 'folders/parent', function()
self.parentFolder()
end)

Bar.addItem(3, 'Bookmark', 'Bookmarks', 'items/bookmark', function()
-- TODO: Add the current folder as a new volume.
end)

Bar.addItem(4, 'Prev', 'Previous File', 'arrows/fat_left', function()
self.view.selectPrev(function (Item) if Item.type == 'file' then return true end end)
end)
Expand All @@ -1504,6 +1500,30 @@ gui.fileview = function(View, Options)
displayFilters(self)
end)
end

Bar.addItem(3, 'Bookmark', 'Bookmarks', 'items/new_bookmark', function()
if (string.len(self.path) < 3) then return end

local current_path = self.path

gui.dialog.message({
modal = true,
image = 'items/bookmark',
title = 'Create New Volume',
message = 'Enter a new volume name for the path ' .. self.path,
userInput = '',
options = {
{ id=2, text='Cancel', icon='items/cancel' },
{ id=1, text='Create Volume', icon='items/checkmark' }
},
feedback = function(Dialog, Response, State)
if Response and Response.id == 1 and string.len(State.input) > 0 then
mSys.SetVolume(State.input, current_path, 'items/bookmark', nil, nil, VOLUME_REPLACE)
end
end
})
end)

end
})

Expand Down
4 changes: 0 additions & 4 deletions src/audio/class_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ static ERR AUDIO_Activate(extAudio *Self)
return error;
}

// Save the audio settings to disk post-initialisation

acSaveSettings(Self);

// Calculate one mixing element size for the hardware driver (not our floating point mixer).

if (Self->BitDepth IS 16) Self->DriverBitSize = sizeof(WORD);
Expand Down
2 changes: 1 addition & 1 deletion src/core/data_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ FDEF argsSetResource[] = { { "Result", FD_LARGE }, { "Resource", FD_LONG }, { "V
FDEF argsSetResourcePath[] = { { "Error", FD_LONG|FD_ERROR }, { "PathType", FD_LONG }, { "Path", FD_STR }, { 0, 0 } };
FDEF argsSetVolume[] = { { "Error", FD_LONG|FD_ERROR }, { "Name", FD_STR }, { "Path", FD_STR }, { "Icon", FD_STR }, { "Label", FD_STR }, { "Device", FD_STR }, { "Flags", FD_LONG }, { 0, 0 } };
FDEF argsSubscribeAction[] = { { "Error", FD_LONG|FD_ERROR }, { "Object", FD_OBJECTPTR }, { "Action", FD_LONG }, { "Callback", FD_FUNCTIONPTR }, { 0, 0 } };
FDEF argsSubscribeEvent[] = { { "Error", FD_LONG|FD_ERROR }, { "Event", FD_LARGE }, { "Callback", FD_FUNCTIONPTR }, { "Custom", FD_PTR }, { "Handle", FD_PTR|FD_RESULT }, { 0, 0 } };
FDEF argsSubscribeEvent[] = { { "Error", FD_LONG|FD_ERROR }, { "Event", FD_LARGE }, { "Callback", FD_FUNCTIONPTR }, { "Handle", FD_PTR|FD_RESULT }, { 0, 0 } };
FDEF argsSubscribeTimer[] = { { "Error", FD_LONG|FD_ERROR }, { "Interval", FD_DOUBLE }, { "Callback", FD_FUNCTIONPTR }, { "Subscription", FD_PTR|FD_RESULT }, { 0, 0 } };
FDEF argsUnloadFile[] = { { "Void", FD_VOID }, { "CacheFile:Cache", FD_PTR|FD_STRUCT|FD_RESOURCE }, { 0, 0 } };
FDEF argsUnsubscribeAction[] = { { "Error", FD_LONG|FD_ERROR }, { "Object", FD_OBJECTPTR }, { "Action", FD_LONG }, { 0, 0 } };
Expand Down
32 changes: 17 additions & 15 deletions src/core/defs/core.fdl
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ struct OpenInfo {
#define FDF_SYNONYM FD_SYNONYM

#define FDF_UNSIGNED FD_UNSIGNED
#define FDF_FUNCTION FD_FUNCTION // sizeof(struct rkFunction) - use FDF_FUNCTIONPTR for sizeof(APTR)
#define FDF_FUNCTION FD_FUNCTION // sizeof(FUNCTION) - use FDF_FUNCTIONPTR for sizeof(APTR)
#define FDF_FUNCTIONPTR (FD_FUNCTION|FD_POINTER)
#define FDF_STRUCT FD_STRUCT
#define FDF_RESOURCE FD_RESOURCE
Expand Down Expand Up @@ -1213,8 +1213,8 @@ inline ERR SubscribeAction(OBJECTPTR Object, AC Action, FUNCTION Callback) {
return SubscribeAction(Object,Action,&Callback);
}

inline ERR SubscribeEvent(LARGE Event, FUNCTION Callback, APTR Custom, APTR *Handle) {
return SubscribeEvent(Event,&Callback,Custom,Handle);
inline ERR SubscribeEvent(LARGE Event, FUNCTION Callback, APTR *Handle) {
return SubscribeEvent(Event,&Callback,Handle);
}

inline ERR SubscribeTimer(DOUBLE Interval, FUNCTION Callback, APTR *Subscription) {
Expand Down Expand Up @@ -2270,22 +2270,22 @@ inline ERR Call(const FUNCTION &Function, ERR &Result) noexcept {
#include <pthread.h>
#endif

#ifdef __system__

struct ActionMessage {
OBJECTID ObjectID; // The object that is to receive the action
LONG Time;
AC ActionID; // ID of the action or method to execute
bool SendArgs;
namespace pf {

// Action arguments follow this structure in a buffer
};
#ifdef __system__
struct ActionMessage {
OBJECTID ObjectID; // The object that is to receive the action
LONG Time;
AC ActionID; // ID of the action or method to execute
bool SendArgs;

// Action arguments follow this structure in a buffer
};
#endif

// Event support

struct rkEvent {
struct Event {
EVENTID EventID;
// Data follows
};
Expand Down Expand Up @@ -2356,6 +2356,8 @@ struct evHotplug {
char Vendor[40]; // Name of vendor
};

} // namespace

namespace fl {

// Read endian values from files and objects.
Expand Down Expand Up @@ -2412,11 +2414,11 @@ template<class T> ERR ReadBE(OBJECTPTR Object, T *Result)

// Function construction (refer types.h)

template <class T> FUNCTION C_FUNCTION(T *pRoutine, APTR pMeta = NULL) {
template <class T, class X = APTR> FUNCTION C_FUNCTION(T *pRoutine, X pMeta = 0) {
auto func = FUNCTION(CALL::STD_C);
func.Context = CurrentContext();
func.Routine = (APTR)pRoutine;
func.Meta = pMeta;
func.Meta = reinterpret_cast<void *>(pMeta);
return func;
};

Expand Down
9 changes: 5 additions & 4 deletions src/core/fs_volumes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ ERR RenameVolume(CSTRING Volume, CSTRING Name)
/*********************************************************************************************************************
-FUNCTION-
SetVolume: Adds a new volume name to the system.
SetVolume: Create or modify a filesystem volume.
The SetVolume() function is used to create a volume that is associated with one or more paths. If the volume already
exists, it possible to append more paths or replace them entirely.
SetVolume() is used to create or modify a volume that is associated with one or more paths. If the named volume
already exists, it possible to append more paths or replace them entirely. Volume changes that are made with this
function will only apply to the current process, and are lost after the program closes.
Flags that may be passed are as follows:
Expand All @@ -110,7 +111,7 @@ cstr Name: Required. The name of the volume.
cstr Path: Required. The path to be associated with the volume. If setting multiple paths, separate each path with a semi-colon character. Each path must terminate with a forward slash to denote a folder.
cstr Icon: An icon can be associated with the volume so that it has graphical representation when viewed in the UI. The required icon string format is `category/name`.
cstr Label: An optional label or short comment may be applied to the volume. This may be useful if the volume name has little meaning to the user (e.g. `drive1`, `drive2` ...).
cstr Device: If the volume references the root of a device, specify a code of `disk`, `hd`, `cd`, `network` or `usb`.
cstr Device: If the volume references the root of a device, specify a device name of `disk`, `hd`, `cd`, `network` or `usb`.
int(VOLUME) Flags: Optional flags.
-ERRORS-
Expand Down
Loading

0 comments on commit 1b4cd36

Please sign in to comment.