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

Refactor of PcapRemoteDeviceList's factory functions. #1476

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

Dimi1010
Copy link
Collaborator

@Dimi1010 Dimi1010 commented Jun 30, 2024

Part of #1431. implements point 6.

  • Added a new factory function createRemoteDeviceList with overloads with/without authentication returning unique_ptr.
  • Deprecated the old getRemoteDeviceList due to the functions returning raw pointers.
  • Removed default constructor of PcapRemoteDeviceList
  • Added parameterized constructor to PcapRemoteDeviceList for detailed initialization.
  • Removed unused private methods:
    • setRemoteMachineIpAddress
    • setRemoteMachinePort
    • setRemoteAuthentication
  • Changed typedefs to Cpp11 standard.
  • Typo fixes

- Introduced `createRemoteDeviceList` static methods in `PcapRemoteDeviceList` for creating and managing remote device lists using `std::unique_ptr`, enhancing memory management and safety.
- Modified existing `getRemoteDeviceList` methods to utilize new `createRemoteDeviceList` methods, maintaining backward compatibility by returning raw pointers through `.release()`.
- Adopted smart pointers (`std::unique_ptr`) in the implementation for automatic memory cleanup, reducing the risk of memory leaks and improving code maintainability.
- Modernized the codebase by leveraging C++11 smart pointers, simplifying resource management and providing a clearer, more flexible API for handling remote device lists with and without authentication.
Modernized the syntax for defining iterator and const iterator type aliases in `PcapRemoteDeviceList.h` within the `pcpp` namespace. Replaced traditional `typedef` with the `using` syntax for `RemoteDeviceListIterator` and `ConstRemoteDeviceListIterator`. These changes enhance code readability and align with modern C++ best practices without altering functionality.
- Removed the default constructor of 'PcapRemoteDeviceList'.
- Added a new constructor to `PcapRemoteDeviceList` for initializing with detailed remote machine info and authentication.
- Corrected typographical errors in comments for better documentation clarity.
- Improved const-correctness in `createRemoteDeviceList` by changing `remoteAuth` parameter type.
- Refactored device creation logic in `createRemoteDeviceList` for clearer error handling and separation of concerns.
- Enhanced error handling in device creation to prevent memory leaks on exceptions.
- Transitioned to using `std::shared_ptr<PcapRemoteAuthentication>` for better memory management in device creation.
- Simplified authentication object handling by converting to `std::shared_ptr` early in the device creation process.
- Included DeprecationUtils.h in PcapRemoteDeviceList.h to mark certain functionalities as deprecated, indicating a move towards newer alternatives.
- Updated the private constructor comment in PcapRemoteDeviceList to recommend using `createRemoteDeviceList` for instance creation, reflecting a shift to a new factory method.
- Deprecated two static factory functions, `getRemoteDeviceList(const IPAddress& ipAddress, uint16_t port)` and `getRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, PcapRemoteAuthentication* remoteAuth)`, in favor of `createRemoteDeviceList`, enhancing memory safety and functionality.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant