acpc_dealer 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 908fe7324c280b21ad9c8ef23910772b67b96c33
4
- data.tar.gz: 001d18938556bd455536bb2cadeab360e80439ac
3
+ metadata.gz: 6efdce0a35fe154dc42128ecbb0c0178d25ca739
4
+ data.tar.gz: 0575059959d08e372dcc0e8b071d5301f54a3a04
5
5
  SHA512:
6
- metadata.gz: 90d7b38a414a69ee50e28e846896533d1da0f1f5d319d3395a6bee5028aea36bcebf946876a8ce7257e28311cc20d8bf281dda13224879b119fd6e8af6b8388a
7
- data.tar.gz: 5574c30df5baa79a5fc380ef2f6a8dff28ca78a0980deb8ad170671167837ecd9ef9cbb551e2821b3232bb37a481c0e1aae3263fef19563beec99176322f735d
6
+ metadata.gz: 4879476724145fb209baab610e1b55e34e60455f6014b1e8224e942d4465a84ae4b9a457c62e99232407297284c24161a97e83442c177c27a3afd94174020c08
7
+ data.tar.gz: 7e7eb6a63b6dfed32a17da8ea70bf4d0df1ca3cf86550e45942a84f066e497f2393ad51b2c98c030e98158a22802a776badcfd552be4717e003cd14ed24021cf
data/lib/acpc_dealer.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'hand_evaluator'
2
2
  require "acpc_dealer/dealer_runner"
3
+ require 'date'
3
4
 
4
5
  module AcpcDealer
5
6
  VENDOR_DIRECTORY = File.expand_path('../../vendor', __FILE__)
@@ -41,4 +42,18 @@ module AcpcDealer
41
42
  super port_number, host_name
42
43
  end
43
44
  end
45
+
46
+ def self.game_def_label(number_of_players, betting_type_key)
47
+ "#{number_of_players}P-#{betting_type_key}"
48
+ end
49
+
50
+ def self.default_match_name(players, game_def, seed)
51
+ "#{players.join('-')}.#{game_def}.r#{seed}.#{date}"
52
+ end
53
+
54
+ private
55
+
56
+ def self.date
57
+ "#{Date.today.strftime('%b%-d_%Y').downcase}"
58
+ end
44
59
  end
@@ -1,3 +1,3 @@
1
1
  module AcpcDealer
2
- VERSION = "2.1.3"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ ./example_player kuhn.limit.3p.game $1 $2
@@ -1444,7 +1444,6 @@ static int printBoardCards( const Game *game, const State *state,
1444
1444
  return c;
1445
1445
  }
1446
1446
 
1447
-
1448
1447
  static int readStateCommon( const char *string, const Game *game,
1449
1448
  State *state )
