added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / libs / realtime / setplayerattrsa.c
blob45de17be30fc3b9a6b477529e5e2970f267cf6f0
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(), GetPlayerAttrs(), SetPlayerAttrs()
59 INTERNALS
61 ******************************************************************************/
64 AROS_LIBFUNC_INIT
66 LONG *error = NULL;
67 struct TagItem *tag, *tl = tagList;
68 APTR lock;
70 error = (LONG *)GetTagData(PLAYER_ErrorCode, NULL, tl);
72 while ((tag = NextTagItem(&tl)) != NULL)
74 switch(tag->ti_Tag)
76 case PLAYER_Name:
77 player->pl_Link.ln_Name = (APTR)tag->ti_Data;
78 break;
80 case PLAYER_Hook:
81 player->pl_Hook = (struct Hook *)tag->ti_Data;
82 break;
84 case PLAYER_Priority:
85 player->pl_Link.ln_Pri = (BYTE)tag->ti_Data;
87 if (player->pl_Link.ln_Succ != NULL)
89 /* If this node has been (is) inserted before, then remove it
90 and put it in the right place. */
92 /* Is this player attached to a conductor? */
93 if (player->pl_Source != NULL)
95 lock = LockRealTime(RT_CONDUCTORS);
96 Remove((struct Node *)player);
97 Enqueue((struct List *)&player->pl_Source->cdt_Players,
98 (struct Node *)player);
99 UnlockRealTime(lock);
101 else
103 if(error != NULL)
105 *error = RTE_NOCONDUCTOR;
108 return FALSE;
112 break;
114 case PLAYER_Conductor:
115 if (tag->ti_Data == NULL)
117 player->pl_Source = NULL;
119 else
121 struct Conductor *conductor;
123 lock = LockRealTime(RT_CONDUCTORS);
124 conductor = FindConductor((STRPTR)tag->ti_Data);
125 UnlockRealTime(lock);
127 if (conductor == NULL)
129 if (error != NULL)
131 *error = RTE_NOCONDUCTOR;
134 return FALSE;
138 break;
140 case PLAYER_Ready:
141 if ((BOOL)tag->ti_Data)
143 struct Conductor *conductor = player->pl_Source;
145 player->pl_Flags |= PLAYERF_READY;
147 if (conductor != NULL)
149 ObtainSemaphoreShared(&conductor->cdt_Lock);
151 if (conductor->cdt_Barrier != NULL)
153 Signal(conductor->cdt_Barrier, SIGF_SINGLE);
156 ReleaseSemaphore(&conductor->cdt_Lock);
159 else
161 player->pl_Flags &= ~PLAYERF_READY;
164 break;
166 case PLAYER_AlarmTime:
167 player->pl_Flags |= PLAYERF_ALARMSET;
168 player->pl_AlarmTime = (LONG)tag->ti_Data;
169 break;
171 case PLAYER_Alarm:
172 if ((BOOL)tag->ti_Data)
174 player->pl_Flags |= PLAYERF_ALARMSET;
176 else
178 player->pl_Flags &= ~PLAYERF_ALARMSET;
181 break;
183 case PLAYER_AlarmSigTask:
184 if ((struct Task *)tag->ti_Data == NULL)
186 player->pl_Flags &= ~PLAYERF_ALARMSET;
189 player->pl_Task = (struct Task *)tag->ti_Data;
190 break;
192 case PLAYER_AlarmSigBit:
193 if ((BYTE)tag->ti_Data == -1)
195 player->pl_Flags &= ~PLAYERF_ALARMSET;
198 /* We could use player->pl_Link.ln_Type here */
199 player->pl_Reserved0 = (BYTE)tag->ti_Data; /* NOTE! */
200 break;
202 case PLAYER_Quiet:
203 if ((BOOL)tag->ti_Data)
205 player->pl_Flags |= PLAYERF_QUIET;
207 else
209 player->pl_Flags &= ~PLAYERF_QUIET;
212 break;
214 case PLAYER_UserData:
215 player->pl_UserData = (APTR)tag->ti_Data;
216 break;
218 case PLAYER_ID:
219 player->pl_PlayerID = (UWORD)tag->ti_Data;
220 break;
222 case PLAYER_Conducted:
223 if ((BOOL)tag->ti_Data)
225 player->pl_Flags |= PLAYERF_CONDUCTED;
227 else
229 player->pl_Flags &= ~PLAYERF_CONDUCTED;
232 break;
234 case PLAYER_ExtSync:
235 lock = LockRealTime(RT_CONDUCTORS);
237 if ((BOOL)tag->ti_Data)
239 if (player->pl_Source->cdt_Flags & CONDUCTF_EXTERNAL)
241 /* Only one external synchronizer at a time, please */
242 UnlockRealTime(lock);
244 return FALSE;
247 player->pl_Source->cdt_Flags |= CONDUCTF_EXTERNAL;
248 player->pl_Flags |= PLAYERF_EXTSYNC;
250 else
252 /* If this player was the external synchronizer, we
253 clean up */
254 if (player->pl_Flags & PLAYERF_EXTSYNC)
256 player->pl_Source->cdt_Flags &= ~CONDUCTF_EXTERNAL;
257 player->pl_Source->cdt_Flags &= ~CONDUCTF_GOTTICK;
260 player->pl_Flags &= ~PLAYERF_EXTSYNC;
263 UnlockRealTime(lock);
265 break;
269 /* Consistency checks */
270 if (player->pl_Task == NULL)
272 player->pl_Flags &= ~PLAYERF_ALARMSET;
275 return TRUE;
277 AROS_LIBFUNC_EXIT
278 } /* SetPlayerAttrsA */