2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
6 # include <aros/debug.h>
8 #include <proto/exec.h>
9 #include <proto/realtime.h>
10 #include <proto/utility.h>
11 #include <exec/memory.h>
12 #include <utility/tagitem.h>
13 #include "realtime_intern.h"
15 struct Conductor
*createConductor(BOOL
private, LONG
*error
,STRPTR name
,
16 struct Library
*RealTimeBase
);
18 /*****************************************************************************
21 #include <libraries/realtime.h>
23 AROS_LH1(struct Player
*, CreatePlayerA
,
27 AROS_LHA(struct TagItem
*, tagList
, A0
),
31 struct Library
*, RealTimeBase
, 7, RealTime
)
39 tagList -- pointer to an array of tags describing the player's
44 PLAYER_Name (STRPTR) -- The name of the player; default is no
47 PLAYER_Hook (struct Hook *) -- Function to call every time the time
48 changes; default is none. The hook is
51 a0 -- address of Hook structure
52 a1 -- message (see <libraries/realtime.h>)
53 a2 -- address of Player structure
55 Be aware of that the function is not
56 necessarily called TICK_FREQ times per
57 second: this is the upper limit of times
60 PLAYER_Priority (BYTE) -- The priority of the player; default is 0.
62 PLAYER_Conductor (STRPTR) -- The name of the conductor to link the
63 player to. If the conductor doesn't exist,
64 it's created automatically. Passing ~0
65 creates a private conductor.
67 PLAYER_Ready (BOOL) -- Set / clear the ready flag; default is
70 PLAYER_AlarmTime (LONG) -- Set player's alarm time; implies setting
71 the PLAYERF_ALARMSET flag.
73 PLAYER_Alarm (BOOL) -- Set / clear the PLAYERF_ALARMSET flag;
76 PLAYER_AlarmSigTask (struct Task *)
77 -- The task to signal when the alarm goes
78 off; default is no task. If no task is
79 specified PLAYERF_ALARMSET is turned
82 PLAYER_AlarmSigBit (BYTE) -- Signal bit to use for the alarm or -1
83 to disable signalling; default is -1.
85 PLAYER_Quiet (BOOL) -- Specify whether this player should be
86 ignored or not; default is FALSE.
87 Generally only used by external sync
90 PLAYER_UserData (VOID *) -- Set pointer to user specific data;
93 PLAYER_ID (UWORD) -- Set the player's ID; default is 0.
95 PLAYER_Conducted (BOOL) -- Set / clear the PLAYERF_CONDUCTED flag;
98 PLAYER_ExtSync (BOOL) -- If TRUE, this player attempts to become
99 the external sync source.
101 PLAYER_ErrorCode (LONG *) -- Optional pointer to a LONG that will
102 contain an error code if the function
103 fails. Possible error values are:
105 RTE_NOMEMORY -- memory allocation failed
106 RTE_NOTIMER -- timer allocation failed
110 A pointer to a player structure or NULL if failure. In case of a failure
111 additional information may be retreived from the LONG variable pointed
112 to by PLAYER_ErrorCode if you have specified that tag.
122 DeletePlayer(), GetPlayerAttrsA(), SetPlayerAttrsA()
126 ******************************************************************************/
131 struct TagItem
*tag
, *tl
= tagList
;
132 struct Player
*player
= AllocMem(sizeof(struct Player
),
133 MEMF_PUBLIC
| MEMF_CLEAR
);
136 D(bug("Entering CreatePlayerA()\n"));
138 error
= (LONG
*) GetTagData(PLAYER_ErrorCode
, (IPTR
) NULL
, tl
);
144 *error
= RTE_NOMEMORY
;
150 /* Set default values */
151 player
->pl_Reserved0
= -1; /* AlarmSigBit */
152 player
->pl_Flags
|= PLAYERF_READY
;
154 while((tag
= NextTagItem(&tl
)) != NULL
)
158 case PLAYER_Conductor
:
160 D(bug("Found PLAYER_Conductor tag\n"));
162 if ((IPTR
)tag
->ti_Data
== -1)
164 player
->pl_Source
= createConductor(TRUE
, error
,
165 (STRPTR
)tag
->ti_Data
,
170 struct Conductor
*cd
= FindConductor((STRPTR
)tag
->ti_Data
);
174 D(bug("Trying to create a public conductor.\n"));
175 player
->pl_Source
= createConductor(FALSE
, error
,
176 (STRPTR
)tag
->ti_Data
,
181 player
->pl_Source
= cd
;
185 if (player
->pl_Source
!= NULL
)
189 lock
= LockRealTime(RT_CONDUCTORS
);
191 /* Enqueue the player to the conductor list */
192 Enqueue((struct List
*)&player
->pl_Source
->cdt_Players
,
193 (struct Node
*)player
);
195 UnlockRealTime(lock
);
201 /* The rest of the tags are taken care of in SetPlayerAttrsA() */
204 D(bug("Calling SetPlayerAttrsA()\n"));
206 if (SetPlayerAttrsA(player
, tagList
))
216 } /* CreatePlayerA */
219 struct Conductor
*createConductor(BOOL
private, LONG
*error
, STRPTR name
,
220 struct Library
*RealTimeBase
)
222 struct Conductor
*cd
= AllocMem(sizeof(struct Conductor
),
223 MEMF_PUBLIC
| MEMF_CLEAR
);
229 *error
= RTE_NOMEMORY
;
235 cd
->cdt_Link
.ln_Name
= name
;
237 NEWLIST(&cd
->cdt_Players
);
238 InitSemaphore(&cd
->cdt_Lock
);
240 /* Initialize conductor clock */
241 cd
->cdt_ClockTime
= GPB(RealTimeBase
)->rtb_Time
;
242 cd
->cdt_StartTime
= GPB(RealTimeBase
)->rtb_Time
;
244 /* Conductors are created in 'stopped' mode. To make the clock start
245 running, call SetConductorState(player, CONDSTATE_RUNNING, _); */
246 cd
->cdt_State
= CONDSTATE_STOPPED
;
250 cd
->cdt_Flags
|= CONDUCTF_PRIVATE
;
254 /* Add the conductor to the realtime library conductor list */
257 lock
= LockRealTime(RT_CONDUCTORS
);
259 AddTail((struct List
*)&GPB(RealTimeBase
)->rtb_ConductorList
,
262 UnlockRealTime(lock
);