diff options
author | sersut <serdar@opscode.com> | 2014-06-18 17:00:23 -0700 |
---|---|---|
committer | Claire McQuin <claire@getchef.com> | 2014-06-19 15:29:24 -0700 |
commit | f4fc9dfa580997369952e9d26da2bb63dc9d569d (patch) | |
tree | 76f9393a0a0139113e047cbb78ef8eb3d10f94d3 /lib/chef | |
parent | d8592902ae09980552f8dd57abe9ed9c76851445 (diff) | |
download | chef-f4fc9dfa580997369952e9d26da2bb63dc9d569d.tar.gz |
Use FFI binders to attach :SendMessageTimeout instead of Win32API in order to disable annoying message of:
DL is deprecated, please use Fiddle
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/provider/env/windows.rb | 7 | ||||
-rw-r--r-- | lib/chef/win32/api/system.rb | 14 | ||||
-rw-r--r-- | lib/chef/win32/version.rb | 8 |
3 files changed, 23 insertions, 6 deletions
diff --git a/lib/chef/provider/env/windows.rb b/lib/chef/provider/env/windows.rb index d0c136451f..a5f4b8148e 100644 --- a/lib/chef/provider/env/windows.rb +++ b/lib/chef/provider/env/windows.rb @@ -17,13 +17,14 @@ # if RUBY_PLATFORM =~ /mswin|mingw32|windows/ - require 'Win32API' + require 'chef/win32/api/system' end class Chef class Provider class Env class Windows < Chef::Provider::Env + include Chef::ReservedNames::Win32::API::System def create_env obj = env_obj(@new_resource.key_name) @@ -73,10 +74,8 @@ class Chef SMTO_NOTIMEOUTIFNOTHUNG = 0x0008 def broadcast_env_change - result = 0 flags = SMTO_BLOCK | SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG - @send_message ||= Win32API.new('user32', 'SendMessageTimeout', 'LLLPLLP', 'L') - @send_message.call(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 'Environment', flags, 5000, result) + SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, FFI::MemoryPointer.from_string('Environment').address, flags, 5000, nil) end end end diff --git a/lib/chef/win32/api/system.rb b/lib/chef/win32/api/system.rb index 60f381aa5a..a58c0f38f4 100644 --- a/lib/chef/win32/api/system.rb +++ b/lib/chef/win32/api/system.rb @@ -186,6 +186,20 @@ int WINAPI GetSystemMetrics( =end safe_attach_function :GetSystemMetrics, [:int], :int +=begin +LRESULT WINAPI SendMessageTimeout( + _In_ HWND hWnd, + _In_ UINT Msg, + _In_ WPARAM wParam, + _In_ LPARAM lParam, + _In_ UINT fuFlags, + _In_ UINT uTimeout, + _Out_opt_ PDWORD_PTR lpdwResult +); +=end + safe_attach_function :SendMessageTimeoutW, [:HWND, :UINT, :WPARAM, :LPARAM, :UINT, :UINT, :PDWORD_PTR], :LRESULT + safe_attach_function :SendMessageTimeoutA, [:HWND, :UINT, :WPARAM, :LPARAM, :UINT, :UINT, :PDWORD_PTR], :LRESULT + end end end diff --git a/lib/chef/win32/version.rb b/lib/chef/win32/version.rb index 233e31fe76..d2138289f5 100644 --- a/lib/chef/win32/version.rb +++ b/lib/chef/win32/version.rb @@ -23,6 +23,10 @@ require 'wmi-lite/wmi' class Chef module ReservedNames::Win32 class Version + class << self + include Chef::ReservedNames::Win32::API::System + end + include Chef::ReservedNames::Win32::API::Macros include Chef::ReservedNames::Win32::API::System @@ -33,12 +37,12 @@ class Chef private def self.get_system_metrics(n_index) - Win32API.new('user32', 'GetSystemMetrics', 'I', 'I').call(n_index) + GetSystemMetrics(n_index) end def self.method_name_from_marketing_name(marketing_name) "#{marketing_name.gsub(/\s/, '_').gsub(/\./, '_').downcase}?" - # "#{marketing_name.gsub(/\s/, '_').gsub(//, '_').downcase}?" + # "#{marketing_name.gsub(/\s/, '_').gsub(//, '_').downcase}?" end public |