Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Base class for generating wrapper functions for PPAPI methods. | 5 """Base class for generating wrapper functions for PPAPI methods. |
| 6 """ | 6 """ |
| 7 | 7 |
| 8 from datetime import datetime | 8 from datetime import datetime |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 while (*next != NULL) { | 150 while (*next != NULL) { |
| 151 if (mystrcmp(name, (*next)->iface_macro) == 0) return *next; | 151 if (mystrcmp(name, (*next)->iface_macro) == 0) return *next; |
| 152 ++next; | 152 ++next; |
| 153 } | 153 } |
| 154 return NULL; | 154 return NULL; |
| 155 } | 155 } |
| 156 | 156 |
| 157 const void *__%(wrapper_prefix)s_PPBGetInterface(const char *name) { | 157 const void *__%(wrapper_prefix)s_PPBGetInterface(const char *name) { |
| 158 struct %(wrapper_struct)s *wrapper = %(wrapper_prefix)sPPBShimIface(name); | 158 struct %(wrapper_struct)s *wrapper = %(wrapper_prefix)sPPBShimIface(name); |
| 159 if (wrapper == NULL) { | 159 if (wrapper == NULL) { |
| 160 /* We don't have an IDL for this, for some reason. Take our chances. */ | 160 /* We don't have an IDL for this, for some reason. Take our chances. */ |
|
jvoung (off chromium)
2013/06/20 19:46:57
Can you update the emitted comment?
This is now n
| |
| 161 return (*__real_PPBGetInterface)(name); | 161 return (*__real_PPBGetInterface)(name); |
| 162 } | 162 } |
| 163 | 163 |
| 164 /* Initialize the real_iface if it hasn't been. The wrapper depends on it. */ | 164 /* Initialize the real_iface if it hasn't been. The wrapper depends on it. */ |
| 165 if (wrapper->real_iface == NULL) { | 165 if (wrapper->real_iface == NULL) { |
| 166 const void *iface = (*__real_PPBGetInterface)(name); | 166 const void *iface = (*__real_PPBGetInterface)(name); |
| 167 if (NULL == iface) return NULL; | 167 if (NULL == iface) return NULL; |
| 168 wrapper->real_iface = iface; | 168 wrapper->real_iface = iface; |
| 169 } | 169 } |
| 170 | 170 |
| 171 if (wrapper->wrapped_iface) { | 171 if (wrapper->wrapped_iface) { |
| 172 return wrapper->wrapped_iface; | 172 return wrapper->wrapped_iface; |
| 173 } else { | 173 } else { |
| 174 return wrapper->real_iface; | 174 return wrapper->real_iface; |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 const void *__%(wrapper_prefix)s_PPPGetInterface(const char *name) { | 178 const void *__%(wrapper_prefix)s_PPPGetInterface(const char *name) { |
| 179 struct %(wrapper_struct)s *wrapper = %(wrapper_prefix)sPPPShimIface(name); | 179 struct %(wrapper_struct)s *wrapper = %(wrapper_prefix)sPPPShimIface(name); |
| 180 if (wrapper == NULL) { | 180 if (wrapper == NULL) { |
| 181 /* We don't have an IDL for this, for some reason. Take our chances. */ | 181 /* We don't have an IDL for this, for some reason. Take our chances. */ |
|
jvoung (off chromium)
2013/06/20 19:46:57
same update for comment.
| |
| 182 return (*__real_PPPGetInterface)(name); | 182 return (*__real_PPPGetInterface)(name); |
| 183 } | 183 } |
| 184 | 184 |
| 185 /* Initialize the real_iface if it hasn't been. The wrapper depends on it. */ | 185 /* Initialize the real_iface if it hasn't been. The wrapper depends on it. */ |
| 186 if (wrapper->real_iface == NULL) { | 186 if (wrapper->real_iface == NULL) { |
| 187 const void *iface = (*__real_PPPGetInterface)(name); | 187 const void *iface = (*__real_PPPGetInterface)(name); |
| 188 if (NULL == iface) return NULL; | 188 if (NULL == iface) return NULL; |
| 189 wrapper->real_iface = iface; | 189 wrapper->real_iface = iface; |
| 190 } | 190 } |
| 191 | 191 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 def GetWrapperInfoName(self, iface): | 357 def GetWrapperInfoName(self, iface): |
| 358 return '%s_WrapperInfo_%s' % (self.wrapper_prefix, iface.struct_name) | 358 return '%s_WrapperInfo_%s' % (self.wrapper_prefix, iface.struct_name) |
| 359 | 359 |
| 360 | 360 |
| 361 def GenerateWrapperInfoAndCollection(self, iface_releases, out): | 361 def GenerateWrapperInfoAndCollection(self, iface_releases, out): |
| 362 for iface in iface_releases: | 362 for iface in iface_releases: |
| 363 iface_macro = self.cgen.GetInterfaceMacro(iface.node, iface.version) | 363 iface_macro = self.cgen.GetInterfaceMacro(iface.node, iface.version) |
| 364 if iface.needs_wrapping: | 364 if iface.needs_wrapping: |
| 365 wrap_iface = '(void *) &%s_Wrappers_%s' % (self.wrapper_prefix, | 365 wrap_iface = '(void *) &%s_Wrappers_%s' % (self.wrapper_prefix, |
| 366 iface.struct_name) | 366 iface.struct_name) |
| 367 else: | 367 out.Write("""static struct %s %s = { |
| 368 wrap_iface = 'NULL /* Still need slot for real_iface */' | |
| 369 out.Write("""static struct %s %s = { | |
| 370 .iface_macro = %s, | 368 .iface_macro = %s, |
| 371 .wrapped_iface = %s, | 369 .wrapped_iface = %s, |
| 372 .real_iface = NULL | 370 .real_iface = NULL |
| 373 };\n\n""" % (self.GetWrapperMetadataName(), | 371 };\n\n""" % (self.GetWrapperMetadataName(), |
| 374 self.GetWrapperInfoName(iface), | 372 self.GetWrapperInfoName(iface), |
| 375 iface_macro, | 373 iface_macro, |
| 376 wrap_iface)) | 374 wrap_iface)) |
| 377 | 375 |
| 378 # Now generate NULL terminated arrays of the above wrapper infos. | 376 # Now generate NULL terminated arrays of the above wrapper infos. |
| 379 ppb_wrapper_infos = [] | 377 ppb_wrapper_infos = [] |
| 380 ppp_wrapper_infos = [] | 378 ppp_wrapper_infos = [] |
| 381 for iface in iface_releases: | 379 for iface in iface_releases: |
| 382 appender = PPKind.ChoosePPFunc(iface, | 380 if iface.needs_wrapping: |
| 383 ppb_wrapper_infos.append, | 381 appender = PPKind.ChoosePPFunc(iface, |
| 384 ppp_wrapper_infos.append) | 382 ppb_wrapper_infos.append, |
| 385 appender(' &%s' % self.GetWrapperInfoName(iface)) | 383 ppp_wrapper_infos.append) |
| 384 appender(' &%s' % self.GetWrapperInfoName(iface)) | |
| 386 ppb_wrapper_infos.append(' NULL') | 385 ppb_wrapper_infos.append(' NULL') |
| 387 ppp_wrapper_infos.append(' NULL') | 386 ppp_wrapper_infos.append(' NULL') |
| 388 out.Write( | 387 out.Write( |
| 389 'static struct %s *s_ppb_wrappers[] = {\n%s\n};\n\n' % | 388 'static struct %s *s_ppb_wrappers[] = {\n%s\n};\n\n' % |
| 390 (self.GetWrapperMetadataName(), ',\n'.join(ppb_wrapper_infos))) | 389 (self.GetWrapperMetadataName(), ',\n'.join(ppb_wrapper_infos))) |
| 391 out.Write( | 390 out.Write( |
| 392 'static struct %s *s_ppp_wrappers[] = {\n%s\n};\n\n' % | 391 'static struct %s *s_ppp_wrappers[] = {\n%s\n};\n\n' % |
| 393 (self.GetWrapperMetadataName(), ',\n'.join(ppp_wrapper_infos))) | 392 (self.GetWrapperMetadataName(), ',\n'.join(ppp_wrapper_infos))) |
| 394 | 393 |
| 395 | 394 |
| 396 def DeclareWrapperInfos(self, iface_releases, out): | 395 def DeclareWrapperInfos(self, iface_releases, out): |
| 397 """The wrapper methods usually need access to the real_iface, so we must | 396 """The wrapper methods usually need access to the real_iface, so we must |
| 398 declare these wrapper infos ahead of time (there is a circular dependency). | 397 declare these wrapper infos ahead of time (there is a circular dependency). |
| 399 """ | 398 """ |
| 400 out.Write('/* BEGIN Declarations for all Wrapper Infos */\n\n') | 399 out.Write('/* BEGIN Declarations for all Wrapper Infos */\n\n') |
| 401 for iface in iface_releases: | 400 for iface in iface_releases: |
| 402 out.Write('static struct %s %s;\n' % | 401 if iface.needs_wrapping: |
| 403 (self.GetWrapperMetadataName(), self.GetWrapperInfoName(iface))) | 402 out.Write('static struct %s %s;\n' % |
| 403 (self.GetWrapperMetadataName(), | |
| 404 self.GetWrapperInfoName(iface))) | |
| 404 out.Write('/* END Declarations for all Wrapper Infos. */\n\n') | 405 out.Write('/* END Declarations for all Wrapper Infos. */\n\n') |
| 405 | 406 |
| 406 | 407 |
| 407 def GenerateRange(self, ast, releases, options): | 408 def GenerateRange(self, ast, releases, options): |
| 408 """Generate shim code for a range of releases. | 409 """Generate shim code for a range of releases. |
| 409 """ | 410 """ |
| 410 | 411 |
| 411 # Remember to set the output filename before running this. | 412 # Remember to set the output filename before running this. |
| 412 out_filename = self.output_file | 413 out_filename = self.output_file |
| 413 if out_filename is None: | 414 if out_filename is None: |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 439 self.GenerateWrapperInterfaces(iface_releases, out) | 440 self.GenerateWrapperInterfaces(iface_releases, out) |
| 440 | 441 |
| 441 # Generate a table of the wrapped interface structs that can be looked up. | 442 # Generate a table of the wrapped interface structs that can be looked up. |
| 442 self.GenerateWrapperInfoAndCollection(iface_releases, out) | 443 self.GenerateWrapperInfoAndCollection(iface_releases, out) |
| 443 | 444 |
| 444 # Write out the IDL-invariant functions. | 445 # Write out the IDL-invariant functions. |
| 445 self.GenerateFixedFunctions(out) | 446 self.GenerateFixedFunctions(out) |
| 446 | 447 |
| 447 out.Close() | 448 out.Close() |
| 448 return 0 | 449 return 0 |
| OLD | NEW |