| 26 | static ChecksumHandler s_handler_map[MAX_HANDLER_SIZE] = {{NULL, NULL, NULL}}; |
| 27 | |
| 28 | int RegisterChecksumHandler(ChecksumType type, ChecksumHandler handler) { |
| 29 | if (NULL == handler.Compute) { |
| 30 | LOG(FATAL) << "Invalid parameter: handler function is NULL"; |
| 31 | return -1; |
| 32 | } |
| 33 | int index = type; |
| 34 | if (index < 0 || index >= MAX_HANDLER_SIZE) { |
| 35 | LOG(FATAL) << "ChecksumType=" << type << " is out of range"; |
| 36 | return -1; |
| 37 | } |
| 38 | if (s_handler_map[index].Compute != NULL) { |
| 39 | LOG(FATAL) << "ChecksumType=" << type << " was registered"; |
| 40 | return -1; |
| 41 | } |
| 42 | s_handler_map[index] = handler; |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | // Find ChecksumHandler by type. |
| 47 | // Returns NULL if not found |
no outgoing calls
no test coverage detected