![Phân tích tư tưởng của nhân dân qua đoạn thơ: Những người vợ nhớ chồng… Những cuộc đời đã hóa sông núi ta trong Đất nước của Nguyễn Khoa Điềm](https://timtailieu.net/upload/document/136415/phan-tich-tu-tuong-cua-nhan-dan-qua-doan-tho-039-039-nhung-nguoi-vo-nho-chong-nhung-cuoc-doi-da-hoa-song-nui-ta-039-039-trong-dat-nuoc-cua-nguyen-khoa-136415.jpg)
Creating Applications with Mozilla-Chapter 8. XPCOM- P4
Số trang: 18
Loại file: pdf
Dung lượng: 32.71 KB
Lượt xem: 1
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tham khảo tài liệu creating applications with mozilla-chapter 8. xpcom- p4, công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Creating Applications with Mozilla-Chapter 8. XPCOM- P4 Chapter 8. XPCOM- P4As you can see, the macro is made up of other macros that implement basicmethods of the nsISupports interface. Unless you need to modify thesemacros, they should be left as is. This macro is used later on when we createour C++ component.Example 8-6 shows a reference implementation of the QueryInterfacemethod in C++.Example 8-6. Reference implementation of QueryInterfaceNS_IMETHODIMPnsMyImplementation::QueryInterface( REFNSIID aIID,void** aInstancePtr ){ NS_ASSERTION(aInstancePtr, QueryInterfacerequires a non-NULL destination!); if ( !aInstancePtr ) return NS_ERROR_NULL_POINTER; nsISupports* foundInterface; if ( aIID.Equals(nsCOMTypeInfo::GetIID( ))) foundInterface = NS_STATIC_CAST(nsIX*, this); else if (aIID.Equals(nsCOMTypeInfo::GetIID( )) ) foundInterface = NS_STATIC_CAST(nsIY*, this); else if (aIID.Equals(nsCOMTypeInfo::GetIID( ))) foundInterface = NS_STATIC_CAST(nsISupports*,NS_STATIC_CAST(nsIX*, this)); else foundInterface = 0; nsresult status; if ( !foundInterface ) { status = NS_NOINTERFACE; } else { NS_ADDREF(foundInterface); status = NS_OK; } *aInstancePtr = foundInterface; return status;}8.2.4.2. The results macrosSince all XPCOM methods return result codes called nsresults, anotheruseful macro is the NS_SUCCEEDED macro. This indicates whether anXPCOM accessor has returned a successful result. It is defined innsError.h: #define NS_SUCCEEDED(_nsresult) (!((_nsresult) &0x80000000))A related macro, NS_FAILED, is indicates whether an XPCOM accessorreturned a failure code result. It too is defined in nsError.h. Thefollowing code demonstrates the typical use of these two macros:nsresult rv;nsCOMPtrfile(do_CreateInstance(@mozilla.org/file/local;1,&rv)); if (NS_FAILED(rv)) { printf(FAILED\n); return rv; } if (NS_SUCCEEDED(rv)) { printf( SUCCEEDED \n); return rv; }You may have noticed that the declaration of the identifier rv as the typensresult. nsresult is a 32-bit unsigned integer declared innscore.h: typedef PRUint32 nsresult;We assign an nsCOMPtr or smart pointer named file to a newly createdinstance of the nsILocalFile component. Using the NS_FAILED andNS_SUCCEEDED macros, we test for the nsresult to see if our attemptto create an instance of the component failed. If it did, rv would be assignedan integer with a specific error return code. Return codes are defined innsError.h. Alternatively, you can test your results for the success code:nsresult rv =nsComponentManager::CreateInstance(@mozilla.org/file/local;1, nsnull,NS_GET_IID(nsILocalFile), (void**)&refp);If a result is successful, the value of rv returns NS_OK, which is 0.Return codes are used in XPCOM instead of exceptions. Exceptions are notallowed because of their inconsistent implementation across differentcompilers. All error code numbers equate to a specific type of error. Forexample NS_ERROR_FAILURE and NS_ERROR_NULL_POINTER arecommon types of error code return values used throughout the Mozilla codebase. If a value returned to rv was NS_ERROR_NULL_POINTER, the testfor failure would be true and the code would return the numerical result codefor NS_ERROR_NULL_POINTER.8.2.4.3. The nsnull typeAnother widely use type is nsnull, defined in nscore.h. Here is thedefinition:#define nsnull 0This definition, nsnull, is the most common way to use null. Thefollowing code shows how to use nsnull: nsresult rv; nsCOMPtr file = do_CreateInstance(@mozilla.org/file/local;1,&rv); if (NS_SUCCEEDED(rv)) { char* msg = we successfully created aninstance of file\n; *_retval = (char*)nsMemory::Alloc(PL_strlen(msg) + 1); if (!*_retval) return NS_ERROR_OUT_OF_MEMORY; PL_strcpy(*_retval, msg); } else { *_retval = nsnull; }8.2.4.4. The NS_IMETHODIMP macroIf you look in the Mozilla C++ source code, you will see the macroNS_IMETHODIMP used frequently. This macro identifies the type of yourinterface implementation method. It is also defined in nscore.h, asshown in Example 8-7.Example 8-7. Platform macros in xpcom/base/nscore.h#define NS_IMETHODIMP NS_IMETHODIMP_(nsresult)#ifdef NS_WIN32 #define NS_IMETHODIMP_(type) type _ _stdcall#elif defined(XP_MAC) #define NS_IMETHODIMP_(type) type#elif defined(XP_OS2) #define NS_IMETHODIMP_(type) type#else #define NS_IMETHODIMP_(type) type#endifExample 8-8 shows a typical use of the NS_IMETHODIMP macro. Allmethods that implement an interface are of the type NS_IMETHODIMP.Example 8-8. NS_IMETHOD macroNS_IMETHODIMPnsMyImpl::GetSomeString(char** _retval){ nsresult rv; nsCOMPtr file = do_CreateInstance(@mozilla.org/file/local;1,&rv); if (NS_SUCCEEDED(rv)) { char* msg = we successfully created aninstance of file\n; *_retval = (char*)nsMemory::Alloc(PL_strlen(msg) + 1); if (!*_retval) return NS_ERROR_OUT_OF_MEMORY; PL_strcpy(*_retval, msg); } else { *_retval = nsnull; } return NS_OK;}The macro in Example 8-8 declares the method GetSomeString as anXPCOM implementation.8.2.4.5. nsCOMPtr smart pointerAs described earlier, XPCOM provides a C++ tool called a smart pointer tomanage reference counting. A smart pointer is a template class that actssyntactically, just like an ordinary pointer in C or C++. You can apply * todereference the pointer, ->, or access what the pointer refers to. Unlike araw COM interface pointer, however, nsCOMPtr manages AddRef,Release, and QueryInterface for y ...
Nội dung trích xuất từ tài liệu:
Creating Applications with Mozilla-Chapter 8. XPCOM- P4 Chapter 8. XPCOM- P4As you can see, the macro is made up of other macros that implement basicmethods of the nsISupports interface. Unless you need to modify thesemacros, they should be left as is. This macro is used later on when we createour C++ component.Example 8-6 shows a reference implementation of the QueryInterfacemethod in C++.Example 8-6. Reference implementation of QueryInterfaceNS_IMETHODIMPnsMyImplementation::QueryInterface( REFNSIID aIID,void** aInstancePtr ){ NS_ASSERTION(aInstancePtr, QueryInterfacerequires a non-NULL destination!); if ( !aInstancePtr ) return NS_ERROR_NULL_POINTER; nsISupports* foundInterface; if ( aIID.Equals(nsCOMTypeInfo::GetIID( ))) foundInterface = NS_STATIC_CAST(nsIX*, this); else if (aIID.Equals(nsCOMTypeInfo::GetIID( )) ) foundInterface = NS_STATIC_CAST(nsIY*, this); else if (aIID.Equals(nsCOMTypeInfo::GetIID( ))) foundInterface = NS_STATIC_CAST(nsISupports*,NS_STATIC_CAST(nsIX*, this)); else foundInterface = 0; nsresult status; if ( !foundInterface ) { status = NS_NOINTERFACE; } else { NS_ADDREF(foundInterface); status = NS_OK; } *aInstancePtr = foundInterface; return status;}8.2.4.2. The results macrosSince all XPCOM methods return result codes called nsresults, anotheruseful macro is the NS_SUCCEEDED macro. This indicates whether anXPCOM accessor has returned a successful result. It is defined innsError.h: #define NS_SUCCEEDED(_nsresult) (!((_nsresult) &0x80000000))A related macro, NS_FAILED, is indicates whether an XPCOM accessorreturned a failure code result. It too is defined in nsError.h. Thefollowing code demonstrates the typical use of these two macros:nsresult rv;nsCOMPtrfile(do_CreateInstance(@mozilla.org/file/local;1,&rv)); if (NS_FAILED(rv)) { printf(FAILED\n); return rv; } if (NS_SUCCEEDED(rv)) { printf( SUCCEEDED \n); return rv; }You may have noticed that the declaration of the identifier rv as the typensresult. nsresult is a 32-bit unsigned integer declared innscore.h: typedef PRUint32 nsresult;We assign an nsCOMPtr or smart pointer named file to a newly createdinstance of the nsILocalFile component. Using the NS_FAILED andNS_SUCCEEDED macros, we test for the nsresult to see if our attemptto create an instance of the component failed. If it did, rv would be assignedan integer with a specific error return code. Return codes are defined innsError.h. Alternatively, you can test your results for the success code:nsresult rv =nsComponentManager::CreateInstance(@mozilla.org/file/local;1, nsnull,NS_GET_IID(nsILocalFile), (void**)&refp);If a result is successful, the value of rv returns NS_OK, which is 0.Return codes are used in XPCOM instead of exceptions. Exceptions are notallowed because of their inconsistent implementation across differentcompilers. All error code numbers equate to a specific type of error. Forexample NS_ERROR_FAILURE and NS_ERROR_NULL_POINTER arecommon types of error code return values used throughout the Mozilla codebase. If a value returned to rv was NS_ERROR_NULL_POINTER, the testfor failure would be true and the code would return the numerical result codefor NS_ERROR_NULL_POINTER.8.2.4.3. The nsnull typeAnother widely use type is nsnull, defined in nscore.h. Here is thedefinition:#define nsnull 0This definition, nsnull, is the most common way to use null. Thefollowing code shows how to use nsnull: nsresult rv; nsCOMPtr file = do_CreateInstance(@mozilla.org/file/local;1,&rv); if (NS_SUCCEEDED(rv)) { char* msg = we successfully created aninstance of file\n; *_retval = (char*)nsMemory::Alloc(PL_strlen(msg) + 1); if (!*_retval) return NS_ERROR_OUT_OF_MEMORY; PL_strcpy(*_retval, msg); } else { *_retval = nsnull; }8.2.4.4. The NS_IMETHODIMP macroIf you look in the Mozilla C++ source code, you will see the macroNS_IMETHODIMP used frequently. This macro identifies the type of yourinterface implementation method. It is also defined in nscore.h, asshown in Example 8-7.Example 8-7. Platform macros in xpcom/base/nscore.h#define NS_IMETHODIMP NS_IMETHODIMP_(nsresult)#ifdef NS_WIN32 #define NS_IMETHODIMP_(type) type _ _stdcall#elif defined(XP_MAC) #define NS_IMETHODIMP_(type) type#elif defined(XP_OS2) #define NS_IMETHODIMP_(type) type#else #define NS_IMETHODIMP_(type) type#endifExample 8-8 shows a typical use of the NS_IMETHODIMP macro. Allmethods that implement an interface are of the type NS_IMETHODIMP.Example 8-8. NS_IMETHOD macroNS_IMETHODIMPnsMyImpl::GetSomeString(char** _retval){ nsresult rv; nsCOMPtr file = do_CreateInstance(@mozilla.org/file/local;1,&rv); if (NS_SUCCEEDED(rv)) { char* msg = we successfully created aninstance of file\n; *_retval = (char*)nsMemory::Alloc(PL_strlen(msg) + 1); if (!*_retval) return NS_ERROR_OUT_OF_MEMORY; PL_strcpy(*_retval, msg); } else { *_retval = nsnull; } return NS_OK;}The macro in Example 8-8 declares the method GetSomeString as anXPCOM implementation.8.2.4.5. nsCOMPtr smart pointerAs described earlier, XPCOM provides a C++ tool called a smart pointer tomanage reference counting. A smart pointer is a template class that actssyntactically, just like an ordinary pointer in C or C++. You can apply * todereference the pointer, ->, or access what the pointer refers to. Unlike araw COM interface pointer, however, nsCOMPtr manages AddRef,Release, and QueryInterface for y ...
Tìm kiếm theo từ khóa liên quan:
thủ thuật máy tính công nghệ thông tin tin học quản trị mạng computer networkTài liệu liên quan:
-
52 trang 439 1 0
-
24 trang 366 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 329 0 0 -
Làm việc với Read Only Domain Controllers
20 trang 321 0 0 -
74 trang 309 0 0
-
96 trang 305 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 299 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 291 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 291 1 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 278 0 0