Some compiler warnings removed.
[cake.git] / workbench / libs / realtime / setplayerattrsa.c
blob8da63d35c58ebc3632aa44c2f3b5e8b57e042bfd
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
5 #include <proto/exec.h>
6 #include <proto/utility.h>
7 #include <proto/realtime.h>
8 #include <exec/lists.h>
9 #include "realtime_intern.h"
11 /*****************************************************************************
13 NAME */
15 #include <utility/tagitem.h>
16 #include <libraries/realtime.h>
18 AROS_LH2(BOOL, SetPlayerAttrsA,
20 /* SYNOPSIS */
22 AROS_LHA(struct Player *, player , A0),
23 AROS_LHA(struct TagItem *, tagList, A1),
25 /* LOCATION */
27 struct Library *, RealTimeBase, 9, RealTime)
29 /* FUNCTION
31 Sets the attributes of a player. An attribute not specified in the array
32 of tags is unchanged after this procedure.
34 INPUTS
36 player -- The player the attributes of which to set.
37 tagList -- Pointer to an array of tags describing the player's
38 attributes or NULL.
40 TAGS
42 The same tags as for CreatePlayerA().
44 RESULT
46 Success/failure indicator. If failure, then, in case the PLAYER_ErrorCode
47 is provided, more information can be obtained via that pointer.
49 NOTES
51 EXAMPLE
53 BUGS
55 SEE ALSO
57 DeletePlayer(), GetPlayerAttrsA()
59 INTERNALS
61 ******************************************************************************/
64 AROS_LIBFUNC_INIT
66 LONG *error = NULL;
67 const struct TagItem *tl = tagList;
68 struct TagItem *tag;
69 APTR lock;
71 error = (LONG *)GetTagData(PLAYER_ErrorCode, NULL, tl);
73 while ((tag = NextTagItem(&tl)) != NULL)
75 switch(tag->ti_Tag)
77 case PLAYER_Name:
78 player->pl_Link.ln_Name = (APTR)tag->ti_Data;
79 break;
81 case PLAYER_Hook:
82 player->pl_Hook = (struct Hook *)tag->ti_Data;
83 break;
85 case PLAYER_Priority:
86 player->pl_Link.ln_Pri = (BYTE)tag->ti_Data;
88 if (player->pl_Link.ln_Succ != NULL)
90 /* If this node has been (is) inserted before, then remove it
91 and put it in the right place. */
93 /* Is this player attached to a conductor? */
94 if (player->pl_Source != NULL)
96 lock = LockRealTime(RT_CONDUCTORS);
97 Remove((struct Node *)player);
98 Enqueue((struct List *)&player->pl_Source->cdt_Players,
99 (struct Node *)player);
100 UnlockRealTime(lock);
102 else
104 if(error != NULL)
106 *error = RTE_NOCONDUCTOR;
109 return FALSE;
113 break;
115 case PLAYER_Conductor:
116 if (tag->ti_Data == NULL)
118 player->pl_Source = NULL;
120 else
122 struct Conductor *conductor;
124 lock = LockRealTime(RT_CONDUCTORS);
125 conductor = FindConductor((STRPTR)tag->ti_Data);
126 UnlockRealTime(lock);
128 if (conductor == NULL)
130 if (error != NULL)
132 *error = RTE_NOCONDUCTOR;
135 return FALSE;
139 break;
141 case PLAYER_Ready:
142 if ((BOOL)tag->ti_Data)
144 struct Conductor *conductor = player->pl_Source;
146 player->pl_Flags |= PLAYERF_READY;
148 if (conductor != NULL)
150 ObtainSemaphoreShared(&conductor->cdt_Lock);
152 if (conductor->cdt_Barrier != NULL)
154 Signal(conductor->cdt_Barrier, SIGF_SINGLE);
157 ReleaseSemaphore(&conductor->cdt_Lock);
160 else
162 player->pl_Flags &= ~PLAYERF_READY;
165 break;
167 case PLAYER_AlarmTime:
168 player->pl_Flags |= PLAYERF_ALARMSET;
169 player->pl_AlarmTime = (LONG)tag->ti_Data;
170 break;
172 case PLAYER_Alarm:
173 if ((BOOL)tag->ti_Data)
175 player->pl_Flags |= PLAYERF_ALARMSET;
177 else
179 player->pl_Flags &= ~PLAYERF_ALARMSET;
182 break;
184 case PLAYER_AlarmSigTask:
185 if ((struct Task *)tag->ti_Data == NULL)
187 player->pl_Flags &= ~PLAYERF_ALARMSET;
190 player->pl_Task = (struct Task *)tag->ti_Data;
191 break;
193 case PLAYER_AlarmSigBit:
194 if ((BYTE)tag->ti_Data == -1)
196 player->pl_Flags &= ~PLAYERF_ALARMSET;
199 /* We could use player->pl_Link.ln_Type here */
200 player->pl_Reserved0 = (BYTE)tag->ti_Data; /* NOTE! */
201 break;
203 case PLAYER_Quiet:
204 if ((BOOL)tag->ti_Data)
206 player->pl_Flags |= PLAYERF_QUIET;
208 else
210 player->pl_Flags &= ~PLAYERF_QUIET;
213 break;
215 case PLAYER_UserData:
216 player->pl_UserData = (APTR)tag->ti_Data;
217 break;
219 case PLAYER_ID:
220 player->pl_PlayerID = (UWORD)tag->ti_Data;
221 break;
223 case PLAYER_Conducted:
224 if ((BOOL)tag->ti_Data)
226 player->pl_Flags |= PLAYERF_CONDUCTED;
228 else
230 player->pl_Flags &= ~PLAYERF_CONDUCTED;
233 break;
235 case PLAYER_ExtSync:
236 lock = LockRealTime(RT_CONDUCTORS);
238 if ((BOOL)tag->ti_Data)
240 if (player->pl_Source->cdt_Flags & CONDUCTF_EXTERNAL)
242 /* Only one external synchronizer at a time, please */
243 UnlockRealTime(lock);
245 return FALSE;
248 player->pl_Source->cdt_Flags |= CONDUCTF_EXTERNAL;
249 player->pl_Flags |= PLAYERF_EXTSYNC;
251 else
253 /* If this player was the external synchronizer, we
254 clean up */
255 if (player->pl_Flags & PLAYERF_EXTSYNC)
257 player->pl_Source->cdt_Flags &= ~CONDUCTF_EXTERNAL;
258 player->pl_Source->cdt_Flags &= ~CONDUCTF_GOTTICK;
261 player->pl_Flags &= ~PLAYERF_EXTSYNC;
264 UnlockRealTime(lock);
266 break;
270 /* Consistency checks */
271 if (player->pl_Task == NULL)
273 player->pl_Flags &= ~PLAYERF_ALARMSET;
276 return TRUE;
278 AROS_LIBFUNC_EXIT
279 } /* SetPlayerAttrsA */