2014 snapchat source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.2 KiB

  1. //
  2. // SCCaptureStateTransitionBookKeeper.m
  3. // Snapchat
  4. //
  5. // Created by Lin Jia on 10/27/17.
  6. //
  7. //
  8. #import "SCCaptureStateMachineBookKeeper.h"
  9. #import "SCCaptureStateUtil.h"
  10. #import "SCLogger+Camera.h"
  11. #import <SCFoundation/SCAssertWrapper.h>
  12. #import <SCLogger/SCCameraMetrics.h>
  13. @interface SCCaptureStateMachineBookKeeper () {
  14. NSDate *_lastStateStartTime;
  15. }
  16. @end
  17. @implementation SCCaptureStateMachineBookKeeper
  18. - (void)stateTransitionFrom:(SCCaptureStateMachineStateId)fromId
  19. to:(SCCaptureStateMachineStateId)toId
  20. context:(NSString *)context
  21. {
  22. NSDate *date = [NSDate date];
  23. SCLogCaptureStateMachineInfo(@"State %@ life span: %f seconds, transition to: %@, in context:%@, at: %@ \n",
  24. SCCaptureStateName(fromId), [date timeIntervalSinceDate:_lastStateStartTime],
  25. SCCaptureStateName(toId), context, date);
  26. _lastStateStartTime = date;
  27. }
  28. - (void)state:(SCCaptureStateMachineStateId)captureState
  29. illegalAPIcalled:(NSString *)illegalAPIName
  30. callStack:(NSArray<NSString *> *)callStack
  31. context:(NSString *)context
  32. {
  33. SCAssert(callStack, @"call stack empty");
  34. SCAssert(illegalAPIName, @"");
  35. SCAssert(context, @"Context is empty");
  36. SCLogCaptureStateMachineError(@"State: %@, illegal API invoke: %@, at: %@, callstack: %@ \n",
  37. SCCaptureStateName(captureState), illegalAPIName, [NSDate date], callStack);
  38. NSArray<NSString *> *reportedArray =
  39. [callStack count] > 15 ? [callStack subarrayWithRange:NSMakeRange(0, 15)] : callStack;
  40. [[SCLogger sharedInstance] logEvent:kSCCameraStateMachineIllegalAPICall
  41. parameters:@{
  42. @"state" : SCCaptureStateName(captureState),
  43. @"API" : illegalAPIName,
  44. @"call_stack" : reportedArray,
  45. @"context" : context
  46. }];
  47. }
  48. - (void)logAPICalled:(NSString *)apiName context:(NSString *)context
  49. {
  50. SCAssert(apiName, @"API name is empty");
  51. SCAssert(context, @"Context is empty");
  52. SCLogCaptureStateMachineInfo(@"api: %@ context: %@", apiName, context);
  53. }
  54. @end