1450
1449
  {
Binary file
@@ -1,3 +1,3 @@
1
1
  #!/bin/bash
2
2
  THIS_DIR=$( cd "$( dirname "$0" )" && pwd )
3
- cd $THIS_DIR && ./kuhn_3p_equilibrium_player/kuhn_3p_equilibrium_player -n $1 -p $2 --c11 0.0 --b11 0.25 --b21 0.25 --b32 0.9375 --c33 0.0 --c34 1.0 -g kuhn.limit.3p.game
3
+ cd $THIS_DIR && ./kuhn_3p_equilibrium_player/kuhn_3p_equilibrium_player -n $1 -p $2 --c11 0.0 --b11 0.25 --b21 0.25 --b32 0.9375 --c33 0.0 --c34 1.0 -g kuhn.limit.3p.game -r 237363252
@@ -1,3 +1,3 @@
1
1
  #!/bin/bash
2
2
  THIS_DIR=$( cd "$( dirname "$0" )" && pwd )
3
- cd $THIS_DIR && ./kuhn_3p_equilibrium_player/kuhn_3p_equilibrium_player -n $1 -p $2 --c11 0.5 --b11 0.25 --b21 0.0 --b23 0.125 --b32 0.75 --c33 0.0 --c34 0.75 -g kuhn.limit.3p.game
3
+ cd $THIS_DIR && ./kuhn_3p_equilibrium_player/kuhn_3p_equilibrium_player -n $1 -p $2 --c11 0.5 --b11 0.25 --b21 0.0 --b23 0.125 --b32 0.75 --c33 0.0 --c34 0.75 -g kuhn.limit.3p.game -r 237363252
@@ -1,3 +1,3 @@
1
1
  #!/bin/bash
2
2
  THIS_DIR=$( cd "$( dirname "$0" )" && pwd )
3
- cd $THIS_DIR && ./kuhn_3p_equilibrium_player/kuhn_3p_equilibrium_player -n $1 -p $2 --c11 0.33 --b11 0.166667 --b32 0.791667 --c33 0.0 --c34 0.75 -g kuhn.limit.3p.game
3
+ cd $THIS_DIR && ./kuhn_3p_equilibrium_player/kuhn_3p_equilibrium_player -n $1 -p $2 --c11 0.33 --b11 0.166667 --b32 0.791667 --c33 0.0 --c34 0.75 -g kuhn.limit.3p.game -r 237363252
@@ -1,35 +1,35 @@
1
1
  Kuhn 3-Player Equilibrium Player
2
2
  =================================
3
3
  `kuhn_3p_equilibrium_player` is an ACPC compatible player that connects to the
4
- ACPC dealer and plays 3-player Kuhn poker with an equilibrium component
5
- strategy specified by its arguments from one of those specified by
6
- [*A Parameterized Family of Equilibrium Profiles for Three-Player Kuhn
7
- Poker*](http://poker.cs.ualberta.ca/publications/2013-techreport-nl-size.pdf),
8
- written by Duane Szafron, Richard Gibson, and Nathan Sturtevant, found in
9
- *Proceedings of the Twelfth International Conference on Autonomous Agents and
4
+ ACPC dealer and plays 3-player Kuhn poker with an equilibrium component
5
+ strategy specified by its arguments from one of those specified by
6
+ [*A Parameterized Family of Equilibrium Profiles for Three-Player Kuhn
7
+ Poker*](http://poker.cs.ualberta.ca/publications/2013-techreport-nl-size.pdf),
8
+ written by Duane Szafron, Richard Gibson, and Nathan Sturtevant, found in
9
+ *Proceedings of the Twelfth International Conference on Autonomous Agents and
10
10
  Multiagent Systems (AAMAS-13)* in May 2013.
11
-
11
+
12
12
  Equilibrium sub-families
13
13
  --------------------------
14
- There are three sub-families of equilibria identified by Szafron, Gibson, and
14
+ There are three sub-families of equilibria identified by Szafron, Gibson, and
15
15
  Sturtevant, each defined by a different value of parameter `c11`. Depending on
16
16
  the sub-family, different parameters must necessarily be provided, except for
17
17
  `c11`, `b11`, `b32`, `c33`, and `c34`, which are always necessary. Please
18
- see
18
+ see
19
19
  [the paper](http://poker.cs.ualberta.ca/publications/2013-techreport-nl-size.pdf)
20
- for the domain of each paramter.
20
+ for the domain of each paramter.
21
21
 
22
22
  - `c11 = 0.0` sub-family: `b21` must also be provided.
23
23
  - `c11 = 1/2.0` sub-family: `b21` and `b23` must also be provided.
24
- - `0.0 < c11 < 1/2.0` sub-family: No futher parameters are necessary.
24
+ - `0.0 < c11 < 1/2.0` sub-family: No futher parameters are necessary.
25
25
 
26
26
  License
27
27
  -------
28
28
  MIT license (see `LICENCE`).
29
29
 
30
- Acknowledgements
30
+ Acknowledgments
31
31
  ----------------
32
- This project includes software developed for
33
- the CException Project, by Mark VanderVoord and other
32
+ This project includes software developed for
33
+ the CException Project, by Mark VanderVoord and other
34
34
  contributors, as well as the Unity Project, by Mike Karlesky,
35
35
  Mark VanderVoord, and Greg Williams and other contributors.
@@ -19,17 +19,17 @@ DealerConnection new_dealer_connection()
19
19
  return this;
20
20
  }
21
21
 
22
- void connect_to_dealer(DealerConnection* this)
22
+ void connect_to_dealer(DealerConnection* thisPtr)
23
23
  {
24
- assert(this);
24
+ assert(thisPtr);
25
25
 
26
- int sock = connectTo(this->host, this->port);
26
+ int sock = connectTo(thisPtr->host, thisPtr->port);
27
27
  if( sock < 0 ) {
28
28
  exit( EXIT_FAILURE );
29
29
  }
30
- this->toServer = fdopen( sock, "w" );
31
- this->fromServer = fdopen( sock, "r" );
32
- if(!(this->toServer && this->fromServer)) {
30
+ thisPtr->toServer = fdopen( sock, "w" );
31
+ thisPtr->fromServer = fdopen( sock, "r" );
32
+ if(!(thisPtr->toServer && thisPtr->fromServer)) {
33
33
  fprintf( stderr, "ERROR: could not get socket streams\n" );
34
34
  exit( EXIT_FAILURE );
35
35
  }
@@ -37,7 +37,7 @@ void connect_to_dealer(DealerConnection* this)
37
37
  /* send version string to dealer */
38
38
  if(
39
39
  fprintf(
40
- this->toServer,
40
+ thisPtr->toServer,
41
41
  "VERSION:%"PRIu32".%"PRIu32".%"PRIu32"\n",
42
42
  VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION
43
43
  ) != 14
@@ -45,5 +45,5 @@ void connect_to_dealer(DealerConnection* this)
45
45
  fprintf( stderr, "ERROR: could not get send version to server\n" );
46
46
  exit(EXIT_FAILURE);
47
47
  }
48
- fflush(this->toServer);
48
+ fflush(thisPtr->toServer);
49
49
  }
@@ -17,6 +17,6 @@ typedef struct {
17
17
  } DealerConnection;
18
18
 
19
19
  DealerConnection new_dealer_connection();
20
- void connect_to_dealer(DealerConnection* this);
20
+ void connect_to_dealer(DealerConnection* thisPtr);
21
21
 
22
22
  #endif
@@ -9,7 +9,7 @@ Copyright (C) 2013 by the Computer Poker Research Group, University of Alberta
9
9
  #include <math.h>
10
10
  #include <assert.h>
11
11
 
12
- #include "CException.h"
12
+ #include <CException.h>
13
13
  void print_and_throw_error(const char const *message)
14
14
  {
15
15
  fprintf(stderr, "ERROR: %s", message);
@@ -211,7 +211,7 @@ static void check_params(Kuhn3pEquilibriumPlayer* kuhn_3p_e_player)
211
211
 
212
212
  static void action_probs_p0(
213
213
  uint8_t card_rank,
214
- const State const* state,
214
+ const State* state,
215
215
  double* probs
216
216
  ) {
217
217
  assert(probs);
@@ -239,9 +239,9 @@ static void action_probs_p0(
239
239
  }
240
240
 
241
241
  static void action_probs_p1(
242
- const double const* params,
242
+ const double* params,
243
243
  uint8_t card_rank,
244
- const State const* state,
244
+ const State* state,
245
245
  double* probs
246
246
  ) {
247
247
  assert(params);
@@ -309,9 +309,9 @@ static void action_probs_p1(
309
309
  }
310
310
 
311
311
  static void action_probs_p2(
312
- const double const* params,
312
+ const double* params,
313
313
  uint8_t card_rank,
314
- const State const* state,
314
+ const State* state,
315
315
  double* probs
316
316
  )
317
317
  {
@@ -386,8 +386,8 @@ static void action_probs_p2(
386
386
  /* create any private space needed for future calls
387
387
  game_def is a private copy allocated by the dealer for the player's use */
388
388
  Kuhn3pEquilibriumPlayer new_kuhn_3p_equilibrium_player(
389
- const Game const* game_def,
390
- const double const* params,
389
+ const Game* game_def,
390
+ const double* params,
391
391
  uint32_t seed
392
392
  )
393
393
  {
@@ -461,7 +461,7 @@ Action action(
461
461
  This is an extra function, and does _NOT_ need to be implemented
462
462
  to be considered a valid player.h interface. */
463
463
  void action_probs(
464
- const Kuhn3pEquilibriumPlayer const* player,
464
+ const Kuhn3pEquilibriumPlayer* player,
465
465
  MatchState view,
466
466
  double* probs
467
467
  )
@@ -5,9 +5,9 @@ Copyright (C) 2013 by the Computer Poker Research Group, University of Alberta
5
5
  #ifndef __KUHN_3P_EQUILIBRIUM_PLAYER_H__
6
6
  #define __KUHN_3P_EQUILIBRIUM_PLAYER_H__
7
7
 
8
- #include "game.h"
9
- #include "rng.h"
10
- #include "net.h"
8
+ #include <game.h>
9
+ #include <rng.h>
10
+ #include <net.h>
11
11
 
12
12
  // Types ----------------
13
13
  typedef enum {
@@ -33,7 +33,7 @@ typedef struct {
33
33
 
34
34
  typedef enum{JACK_RANK = 9, QUEEN_RANK, KING_RANK, ACE_RANK} CardRank;
35
35
 
36
- typedef enum{A_POSITION = 0, B_POSITION, C_POSITION} PlayerPosition;
36
+ typedef enum{A_POSITION = 0, B_POSITION, C_POSITION, NUM_PLAYERS} PlayerPosition;
37
37
 
38
38
  // Constants -------------
39
39
  #define KUHN_SUIT 3
@@ -41,6 +41,7 @@ typedef enum{A_POSITION = 0, B_POSITION, C_POSITION} PlayerPosition;
41
41
  #define QUEEN makeCard(QUEEN_RANK, KUHN_SUIT)
42
42
  #define KING makeCard(KING_RANK, KUHN_SUIT)
43
43
  #define ACE makeCard(ACE_RANK, KUHN_SUIT)
44
+ #define NUM_CARDS 4
44
45
 
45
46
  #define KAPPA (1/24.0)
46
47
 
@@ -90,8 +91,8 @@ static const double C4[] = {1.0, 1.0, 1.0, 1.0};
90
91
  // Functions -----------------
91
92
  double beta(const Kuhn3pEquilibriumPlayer* kuhn_3p_e_player);
92
93
  Kuhn3pEquilibriumPlayer new_kuhn_3p_equilibrium_player(
93
- const Game const* game_def,
94
- const double const* params,
94
+ const Game* game_def,
95
+ const double* params,
95
96
  uint32_t seed
96
97
  );
97
98
  Action action(
@@ -99,7 +100,7 @@ Action action(
99
100
  MatchState view
100
101
  );
101
102
  void action_probs(
102
- const Kuhn3pEquilibriumPlayer const* player,
103
+ const Kuhn3pEquilibriumPlayer* player,
103
104
  MatchState view,
104
105
  double* probs
105
106
  );
@@ -1,30 +1,30 @@
1
- Copyright (c) 2007 Mark VanderVoord
2
-
3
- Permission is hereby granted, free of charge, to any person
4
- obtaining a copy of this software and associated documentation
5
- files (the "Software"), to deal in the Software without
6
- restriction, including without limitation the rights to use,
7
- copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the
9
- Software is furnished to do so, subject to the following
10
- conditions:
11
-
12
- The above copyright notice and this permission notice shall be
13
- included in all copies or substantial portions of the Software.
14
-
15
- The end-user documentation included with the redistribution, if
16
- any, must include the following acknowledgment: "This product
17
- includes software developed for the CEXCeption Project, by Mark
18
- VanderVoord and other contributors", in the same place and form
19
- as other third-party acknowledgments. Alternately, this
20
- acknowledgment may appear in the software itself, in the same
21
- form and location as other such third-party acknowledgments.
22
-
23
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1
+ Copyright (c) 2007 Mark VanderVoord
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ The end-user documentation included with the redistribution, if
16
+ any, must include the following acknowledgment: "This product
17
+ includes software developed for the CEXCeption Project, by Mark
18
+ VanderVoord and other contributors", in the same place and form
19
+ as other third-party acknowledgments. Alternately, this
20
+ acknowledgment may appear in the software itself, in the same
21
+ form and location as other such third-party acknowledgments.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30
30
  OTHER DEALINGS IN THE SOFTWARE.
@@ -1,242 +1,242 @@
1
- ====================================================================
2
- CException
3
- ====================================================================
4
-
5
- CException is a basic exception framework for C, suitable for use in
6
- embedded applications. It provides an exception framework similar in
7
- use to C++, but with much less overhead.
8
-
9
- CException uses C standard library functions setjmp and longjmp to
10
- operate. As long as the target system has these two functions defined,
11
- this library should be useable with very little configuration. It
12
- even supports environments where multiple program flows are in use,
13
- such as real-time operating systems.
14
-
15
- There are about a gabillion exception frameworks using a similar
16
- setjmp/longjmp method out there... and there will probably be more
17
- in the future. Unfortunately, when we started our last embedded
18
- project, all those that existed either (a) did not support multiple
19
- tasks (therefore multiple stacks) or (b) were way more complex than
20
- we really wanted. CException was born.
21
-
22
- Why use CException?
23
-
24
- 0. It's ANSI C, and it beats passing error codes around.
25
-
26
- 1. You want something simple... CException throws a single id. You can
27
- define those ID's to be whatever you like. You might even choose which
28
- type that number is for your project. But that's as far as it goes.
29
- We weren't interested in passing objects or structs or strings...
30
- just simple error codes.
31
-
32
- 2. Performance... CException can be configured for single tasking or
33
- multitasking. In single tasking, there is very little overhead past
34
- the setjmp/longjmp calls (which are already fast). In multitasking,
35
- your only additional overhead is the time it takes you to determine
36
- a unique task id 0 - num_tasks.
37
-
38
- For the latest version, go to http://cexception.sourceforge.net
39
-
40
- --------------------------------------------------------------------
41
- CONTENTS OF THIS DOCUMENT
42
- --------------------------------------------------------------------
43
-
44
- Usage
45
- Limitations
46
- API
47
- Configuration
48
- Testing
49
- License
50
-
51
- --------------------------------------------------------------------
52
- Usage
53
- --------------------------------------------------------------------
54
-
55
- Code that is to be protected are wrapped in Try { } Catch { } blocks.
56
- The code directly following the Try call is "protected", meaning that
57
- if any Throws occur, program control is directly transferred to the
58
- start of the Catch block.
59
-
60
- A numerical exception ID is included with Throw, and is made accessible
61
- from the Catch block.
62
-
63
- Throws can occur from within function calls (nested as deeply as you
64
- like) or directly from within the function itself.
65
-
66
- --------------------------------------------------------------------
67
- Limitations
68
- --------------------------------------------------------------------
69
-
70
- This library was made to be as fast as possible, and provide basic
71
- exception handling. It is not a full-blown exception library. Because
72
- of this, there are a few limitations that should be observed in order
73
- to successfully utilize this library:
74
-
75
- 1. Do not directly "return" from within a Try block, nor "goto"
76
- into or out of a Try block.
77
-
78
- Why?
79
-
80
- The "Try" macro allocates some local memory and alters a global
81
- pointer. These are cleaned up at the top of the "Catch" macro.
82
- Gotos and returns would bypass some of these steps, resulting in
83
- memory leaks or unpredictable behavior.
84
-
85
- 2. If (a) you change local (stack) variables within your Try block,
86
- AND (b) wish to make use of the updated values after an exception
87
- is thrown, those variables should be made volatile. Note that this
88
- is ONLY for locals and ONLY when you need access to them after a
89
- throw.
90
-
91
- Why?
92
-
93
- Compilers optimize. There is no way to guarantee that the actual
94
- memory location was updated and not just a register unless the
95
- variable is marked volatile.
96
-
97
- 3. Memory which is malloc'd or new'd is not automatically released
98
- when an error is thrown. This will sometimes be desirable, and
99
- othertimes may not. It will be the responsibility of the Catch
100
- block to perform this kind of cleanup.
101
-
102
- Why?
103
-
104
- There's just no easy way to track malloc'd memory, etc., without
105
- replacing or wrapping malloc calls or something like that. This
106
- is a light framework, so these options were not desirable.
107
-
108
- --------------------------------------------------------------------
109
- API
110
- --------------------------------------------------------------------
111
-
112
- Try
113
- ---
114
-
115
- Try is a macro which starts a protected block. It MUST be followed by
116
- a pair of braces or a single protected line (similar to an 'if'),
117
- enclosing the data that is to be protected. It MUST be followed by a
118
- Catch block (don't worry, you'll get compiler errors to let you know if
119
- you mess any of that up).
120
-
121
- Catch(e)
122
- --------
123
-
124
- Catch is a macro which ends the Try block and starts the error handling
125
- block. The catch block is called if and only if an exception was thrown
126
- while within the Try block. This error was thrown by a Throw call
127
- somewhere within Try (or within a function called within Try, or a function
128
- called by a function called within Try, etc).
129
-
130
- The single parameter 'e' is filled with the error code which was thrown.
131
- This can be used for reporting, conditional cleanup, etc. (or you can just
132
- ignore it if you really want... people ignore return codes all the time,
133
- right?). 'e' should be of type EXCEPTION_T;
134
-
135
- Throw(e)
136
- --------
137
-
138
- The method of throwing an error. Throws should only occur from within a
139
- protected (Try...Catch) block, though it may easily be nested many function
140
- calls deep without an impact on performance or functionality. Throw takes
141
- a single argument, which is an exception id which will be passed to Catch
142
- as the reason for the error.
143
-
144
- If you wish to Rethrow an error, this can be done by calling Throw(e) with
145
- the error code you just caught. It IS valid to throw from a catch block.
146
-
147
- --------------------------------------------------------------------
148
- CONFIGURATION
149
- --------------------------------------------------------------------
150
-
151
- CException is a mostly portable library. It has one universal
152
- dependency, and some macros which are required if working in a
153
- multi-tasking environment.
154
-
155
- 1. The standard C library setjmp must be available. Since this is part
156
- of the standard library, chances are good that you'll be fine.
157
-
158
- 2. If working in a multitasking environment, methods for obtaining an
159
- index into an array of frames and to get the overall number of
160
- id's are required. If the OS supports a method to retrieve Task
161
- ID's, and those Tasks are number 0, 1, 2... you are in an ideal
162
- situation. Otherwise, a more creative mapping function may be
163
- required. Note that this function is likely to be called twice
164
- for each protected block and once during a throw. This is the
165
- only overhead in the system.
166
-
167
- Exception.h
168
- -----------------
169
- By convention, most projects include Exception.h which defines any
170
- further requirements, then calls CException.h to do the gruntwork. All
171
- of these are optional. You could directly include CException.h if
172
- you wanted and just use the defaults provided.
173
-
174
- EXCEPTION_T - Set this to the type you want your exception id's
175
- to be. Defaults to 'unsigned int'.
176
-
177
- EXCEPTION_NONE - Set this to a number which will never be an
178
- exception id in your system. Defaults to 0x5a5a5a5a.
179
-
180
- EXCEPTION_GET_ID - If in a multi-tasking environment, this should be
181
- set to be a call to the function described in #2 above.
182
- Defaults to just return 0 all the time (good for
183
- single tasking environments)
184
-
185
- EXCEPTION_NUM_ID - If in a multi-tasking environment, this should be set
186
- to the number of ID's required (usually the number of
187
- tasks in the system). Defaults to 1 (for single
188
- tasking environments).
189
-
190
- CEXCEPTION_NO_CATCH_HANDLER(id) - This macro can be optionally specified.
191
- It allows you to specify code to be called when a Throw
192
- is made outside of Try...Catch protection. Consider
193
- this the emergency fallback plan for when something has
194
- gone terribly wrong.
195
-
196
- You may also want to include any header files which will commonly be
197
- needed by the rest of your application where it uses exception handling
198
- here. For example, OS header files or exception codes would be useful.
199
-
200
- --------------------------------------------------------------------
201
- TESTING
202
- --------------------------------------------------------------------
203
-
204
- If you want to validate that CException works with your tools or that
205
- it works with your custom configuration, you may want to run the test
206
- suite.
207
-
208
- The test suite included makes use of the Unity Test Framework. It will
209
- require a native C compiler. The example makefile uses MinGW's gcc.
210
- Modify the makefile to include the proper paths to tools, then run 'make'
211
- to compile and run the test application.
212
-
213
- C_COMPILER - The C compiler to use to perform the tests
214
- C_LIBS - The path to the C libraries (including setjmp)
215
- UNITY_DIR - The path to the Unity framework (required to run tests)
216
- (get it at http://unity.sourceforge.net)
217
-
218
- --------------------------------------------------------------------
219
- LICENSE
220
- --------------------------------------------------------------------
221
-
222
- This software is licensed under the MIT License
223
-
224
- Copyright (c) 2007-2012 Mark VanderVoord
225
-
226
- Permission is hereby granted, free of charge, to any person obtaining a copy
227
- of this software and associated documentation files (the "Software"), to deal
228
- in the Software without restriction, including without limitation the rights
229
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
230
- copies of the Software, and to permit persons to whom the Software is
231
- furnished to do so, subject to the following conditions:
232
-
233
- The above copyright notice and this permission notice shall be included in
234
- all copies or substantial portions of the Software.
235
-
236
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
237
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
238
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
239
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
240
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
241
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
242
- THE SOFTWARE.
1
+ ====================================================================
2
+ CException
3
+ ====================================================================
4
+
5
+ CException is a basic exception framework for C, suitable for use in
6
+ embedded applications. It provides an exception framework similar in
7
+ use to C++, but with much less overhead.
8
+
9
+ CException uses C standard library functions setjmp and longjmp to
10
+ operate. As long as the target system has these two functions defined,
11
+ this library should be useable with very little configuration. It
12
+ even supports environments where multiple program flows are in use,
13
+ such as real-time operating systems.
14
+
15
+ There are about a gabillion exception frameworks using a similar
16
+ setjmp/longjmp method out there... and there will probably be more
17
+ in the future. Unfortunately, when we started our last embedded
18
+ project, all those that existed either (a) did not support multiple
19
+ tasks (therefore multiple stacks) or (b) were way more complex than
20
+ we really wanted. CException was born.
21
+
22
+ Why use CException?
23
+
24
+ 0. It's ANSI C, and it beats passing error codes around.
25
+
26
+ 1. You want something simple... CException throws a single id. You can
27
+ define those ID's to be whatever you like. You might even choose which
28
+ type that number is for your project. But that's as far as it goes.
29
+ We weren't interested in passing objects or structs or strings...
30
+ just simple error codes.
31
+
32
+ 2. Performance... CException can be configured for single tasking or
33
+ multitasking. In single tasking, there is very little overhead past
34
+ the setjmp/longjmp calls (which are already fast). In multitasking,
35
+ your only additional overhead is the time it takes you to determine
36
+ a unique task id 0 - num_tasks.
37
+
38
+ For the latest version, go to http://cexception.sourceforge.net
39
+
40
+ --------------------------------------------------------------------
41
+ CONTENTS OF THIS DOCUMENT
42
+ --------------------------------------------------------------------
43
+
44
+ Usage
45
+ Limitations
46
+ API
47
+ Configuration
48
+ Testing
49
+ License
50
+
51
+ --------------------------------------------------------------------
52
+ Usage
53
+ --------------------------------------------------------------------
54
+
55
+ Code that is to be protected are wrapped in Try { } Catch { } blocks.
56
+ The code directly following the Try call is "protected", meaning that
57
+ if any Throws occur, program control is directly transferred to the
58
+ start of the Catch block.
59
+
60
+ A numerical exception ID is included with Throw, and is made accessible
61
+ from the Catch block.
62
+
63
+ Throws can occur from within function calls (nested as deeply as you
64
+ like) or directly from within the function itself.
65
+
66
+ --------------------------------------------------------------------
67
+ Limitations
68
+ --------------------------------------------------------------------
69
+
70
+ This library was made to be as fast as possible, and provide basic
71
+ exception handling. It is not a full-blown exception library. Because
72
+ of this, there are a few limitations that should be observed in order
73
+ to successfully utilize this library:
74
+
75
+ 1. Do not directly "return" from within a Try block, nor "goto"
76
+ into or out of a Try block.
77
+
78
+ Why?
79
+
80
+ The "Try" macro allocates some local memory and alters a global
81
+ pointer. These are cleaned up at the top of the "Catch" macro.
82
+ Gotos and returns would bypass some of these steps, resulting in
83
+ memory leaks or unpredictable behavior.
84
+
85
+ 2. If (a) you change local (stack) variables within your Try block,
86
+ AND (b) wish to make use of the updated values after an exception
87
+ is thrown, those variables should be made volatile. Note that this
88
+ is ONLY for locals and ONLY when you need access to them after a
89
+ throw.
90
+
91
+ Why?
92
+
93
+ Compilers optimize. There is no way to guarantee that the actual
94
+ memory location was updated and not just a register unless the
95
+ variable is marked volatile.
96
+
97
+ 3. Memory which is malloc'd or new'd is not automatically released
98
+ when an error is thrown. This will sometimes be desirable, and
99
+ othertimes may not. It will be the responsibility of the Catch
100
+ block to perform this kind of cleanup.
101
+
102
+ Why?
103
+
104
+ There's just no easy way to track malloc'd memory, etc., without
105
+ replacing or wrapping malloc calls or something like that. This
106
+ is a light framework, so these options were not desirable.
107
+
108
+ --------------------------------------------------------------------
109
+ API
110
+ --------------------------------------------------------------------
111
+
112
+ Try
113
+ ---
114
+
115
+ Try is a macro which starts a protected block. It MUST be followed by
116
+ a pair of braces or a single protected line (similar to an 'if'),
117
+ enclosing the data that is to be protected. It MUST be followed by a
118
+ Catch block (don't worry, you'll get compiler errors to let you know if
119
+ you mess any of that up).
120
+
121
+ Catch(e)
122
+ --------
123
+
124
+ Catch is a macro which ends the Try block and starts the error handling
125
+ block. The catch block is called if and only if an exception was thrown
126
+ while within the Try block. This error was thrown by a Throw call
127
+ somewhere within Try (or within a function called within Try, or a function
128
+ called by a function called within Try, etc).
129
+
130
+ The single parameter 'e' is filled with the error code which was thrown.
131
+ This can be used for reporting, conditional cleanup, etc. (or you can just
132
+ ignore it if you really want... people ignore return codes all the time,
133
+ right?). 'e' should be of type EXCEPTION_T;
134
+
135
+ Throw(e)
136
+ --------
137
+
138
+ The method of throwing an error. Throws should only occur from within a
139
+ protected (Try...Catch) block, though it may easily be nested many function
140
+ calls deep without an impact on performance or functionality. Throw takes
141
+ a single argument, which is an exception id which will be passed to Catch
142
+ as the reason for the error.
143
+
144
+ If you wish to Rethrow an error, this can be done by calling Throw(e) with
145
+ the error code you just caught. It IS valid to throw from a catch block.
146
+
147
+ --------------------------------------------------------------------
148
+ CONFIGURATION
149
+ --------------------------------------------------------------------
150
+
151
+ CException is a mostly portable library. It has one universal
152
+ dependency, and some macros which are required if working in a
153
+ multi-tasking environment.
154
+
155
+ 1. The standard C library setjmp must be available. Since this is part
156
+ of the standard library, chances are good that you'll be fine.
157
+
158
+ 2. If working in a multitasking environment, methods for obtaining an
159
+ index into an array of frames and to get the overall number of
160
+ id's are required. If the OS supports a method to retrieve Task
161
+ ID's, and those Tasks are number 0, 1, 2... you are in an ideal
162
+ situation. Otherwise, a more creative mapping function may be
163
+ required. Note that this function is likely to be called twice
164
+ for each protected block and once during a throw. This is the
165
+ only overhead in the system.
166
+
167
+ Exception.h
168
+ -----------------
169
+ By convention, most projects include Exception.h which defines any
170
+ further requirements, then calls CException.h to do the gruntwork. All
171
+ of these are optional. You could directly include CException.h if
172
+ you wanted and just use the defaults provided.
173
+
174
+ EXCEPTION_T - Set this to the type you want your exception id's
175
+ to be. Defaults to 'unsigned int'.
176
+
177
+ EXCEPTION_NONE - Set this to a number which will never be an
178
+ exception id in your system. Defaults to 0x5a5a5a5a.
179
+
180
+ EXCEPTION_GET_ID - If in a multi-tasking environment, this should be
181
+ set to be a call to the function described in #2 above.
182
+ Defaults to just return 0 all the time (good for
183
+ single tasking environments)
184
+
185
+ EXCEPTION_NUM_ID - If in a multi-tasking environment, this should be set
186
+ to the number of ID's required (usually the number of
187
+ tasks in the system). Defaults to 1 (for single
188
+ tasking environments).
189
+
190
+ CEXCEPTION_NO_CATCH_HANDLER(id) - This macro can be optionally specified.
191
+ It allows you to specify code to be called when a Throw
192
+ is made outside of Try...Catch protection. Consider
193
+ this the emergency fallback plan for when something has
194
+ gone terribly wrong.
195
+
196
+ You may also want to include any header files which will commonly be
197
+ needed by the rest of your application where it uses exception handling
198
+ here. For example, OS header files or exception codes would be useful.
199
+
200
+ --------------------------------------------------------------------
201
+ TESTING
202
+ --------------------------------------------------------------------
203
+
204
+ If you want to validate that CException works with your tools or that
205
+ it works with your custom configuration, you may want to run the test
206
+ suite.
207
+
208
+ The test suite included makes use of the Unity Test Framework. It will
209
+ require a native C compiler. The example makefile uses MinGW's gcc.
210
+ Modify the makefile to include the proper paths to tools, then run 'make'
211
+ to compile and run the test application.
212
+
213
+ C_COMPILER - The C compiler to use to perform the tests
214
+ C_LIBS - The path to the C libraries (including setjmp)
215
+ UNITY_DIR - The path to the Unity framework (required to run tests)
216
+ (get it at http://unity.sourceforge.net)
217
+
218
+ --------------------------------------------------------------------
219
+ LICENSE
220
+ --------------------------------------------------------------------
221
+
222
+ This software is licensed under the MIT License
223
+
224
+ Copyright (c) 2007-2012 Mark VanderVoord
225
+
226
+ Permission is hereby granted, free of charge, to any person obtaining a copy
227
+ of this software and associated documentation files (the "Software"), to deal
228
+ in the Software without restriction, including without limitation the rights
229
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
230
+ copies of the Software, and to permit persons to whom the Software is
231
+ furnished to do so, subject to the following conditions:
232
+
233
+ The above copyright notice and this permission notice shall be included in
234
+ all copies or substantial portions of the Software.
235
+
236
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
237
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
238
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
239
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
240
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
241
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
242
+ THE SOFTWARE.