Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting SDLNames Defines to Constants #446

Merged
merged 13 commits into from
Sep 27, 2016

Conversation

asm09fsu
Copy link
Contributor

Fixes #3

This PR is ready for review.

Risk

This PR makes no API changes.

Testing Plan

These changes have 100% passing tests.

Summary

This PR changes all #defines in SDLNames.h to use a typedef of NSString* called SDLName. Also, SDLFunctionID now uses a static NSDictionary for function names/ids to improve performance, and only one should ever need to be allocated.

Changelog

Enchancements
  • Updated all #defines in SDLNames.h to use constants.
  • Updated SDLFunctionID to use a static dictionary.

…so modified SDLFunctionID to use a static dictionary.
@asm09fsu asm09fsu added enhancement best practice Not a defect but something that should be improved anyway labels Sep 21, 2016
@asm09fsu asm09fsu changed the base branch from master to develop September 21, 2016 23:44
@@ -505,7 +505,7 @@
5D61FCF91A84238C00846EE7 /* SDLMenuParams.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D61FB0C1A84238A00846EE7 /* SDLMenuParams.m */; };
5D61FCFA1A84238C00846EE7 /* SDLMyKey.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D61FB0D1A84238A00846EE7 /* SDLMyKey.h */; settings = {ATTRIBUTES = (Public, ); }; };
5D61FCFB1A84238C00846EE7 /* SDLMyKey.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D61FB0E1A84238A00846EE7 /* SDLMyKey.m */; };
5D61FCFC1A84238C00846EE7 /* SDLNames.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D61FB0F1A84238A00846EE7 /* SDLNames.h */; };
5D61FCFC1A84238C00846EE7 /* SDLNames.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D61FB0F1A84238A00846EE7 /* SDLNames.h */; settings = {ATTRIBUTES = (Public, ); }; };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have to be public now?

} else {
[parameters removeObjectForKey:NAMES_ttsName];
[parameters removeObjectForKey:SDLNameTtsName];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be SDLNameTTSName?

@98305: SDLNameOnSyncPData
};
}
self.functionIDs = functionIDs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be better as a singleton? Kind of weird to have to create a new object every time.

- (NSString *)getFunctionName:(int)functionID {
return [functionIDs objectForKey:[NSString stringWithFormat:@"%d", functionID]];
- (SDLName)getFunctionName:(int)functionID {
return [self.functionIDs objectForKey:@(functionID)];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can use shortened syntax: self.functionIDs[@(functionID)]


@property (nonatomic, strong, nonnull) NSDictionary* functionIDs;

@end

@implementation SDLFunctionID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class can be private

}
return self;
}

- (NSString *)getFunctionName:(int)functionID {
return [functionIDs objectForKey:[NSString stringWithFormat:@"%d", functionID]];
- (SDLName)getFunctionName:(int)functionID {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get function naming is very Java. Should probably be more like functionNameForId:

}

- (void)setUtcYear:(NSNumber *)utcYear {
if (utcYear != nil) {
[store setObject:utcYear forKey:NAMES_utcYear];
[store setObject:utcYear forKey:SDLNameUtcYear];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above comment regarding capitalization?

@asm09fsu
Copy link
Contributor Author

@joeljfischer I think this is ready, can you validate?

joeljfischer and others added 2 commits September 23, 2016 09:24
…into feature/issue_3_constant_names

* 'develop' of https://github.com/smartdevicelink/sdl_ios:
  Update public imports for organization and to remove a duplicate
  A few more updates to travis scripts
  Try better Travis CI build formatting
@codecov-io
Copy link

codecov-io commented Sep 23, 2016

Current coverage is 67.39% (diff: 69.55%)

Merging #446 into develop will increase coverage by 39.71%

@@            develop       #446   diff @@
==========================================
  Files           334        334           
  Lines         10451      10515     +64   
  Methods        3059       3061      +2   
  Messages          0          0           
  Branches        799        799           
==========================================
+ Hits           2893       7087   +4194   
+ Misses         7500       3036   -4464   
- Partials         58        392    +334   

Powered by Codecov. Last update 30f9b83...7246055

@@ -427,7 +427,7 @@
5D61FCAA1A84238C00846EE7 /* SDLFileType.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D61FABD1A84238A00846EE7 /* SDLFileType.m */; };
5D61FCAB1A84238C00846EE7 /* SDLFuelCutoffStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D61FABE1A84238A00846EE7 /* SDLFuelCutoffStatus.h */; settings = {ATTRIBUTES = (Public, ); }; };
5D61FCAC1A84238C00846EE7 /* SDLFuelCutoffStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D61FABF1A84238A00846EE7 /* SDLFuelCutoffStatus.m */; };
5D61FCAD1A84238C00846EE7 /* SDLFunctionID.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D61FAC01A84238A00846EE7 /* SDLFunctionID.h */; };
5D61FCAD1A84238C00846EE7 /* SDLFunctionID.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D61FAC01A84238A00846EE7 /* SDLFunctionID.h */; settings = {ATTRIBUTES = (Private, ); }; };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, we don't actually want 'private', we want 'project'.

Copy link
Contributor

@joeljfischer joeljfischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that was a needle in haystack hunt...

@@ -42,7 +42,7 @@ __deprecated_msg("Use SDLManager instead")
- (void)sendRPCRequest:(SDLRPCMessage *)msg __deprecated_msg("use -sendRPC: instead");

- (void)handleRPCDictionary:(NSDictionary *)dictionary;
- (void)handleRpcMessage:(NSDictionary *)msg __deprecated_msg("use -handleRPCDictionary: instead");
- (void)handleRPCMessage:(NSDictionary *)msg __deprecated_msg("use -handleRPCDictionary: instead");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cannot be changed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a mis-commit when using regex to modify the 1,000,000 files involved in this PR.

@@ -203,7 +203,7 @@ - (BOOL)sendRPC:(SDLRPCMessage *)message encrypted:(BOOL)encryption error:(NSErr
// Build a binary header
// Serialize the RPC data into an NSData
SDLRPCPayload *rpcPayload = [[SDLRPCPayload alloc] init];
rpcPayload.functionID = [[[[SDLFunctionID alloc] init] getFunctionID:[message getFunctionName]] intValue];
rpcPayload.functionID = [[[SDLFunctionID sharedInstance] functionIdForName:[message functionNameForId]] intValue];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things about this seem odd.

  1. Why are we getting the name for the id, then the id for the name? Seems circular?
  2. Wouldn't the message's functionNameForId method just be functionName if we're not passing anything? Can't find if or where that changed in this PR though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems we need a way to retrieve the id for a function name (as a response perhaps?) and the function name for the id (to send a request?). This is just a slight modification/improvement over how it's already been done. A full revamp can be done for 5.0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think i was just confused by the change in [message functionNameForId]. It's actually getting the function name not the id.

@@ -13,7 +13,7 @@

- (instancetype)initWithName:(NSString *)name;
- (instancetype)initWithDictionary:(NSMutableDictionary *)dict;
- (NSString *)getFunctionName;
- (NSString *)functionNameForId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, here it is, guessing a copy-paste error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So to be clear, this has to stay the same to preserve the impact of this PR.

@joeljfischer joeljfischer merged commit 2f587e1 into develop Sep 27, 2016
@joeljfischer joeljfischer deleted the feature/issue_3_constant_names branch September 27, 2016 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
best practice Not a defect but something that should be improved anyway
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants